Checks whether or not the method is safe.
public isMethodSafe ( ) : boolean | ||
return | boolean |
use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals(); if ($request->isMethodSafe()) { // Do something } else { // Do something else }
use Symfony\Component\HttpFoundation\Request; $client = new \GuzzleHttp\Client(); $response = $client->request('POST', 'http://example.com/api', [ 'json' => [ 'foo' => 'bar', ], 'headers' => [ 'Content-Type' => 'application/json', ], ]); $request = Request::createFromGlobals(); if ($request->isMethodSafe()) { $cached_response = get_response_from_cache($request); if ($cached_response) { return $cached_response; } } return $response->getBody()->getContents();
use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals(); if ($request->isMethodSafe()) { $cache = new \My\Cache\Adapter(); $cached_response = $cache->get($request->getUri()); if ($cached_response) { return $cached_response; } } $response = handle_request($request); if ($request->isMethodSafe()) { $cache->set($request->getUri(), $response); } return $response;The isMethodSafe() method is part of the Symfony\Component\HttpFoundation package.
public isMethodSafe ( ) : boolean | ||
return | boolean |