當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ResponseInterface::redirect方法代碼示例

本文整理匯總了PHP中Psr\Http\Message\ResponseInterface::redirect方法的典型用法代碼示例。如果您正苦於以下問題:PHP ResponseInterface::redirect方法的具體用法?PHP ResponseInterface::redirect怎麽用?PHP ResponseInterface::redirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Psr\Http\Message\ResponseInterface的用法示例。


在下文中一共展示了ResponseInterface::redirect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __invoke

 /**
  * Invoke middleware
  * 
  * @param ServerRequestInterface $request  request
  * @param ResponseInterface      $response response
  * @param callable               $next     callable
  * 
  * @return object ResponseInterface
  */
 public function __invoke(Request $request, Response $response, callable $next = null)
 {
     if ($this->getContainer()->get('user')->identity->guest()) {
         $this->getContainer()->get('flash')->info('Your session has been expired.');
         return $response->redirect(static::REDIRECT_URI);
     }
     $err = null;
     return $next($request, $response, $err);
 }
開發者ID:obullo,項目名稱:http-middlewares,代碼行數:18,代碼來源:Guest.php

示例2: __invoke

 /**
  * Invoke middleware
  * 
  * @param ServerRequestInterface $request  request
  * @param ResponseInterface      $response response
  * @param callable               $next     callable
  * 
  * @return object ResponseInterface
  */
 public function __invoke(Request $request, Response $response, callable $next = null)
 {
     $err = null;
     if ($request->isSecure() == false) {
         $path = $request->getUri()->getPath();
         $host = $request->getUri()->getHost();
         return $response->redirect('https://' . $host . $path);
     }
     return $next($request, $response, $err);
 }
開發者ID:obullo,項目名稱:http-middlewares,代碼行數:19,代碼來源:Https.php

示例3: __invoke

 /**
  * Invoke middleware
  * 
  * @param ServerRequestInterface $request  request
  * @param ResponseInterface      $response response
  * @param callable               $next     callable
  * 
  * @return object ResponseInterface
  */
 public function __invoke(Request $request, Response $response, callable $next = null)
 {
     $err = null;
     if (!$this->getContainer()->get('middleware')->isAdded('Translation')) {
         throw new RuntimeException('RewriteLocale middleware requires Translation middleware.');
     }
     if ($request->getMethod() == 'GET') {
         $params = $this->getContainer()->get('translator.params');
         $segment = $request->getUri()->segment($params['uri']['segment']);
         // Get segment http://examples.com/en/welcome  (en)
         if (!in_array($segment, $params['default']['languages'])) {
             $translator = $this->getContainer()->get('translator');
             $path = $translator->getLocale() . $request->getUri()->getPath();
             return $response->redirect($request->getUri()->withPath($path));
         }
     }
     return $next($request, $response, $err);
 }
開發者ID:obullo,項目名稱:http-middlewares,代碼行數:27,代碼來源:RewriteLocale.php


注:本文中的Psr\Http\Message\ResponseInterface::redirect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。