当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::isRedirect方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::isRedirect方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::isRedirect方法的具体用法?PHP Response::isRedirect怎么用?PHP Response::isRedirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\Response的用法示例。


在下文中一共展示了Response::isRedirect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 public function handle(Event $event, Response $response)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
         return $response;
     }
     if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
         $response->setContent(sprintf('<html><head></head><body><h1>This Request redirects to<br /><a href="%s">%s</a>.</h1></body></html>', $response->headers->get('location'), $response->headers->get('location')));
         $response->setStatusCode(200);
         $response->headers->delete('Location');
     }
     $request = $event->getParameter('request');
     if (!$response->headers->has('X-Debug-Token') || '3' === substr($response->getStatusCode(), 0, 1) || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat() || $request->isXmlHttpRequest()) {
         return $response;
     }
     $this->injectToolbar($request, $response);
     return $response;
 }
开发者ID:rsky,项目名称:symfony,代码行数:17,代码来源:WebDebugToolbarListener.php

示例2: handle

 public function handle(EventInterface $event, Response $response)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
         return $response;
     }
     if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
         $response->setContent(sprintf('<html><head></head><body><h1>This Request redirects to<br /><a href="%1$s">%1$s</a>.</h1><h4>The redirect was intercepted by the web debug toolbar to help debugging.<br/>For more information, see the "intercept-redirects" option of the Profiler.</h4></body></html>', $response->headers->get('Location')));
         $response->setStatusCode(200);
         $response->headers->remove('Location');
     }
     $request = $event->get('request');
     if (!$response->headers->has('X-Debug-Token') || '3' === substr($response->getStatusCode(), 0, 1) || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat() || $request->isXmlHttpRequest()) {
         return $response;
     }
     $this->injectToolbar($response);
     return $response;
 }
开发者ID:noelg,项目名称:symfony-demo,代码行数:17,代码来源:WebDebugToolbarListener.php

示例3: testIsRedirectRedirection

 public function testIsRedirectRedirection()
 {
     foreach (array(301, 302, 303, 307) as $code) {
         $response = new Response('', $code);
         $this->assertTrue($response->isRedirection());
         $this->assertTrue($response->isRedirect());
     }
     $response = new Response('', 304);
     $this->assertTrue($response->isRedirection());
     $this->assertFalse($response->isRedirect());
     $response = new Response('', 200);
     $this->assertFalse($response->isRedirection());
     $this->assertFalse($response->isRedirect());
     $response = new Response('', 404);
     $this->assertFalse($response->isRedirection());
     $this->assertFalse($response->isRedirect());
     $response = new Response('', 301, array('Location' => '/good-uri'));
     $this->assertFalse($response->isRedirect('/bad-uri'));
     $this->assertTrue($response->isRedirect('/good-uri'));
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:20,代码来源:ResponseTest.php

示例4: assertRedirectUrl

 public function assertRedirectUrl(Response $returnResponse, $expectedUrl)
 {
     $this->assertTrue($returnResponse->isRedirect($expectedUrl), "Expected: {$expectedUrl}\nGot:      " . $returnResponse->headers->get('Location'));
 }
开发者ID:dev-lav,项目名称:htdocs,代码行数:4,代码来源:RedirectControllerTest.php

示例5: assertRedirect

 public static function assertRedirect(Response $response, $location)
 {
     self::assertTrue($response->isRedirect(), 'Response is not a redirect, got status code: ' . $response->getStatusCode());
     self::assertEquals('http://localhost' . $location, $response->headers->get('Location'));
 }
开发者ID:2martens,项目名称:web-platform,代码行数:5,代码来源:WebTestCase.php

示例6: collect

 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     $responseHeaders = $response->headers->all();
     $cookies = array();
     foreach ($response->headers->getCookies() as $cookie) {
         $cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
     }
     if (count($cookies) > 0) {
         $responseHeaders['Set-Cookie'] = $cookies;
     }
     // attributes are serialized and as they can be anything, they need to be converted to strings.
     $attributes = array();
     foreach ($request->attributes->all() as $key => $value) {
         if ('_route' === $key && is_object($value)) {
             $attributes[$key] = $this->varToString($value->getPath());
         } elseif ('_route_params' === $key) {
             // we need to keep route params as an array (see getRouteParams())
             foreach ($value as $k => $v) {
                 $value[$k] = $this->varToString($v);
             }
             $attributes[$key] = $value;
         } else {
             $attributes[$key] = $this->varToString($value);
         }
     }
     $content = null;
     try {
         $content = $request->getContent();
     } catch (\LogicException $e) {
         // the user already got the request content as a resource
         $content = false;
     }
     $sessionMetadata = array();
     $sessionAttributes = array();
     $session = null;
     $flashes = array();
     if ($request->hasSession()) {
         $session = $request->getSession();
         if ($session->isStarted()) {
             $sessionMetadata['Created'] = date(DATE_RFC822, $session->getMetadataBag()->getCreated());
             $sessionMetadata['Last used'] = date(DATE_RFC822, $session->getMetadataBag()->getLastUsed());
             $sessionMetadata['Lifetime'] = $session->getMetadataBag()->getLifetime();
             $sessionAttributes = $session->all();
             $flashes = $session->getFlashBag()->peekAll();
         }
     }
     $statusCode = $response->getStatusCode();
     $this->data = array('method' => $request->getMethod(), 'format' => $request->getRequestFormat(), 'content' => $content, 'content_type' => $response->headers->get('Content-Type', 'text/html'), 'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '', 'status_code' => $statusCode, 'request_query' => $request->query->all(), 'request_request' => $request->request->all(), 'request_headers' => $request->headers->all(), 'request_server' => $request->server->all(), 'request_cookies' => $request->cookies->all(), 'request_attributes' => $attributes, 'response_headers' => $responseHeaders, 'session_metadata' => $sessionMetadata, 'session_attributes' => $sessionAttributes, 'flashes' => $flashes, 'path_info' => $request->getPathInfo(), 'controller' => 'n/a', 'locale' => $request->getLocale());
     if (isset($this->data['request_headers']['php-auth-pw'])) {
         $this->data['request_headers']['php-auth-pw'] = '******';
     }
     if (isset($this->data['request_server']['PHP_AUTH_PW'])) {
         $this->data['request_server']['PHP_AUTH_PW'] = '******';
     }
     if (isset($this->data['request_request']['_password'])) {
         $this->data['request_request']['_password'] = '******';
     }
     if (isset($this->controllers[$request])) {
         $this->data['controller'] = $this->parseController($this->controllers[$request]);
         unset($this->controllers[$request]);
     }
     if (null !== $session) {
         if ($request->attributes->has('_redirected')) {
             $this->data['redirect'] = $session->remove('sf_redirect');
         }
         if ($response->isRedirect()) {
             $session->set('sf_redirect', array('token' => $response->headers->get('x-debug-token'), 'route' => $request->attributes->get('_route', 'n/a'), 'method' => $request->getMethod(), 'controller' => $this->parseController($request->attributes->get('_controller')), 'status_code' => $statusCode, 'status_text' => Response::$statusTexts[(int) $statusCode]));
         }
     }
 }
开发者ID:zanderbaldwin,项目名称:symfony,代码行数:73,代码来源:RequestDataCollector.php

示例7: check

 protected function check(Response $response)
 {
     return $response->isRedirect();
 }
开发者ID:geschke,项目名称:legacy-integration-bundle,代码行数:4,代码来源:IgnoreRedirect.php

示例8: collect

    /**
     * {@inheritdoc}
     */
    public function collect(Request $request, Response $response, \Exception $exception = null)
    {
        // attributes are serialized and as they can be anything, they need to be converted to strings.
        $attributes = array();
        $route = '';
        foreach ($request->attributes->all() as $key => $value) {
            if ('_route' === $key) {
                $route = is_object($value) ? $value->getPath() : $value;
                $attributes[$key] = $route;
            } else {
                $attributes[$key] = $value;
            }
        }

        $content = null;
        try {
            $content = $request->getContent();
        } catch (\LogicException $e) {
            // the user already got the request content as a resource
            $content = false;
        }

        $sessionMetadata = array();
        $sessionAttributes = array();
        $session = null;
        $flashes = array();
        if ($request->hasSession()) {
            $session = $request->getSession();
            if ($session->isStarted()) {
                $sessionMetadata['Created'] = date(DATE_RFC822, $session->getMetadataBag()->getCreated());
                $sessionMetadata['Last used'] = date(DATE_RFC822, $session->getMetadataBag()->getLastUsed());
                $sessionMetadata['Lifetime'] = $session->getMetadataBag()->getLifetime();
                $sessionAttributes = $session->all();
                $flashes = $session->getFlashBag()->peekAll();
            }
        }

        $statusCode = $response->getStatusCode();

        $this->data = array(
            'method' => $request->getMethod(),
            'format' => $request->getRequestFormat(),
            'content' => $content,
            'content_type' => $response->headers->get('Content-Type', 'text/html'),
            'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '',
            'status_code' => $statusCode,
            'request_query' => $request->query->all(),
            'request_request' => $request->request->all(),
            'request_headers' => $request->headers->all(),
            'request_server' => $request->server->all(),
            'request_cookies' => $request->cookies->all(),
            'request_attributes' => $attributes,
            'route' => $route,
            'response_headers' => $response->headers->all(),
            'session_metadata' => $sessionMetadata,
            'session_attributes' => $sessionAttributes,
            'flashes' => $flashes,
            'path_info' => $request->getPathInfo(),
            'controller' => 'n/a',
            'locale' => $request->getLocale(),
        );

        if (isset($this->data['request_headers']['php-auth-pw'])) {
            $this->data['request_headers']['php-auth-pw'] = '******';
        }

        if (isset($this->data['request_server']['PHP_AUTH_PW'])) {
            $this->data['request_server']['PHP_AUTH_PW'] = '******';
        }

        if (isset($this->data['request_request']['_password'])) {
            $this->data['request_request']['_password'] = '******';
        }

        foreach ($this->data as $key => $value) {
            if (!is_array($value)) {
                continue;
            }
            if ('request_headers' === $key || 'response_headers' === $key) {
                $value = array_map(function ($v) { return isset($v[0]) && !isset($v[1]) ? $v[0] : $v; }, $value);
            }
            if ('request_server' !== $key && 'request_cookies' !== $key) {
                $this->data[$key] = array_map(array($this, 'cloneVar'), $value);
            }
        }

        if (isset($this->controllers[$request])) {
            $this->data['controller'] = $this->parseController($this->controllers[$request]);
            unset($this->controllers[$request]);
        }

        if (null !== $session && $session->isStarted()) {
            if ($request->attributes->has('_redirected')) {
                $this->data['redirect'] = $session->remove('sf_redirect');
            }

            if ($response->isRedirect()) {
//.........这里部分代码省略.........
开发者ID:symfony,项目名称:symfony,代码行数:101,代码来源:RequestDataCollector.php

示例9: makeResponse

 /**
  * Transform an exception handler's response into a Response object.
  *
  * @param  mixed      $response
  * @param  \Exception $exception
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function makeResponse($response, Exception $exception)
 {
     if (!$response instanceof Response) {
         $response = new Response($response);
     }
     if (!$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) {
         if ($exception instanceof HttpExceptionInterface) {
             $response->setStatusCode($exception->getStatusCode());
             $response->headers->add($exception->getHeaders());
         } else {
             $response->setStatusCode(500);
         }
     }
     return $response;
 }
开发者ID:autarky,项目名称:framework,代码行数:23,代码来源:ErrorHandlerManager.php


注:本文中的Symfony\Component\HttpFoundation\Response::isRedirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。