Symfony\Component\HttpFoundation\Request::isMethodSafe PHP Method

isMethodSafe() public method

Checks whether or not the method is safe.
See also: https://tools.ietf.org/html/rfc7231#section-4.2.1
public isMethodSafe ( ) : boolean
return boolean
    public function isMethodSafe(/* $andCacheable = true */)
    {
        if (!func_num_args() || func_get_arg(0)) {
            // This deprecation should be turned into a BadMethodCallException in 4.0 (without adding the argument in the signature)
            // then setting $andCacheable to false should be deprecated in 4.1
            @trigger_error('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is deprecated since version 3.2 and will throw an exception in 4.0. Disable checking only for cacheable methods by calling the method with `false` as first argument or use the Request::isMethodCacheable() instead.', E_USER_DEPRECATED);

            return in_array($this->getMethod(), array('GET', 'HEAD'));
        }

        return in_array($this->getMethod(), array('GET', 'HEAD', 'OPTIONS', 'TRACE'));
    }

Usage Example

Example #1
0
    /**
     * @Tag(expression="'item-'~id")
     */
    public function itemAction(Request $request, $id)
    {
        if (!$request->isMethodSafe()) {
            $this->container->get('fos_http_cache.cache_manager')->invalidateTags(array('all-items'));
        }

        return new Response('Item ' . $id . ' invalidated');
    }
All Usage Examples Of Symfony\Component\HttpFoundation\Request::isMethodSafe