本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::isRedirection方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::isRedirection方法的具体用法?PHP Response::isRedirection怎么用?PHP Response::isRedirection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::isRedirection方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: after
public function after(Request $request, Response $response, Application $app)
{
if ($response->isRedirection()) {
return;
}
// if ('application/json' === $request->headers->get('Accept')) {
// return $this->app()->json($this->data);
// }
//https://blog.yorunohikage.fr/
//Pretty printing all JSON output in Silex PHP
//if($response instanceof JsonResponse) {
// $response->setEncodingOptions(JSON_PRETTY_PRINT);
//}
if ($request->isXmlHttpRequest()) {
$response_data = array('status' => 'OK', 'data' => $this->data);
if (!is_null($this->error)) {
$response_data['status'] = 'ERROR';
$response_data['error'] = $this->error;
}
return $this->app->json($response_data);
}
if ($response->getContent() == '') {
$this->initTwig();
$response->setContent($this->twig()->render($this->template, $this->data));
}
}
示例2: injectJavascript
public static function injectJavascript(Response $response)
{
if (app()->runningInConsole() || !self::isActive() || $response->isRedirection() || !config('2checkout.inject')) {
return $response;
}
$content = $response->getContent();
$response->setContent(str_replace("</body>", "<script src='https://www.2checkout.com/checkout/api/2co.min.js'></script>\n</body>", $content));
return $response;
}
示例3: getParameters
/**
* {@inheritdoc}
*/
public function getParameters()
{
$code = null;
$codeType = null;
$cacheable = null;
if (null !== $this->response) {
$code = sprintf('%d', $this->response->getStatusCode());
$cacheable = $this->response->isCacheable() ? 'cacheable' : 'not_cacheable';
if ($this->response->isInformational()) {
$codeType = 'informational';
} elseif ($this->response->isSuccessful()) {
$codeType = 'successful';
} elseif ($this->response->isRedirection()) {
$codeType = 'redirection';
} elseif ($this->response->isClientError()) {
$codeType = 'client_error';
} elseif ($this->response->isServerError()) {
$codeType = 'server_error';
} else {
$codeType = 'other';
}
}
return array('response_code' => $code, 'response_code_type' => $codeType, 'response_cacheable' => $cacheable);
}
示例4: modifyResponse
/**
* Modify the response and inject the debugbar (or data in headers)
*
* @param \Illuminate\Http\Request $request
* @param \Symfony\Component\HttpFoundation\Response $response
* @return \Symfony\Component\HttpFoundation\Response
*/
public function modifyResponse($request, $response)
{
$app = $this->app;
if ($app->runningInConsole() or !$this->isEnabled() || $this->isDebugbarRequest()) {
return $response;
}
if ($this->shouldCollect('config', false)) {
try {
$configCollector = new ConfigCollector();
$configCollector->setData($app['config']->getItems());
$this->addCollector($configCollector);
} catch (\Exception $e) {
$this->addException(new Exception('Cannot add ConfigCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
}
}
/** @var \Illuminate\Session\SessionManager $sessionManager */
$sessionManager = $app['session'];
$httpDriver = new SymfonyHttpDriver($sessionManager, $response);
$this->setHttpDriver($httpDriver);
if ($this->shouldCollect('symfony_request', true) and !$this->hasCollector('request')) {
try {
$this->addCollector(new SymfonyRequestCollector($request, $response, $sessionManager));
} catch (\Exception $e) {
$this->addException(new Exception('Cannot add SymfonyRequestCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
}
}
if ($response->isRedirection()) {
try {
$this->stackData();
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
} elseif ($request->isXmlHttpRequest() || $request->wantsJson() and $app['config']->get('laravel-debugbar::config.capture_ajax', true)) {
try {
$this->sendDataInHeaders(true);
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
} elseif ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->format()) {
//Do nothing
} elseif ($app['config']->get('laravel-debugbar::config.inject', true)) {
try {
$this->injectDebugbar($response);
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
}
// Stop further rendering (on subrequests etc)
$this->disable();
return $response;
}
示例5: deny
/**
* deny.
*
* @method deny
*
* @param \Symfony\Component\HttpFoundation\Response $response
* @param int $statusCode
*
* @return bool
*/
protected function deny(Response $response, $statusCode)
{
if ($response instanceof BinaryFileResponse) {
return true;
}
if ($response instanceof StreamedResponse) {
return true;
}
if ($response->isRedirection() === true) {
return true;
}
if ($this->ajax === true) {
return false;
}
$contentType = $response->headers->get('Content-Type');
if (empty($contentType) === true && $statusCode >= 400) {
return false;
}
if (count($this->accepts) === 0) {
return false;
}
$contentType = strtolower($contentType);
foreach ($this->accepts as $accept) {
if (strpos($contentType, $accept) !== false) {
return false;
}
}
return true;
}
示例6: shouldCacheResponse
/**
* Determine if the given response should be cached.
*
* @param \Symfony\Component\HttpFoundation\Response $response
*
* @return bool
*/
public function shouldCacheResponse(Response $response)
{
return $response->isSuccessful() || $response->isRedirection();
}
示例7: 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'));
}
示例8: collect
public function collect(Request $request, Response $response, \Exception $exception = null)
{
// Sub-requests and programmatic calls stay in the collected profile.
if ($this->dumper || $this->requestStack && $this->requestStack->getMasterRequest() !== $request || $request->isXmlHttpRequest() || $request->headers->has('Origin')) {
return;
}
// In all other conditions that remove the web debug toolbar, dumps are written on the output.
if (!$this->requestStack || !$response->headers->has('X-Debug-Token') || $response->isRedirection() || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat() || false === strripos($response->getContent(), '</body>')) {
if ($response->headers->has('Content-Type') && false !== strpos($response->headers->get('Content-Type'), 'html')) {
$this->dumper = new HtmlDumper('php://output', $this->charset);
} else {
$this->dumper = new CliDumper('php://output', $this->charset);
}
foreach ($this->data as $dump) {
$this->doDump($dump['data'], $dump['name'], $dump['file'], $dump['line']);
}
}
}
示例9: modifyResponse
/**
* Modify the response and inject the debugbar (or data in headers)
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Symfony\Component\HttpFoundation\Response $response
* @return \Symfony\Component\HttpFoundation\Response
*/
public function modifyResponse($request, $response)
{
$app = $this->app;
if ($app->runningInConsole() || !$this->isEnabled() || $this->isDebugbarRequest()) {
return $response;
}
if ($this->shouldCollect('config', false)) {
try {
$configCollector = new ConfigCollector();
$configCollector->setData($app['config']->all());
$this->addCollector($configCollector);
} catch (\Exception $e) {
$this->addException(new Exception('Cannot add ConfigCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
}
}
/** @var \Illuminate\Session\SessionManager $sessionManager */
$sessionManager = $app['session'];
$httpDriver = new SymfonyHttpDriver($sessionManager, $response);
$this->setHttpDriver($httpDriver);
if ($this->shouldCollect('session')) {
try {
$this->addCollector(new SessionCollector($sessionManager));
} catch (\Exception $e) {
$this->addException(new Exception('Cannot add SessionCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
}
}
if ($this->shouldCollect('symfony_request', true) && !$this->hasCollector('request')) {
try {
$this->addCollector(new SymfonyRequestCollector($request, $response, $sessionManager));
} catch (\Exception $e) {
$this->addException(new Exception('Cannot add SymfonyRequestCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
}
}
if ($response->isRedirection()) {
try {
$this->stackData();
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
} elseif ($this->isJsonRequest($request) && $app['config']->get('debugbar.capture_ajax', true)) {
try {
$this->sendDataInHeaders(true);
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
} elseif ($response->headers->has('Content-Type') && strpos($response->headers->get('Content-Type'), 'html') === false || $request->getRequestFormat() !== 'html') {
try {
// Just collect + store data, don't inject it.
$this->collect();
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
} elseif ($app['config']->get('debugbar.inject', true)) {
try {
$this->injectDebugbar($response);
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
}
// Stop further rendering (on subrequests etc)
$this->disable();
return $response;
}
示例10: isHtmlResponse
/**
* Check if the response is a html page.
*
* @param Response $response
* @return bool
*/
private function isHtmlResponse(Response $response)
{
$headers = $response->headers;
// assumes responses without Content-Type header are html
return !$response->isRedirection() && (!$headers->has('Content-Type') || strpos($headers->get('Content-Type'), 'html') !== false);
}
示例11: assertRedirectedResponse
public function assertRedirectedResponse(Response $response)
{
$this->assertTrue($response->isRedirection());
}