本文整理汇总了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);
}
示例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);
}
示例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);
}