本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::isMethodSafe方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::isMethodSafe方法的具体用法?PHP Request::isMethodSafe怎么用?PHP Request::isMethodSafe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::isMethodSafe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: itemAction
/**
* @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');
}
示例2: setIntent
/**
* @param Request $request
* @param bool $override
*/
public function setIntent(Request $request, $override = false)
{
if ($request->hasSession() && $request->isMethodSafe() && !$request->isXmlHttpRequest()) {
if ($override || false === $this->hasIntent($request)) {
$request->getSession()->set(self::SESSION_INTENT_KEY, $request->getUri());
}
}
}
示例3: setTargetPath
protected function setTargetPath(Request $request)
{
if ($request->isXmlHttpRequest()) {
return;
}
if ($request->hasSession() && ($request->isMethodSafe() || $request->get('_route') == 'engishop_front_cart_add')) {
$request->getSession()->set('_security.' . $this->providerKey . '.target_path', $request->getUri());
}
}
示例4: loginAction
public function loginAction(Request $request)
{
if (!$this->hasRole('ROLE_USER')) {
if ($request->hasSession() && $request->isMethodSafe()) {
$referer = $request->headers->get('referer');
if (null !== $referer) {
$request->getSession()->set('ddr.gitki.manuallogin.targetpath', $referer);
}
}
throw new AuthenticationException();
}
if ($request->hasSession() && $request->isMethodSafe()) {
$targetPath = $request->getSession()->get('ddr.gitki.manuallogin.targetpath');
$request->getSession()->remove('ddr.gitki.manuallogin.targetpath');
if (null !== $targetPath) {
return $this->redirect($targetPath);
}
}
return $this->redirect($this->generateUrl('ddr_gitki_wiki_file', array('path' => '/index.md')));
}
示例5: handle
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
// Forbid direct AUTHENTICATE requests to get user hash
if ($request->headers->get('X-HTTP-Override') === 'AUTHENTICATE' && $request->headers->get('Accept') === Kernel::USER_HASH_ACCEPT_HEADER) {
return new Response('', 405);
}
if ($request->isMethodSafe()) {
$request->headers->set('X-User-Hash', $this->kernel->generateUserHash($request));
}
return parent::handle($request, $type, $catch);
}
示例6: validateRequest
protected function validateRequest(Request $request)
{
// is the Request safe?
if (!$request->isMethodSafe()) {
throw new AccessDeniedHttpException();
}
// is the Request signed?
// we cannot use $request->getUri() here as we want to work with the original URI (no query string reordering)
if ($this->signer->check($request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo() . (null !== ($qs = $request->server->get('QUERY_STRING')) ? '?' . $qs : ''))) {
return;
}
throw new AccessDeniedHttpException();
}
示例7: getContext
/**
* Gets the base Twig context.
*
* @param Request $request
*
* @return array
*/
private function getContext(Request $request) : array
{
$context = ['title' => $this->title, 'description' => $this->description, 'formats' => $this->formats, 'shortName' => null, 'operationId' => null];
if (!$request->isMethodSafe() || null === ($resourceClass = $request->attributes->get('_api_resource_class'))) {
return $context;
}
$metadata = $this->resourceMetadataFactory->create($resourceClass);
$context['shortName'] = $metadata->getShortName();
if (null !== ($collectionOperationName = $request->attributes->get('_api_collection_operation_name'))) {
$context['operationId'] = sprintf('%s%sCollection', $collectionOperationName, $context['shortName']);
} elseif (null !== ($itemOperationName = $request->attributes->get('_api_item_operation_name'))) {
$context['operationId'] = sprintf('%s%sItem', $itemOperationName, $context['shortName']);
}
return $context;
}
示例8: validateRequest
protected function validateRequest(Request $request)
{
// is the Request safe?
if (!$request->isMethodSafe()) {
throw new AccessDeniedHttpException();
}
// does the Request come from a trusted IP?
$trustedIps = array_merge($this->getLocalIpAddresses(), $request->getTrustedProxies());
$remoteAddress = $request->server->get('REMOTE_ADDR');
if (IpUtils::checkIp($remoteAddress, $trustedIps)) {
return;
}
// is the Request signed?
// we cannot use $request->getUri() here as we want to work with the original URI (no query string reordering)
if ($this->signer->check($request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo() . (null !== ($qs = $request->server->get('QUERY_STRING')) ? '?' . $qs : ''))) {
return;
}
throw new AccessDeniedHttpException();
}
示例9: setTargetPath
/**
* @param Request $request
*/
protected function setTargetPath(Request $request)
{
// session isn't required when using HTTP basic authentication mechanism for example
if ($request->hasSession() && $request->isMethodSafe()) {
$request->getSession()->set('_security.' . $this->providerKey . '.target_path', $request->getUri());
}
}
示例10: testMethodSafe
/**
* @dataProvider methodSafeProvider
*/
public function testMethodSafe($method, $safe)
{
$request = new Request();
$request->setMethod($method);
$this->assertEquals($safe, $request->isMethodSafe());
}
示例11: setTargetPath
/**
* @param Request $request
*/
protected function setTargetPath(Request $request)
{
// session isn't required when using HTTP basic authentication mechanism for example
if ($request->hasSession() && $request->isMethodSafe() && !$request->isXmlHttpRequest()) {
$this->saveTargetPath($request->getSession(), $this->providerKey, $request->getUri());
}
}
示例12: handle
/**
* Handles a Request.
*
* @param Request $request A Request instance
* @param integer $type The type of the request (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
* @param Boolean $raw Whether to catch exceptions or not (this is NOT used in this context)
*
* @return Symfony\Component\HttpFoundation\Response A Response instance
*/
public function handle(Request $request = null, $type = HttpKernelInterface::MASTER_REQUEST, $raw = false)
{
// FIXME: catch exceptions and implement a 500 error page here? -> in Varnish, there is a built-in error page mechanism
if (null === $request) {
$request = new Request();
}
if (HttpKernelInterface::MASTER_REQUEST === $type) {
$this->traces = array();
$this->request = $request;
}
$this->traces[$request->getMethod() . ' ' . $request->getPathInfo()] = array();
if (!$request->isMethodSafe($request)) {
$response = $this->invalidate($request);
} elseif ($request->headers->has('expect')) {
$response = $this->pass($request);
} else {
$response = $this->lookup($request);
}
$response->isNotModified($request);
if ('head' === strtolower($request->getMethod())) {
$response->setContent('');
} else {
$this->restoreResponseBody($response);
}
if (HttpKernelInterface::MASTER_REQUEST === $type && $this->options['debug']) {
$response->headers->set('X-Symfony-Cache', $this->getLog());
}
return $response;
}
示例13: isRequestSafe
/**
* Decide whether to even look for matching rules with the current request.
*
* @param Request $request
*
* @return bool True if the request is safe and headers can be set
*/
protected function isRequestSafe(Request $request)
{
return $request->isMethodSafe();
}
示例14: testMethodSafeChecksCacheable
/**
* @group legacy
* @expectedDeprecation 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.
*/
public function testMethodSafeChecksCacheable()
{
$request = new Request();
$request->setMethod('OPTIONS');
$this->assertFalse($request->isMethodSafe());
}
示例15: check
/**
* {@inheritdoc}
*/
public function check(Request $request)
{
if ($this->isCli() || !$request->isMethodSafe()) {
return static::DENY;
}
}