本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::isSuccessful方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::isSuccessful方法的具体用法?PHP Response::isSuccessful怎么用?PHP Response::isSuccessful使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::isSuccessful方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter
/**
*
*
* @param Event $event An Event instance
*/
public function filter(Event $event, Response $response)
{
if (!$configuration = $event->get('request')->attributes->get('_cache')) {
return $response;
}
if (!$response->isSuccessful()) {
return $response;
}
if (null !== $configuration->getSMaxAge()) {
$response->setSharedMaxAge($configuration->getSMaxAge());
}
if (null !== $configuration->getMaxAge()) {
$response->setMaxAge($configuration->getMaxAge());
}
if (null !== $configuration->getExpires()) {
$date = \DateTime::create(\DateTime::createFromFormat('U', $configuration->getExpires(), new \DateTimeZone('UTC')));
$response->setLastModified($date);
}
return $response;
}
示例2: formatData
private function formatData(Response $response)
{
if (!$response->isSuccessful()) {
// Response will have an exception attached
if ($response instanceof LaravelResponse && $response->exception instanceof Exception) {
return $this->formatException($response->exception);
}
}
$content = $response->getContent();
return $response instanceof JsonResponse ? json_decode($content) : $content;
}
示例3: isSuccessful
protected function isSuccessful(HttpResponse $response)
{
if ($response->isSuccessful()) {
if (false !== strpos($response->headers->get('Content-Type'), 'text/html')) {
if (preg_match('/form\\s+name="login_form"\\s+action="([^"]+)"/mi', $response->getContent(), $match)) {
return false;
}
}
return true;
}
return false;
}
示例4: 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);
}
示例5: 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();
}
示例6: testIsSuccessful
public function testIsSuccessful()
{
$response = new Response();
$this->assertTrue($response->isSuccessful());
}
示例7: deliver
/**
* Delivers the Response as a string.
*
* When the Response is a StreamedResponse, the content is streamed immediately
* instead of being returned.
*
* @param Response $response A Response instance
*
* @return string|null The Response content or null when the Response is streamed
*
* @throws \RuntimeException when the Response is not successful
*/
protected function deliver(Response $response)
{
if (!$response->isSuccessful()) {
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $this->requests[0]->getUri(), $response->getStatusCode()));
}
if (!$response instanceof StreamedResponse) {
return $response->getContent();
}
$response->sendContent();
}
示例8: isSuccessful
/**
* Checks the success state of a response.
*
* @param Response $response Response object
* @param bool $success to define whether the response is expected to be successful
* @param string $type
*/
public function isSuccessful(Response $response, $success = true, $type = 'text/html')
{
try {
$crawler = new Crawler();
$crawler->addContent($response->getContent(), $type);
if (!count($crawler->filter('title'))) {
$title = '[' . $response->getStatusCode() . '] - ' . $response->getContent();
} else {
$title = $crawler->filter('title')->text();
}
} catch (\Exception $e) {
$title = $e->getMessage();
}
if ($success) {
$this->assertTrue($response->isSuccessful(), 'The Response was not successful: ' . $title);
} else {
$this->assertFalse($response->isSuccessful(), 'The Response was successful: ' . $title);
}
}
示例9: isCacheable
/**
* @param Request $request
* @param Response $response
*
* @return bool|int Will return integer code if response cannot be cached or true if it's cacheable
*/
public function isCacheable(Request $request, Response $response)
{
if ($request->attributes->get('_supercache') === false) {
return CacheManager::UNCACHEABLE_ROUTE;
}
if ($request->getMethod() !== 'GET') {
return CacheManager::UNCACHEABLE_METHOD;
}
$queryString = $request->server->get('QUERY_STRING');
if (!empty($queryString)) {
return CacheManager::UNCACHEABLE_QUERY;
}
//Response::isCacheable() is unusable here due to expiry & code settings
if (!$response->isSuccessful() || $response->isEmpty()) {
return CacheManager::UNCACHEABLE_CODE;
}
if ($response->headers->hasCacheControlDirective('no-store')) {
return CacheManager::UNCACHEABLE_NO_STORE_POLICY;
}
if ($response->headers->hasCacheControlDirective('private')) {
return CacheManager::UNCACHEABLE_PRIVATE;
}
$environment = $this->container->getParameter('kernel.environment');
if ($environment !== 'prod' && $environment !== 'dev' || !$this->container->getParameter('supercache.enable_' . $environment)) {
return CacheManager::UNCACHEABLE_ENVIRONMENT;
}
return true;
}
示例10: showErrorInBrowserIfOccurred
/**
* @param Response $response
*
* @throws \Exception
*/
protected function showErrorInBrowserIfOccurred(Response $response)
{
if (!$response->isSuccessful()) {
$openCommand = isset($_SERVER['OPEN_BROWSER_COMMAND']) ? $_SERVER['OPEN_BROWSER_COMMAND'] : 'open %s';
$filename = rtrim(sys_get_temp_dir(), \DIRECTORY_SEPARATOR) . \DIRECTORY_SEPARATOR . uniqid() . '.html';
file_put_contents($filename, $response->getContent());
system(sprintf($openCommand, escapeshellarg($filename)));
throw new \Exception('Internal server error.');
}
}
示例11: isSuccessful
protected function isSuccessful(HttpResponse $response)
{
return $response->isSuccessful();
}
示例12: assertSuccessfulResponse
public function assertSuccessfulResponse(Response $response)
{
$this->assertTrue($response->isSuccessful());
}
示例13: store
/**
* Store successful responses with the cache resolver.
*
* @see ResolverInterface::store
*
* @param Response $response
* @param string $targetPath
* @param string $filter
*
* @return Response
*/
public function store(Response $response, $targetPath, $filter)
{
if ($response->isSuccessful()) {
$response = $this->getResolver($filter)->store($response, $targetPath, $filter);
}
return $response;
}
示例14: deliverResponse
/**
* Deliver response
*
* @param Request $request
* @param Response $response
*
* @return string
*/
protected function deliverResponse(Request $request, Response $response)
{
if (!$response->isSuccessful()) {
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $request->getUri(), $response->getStatusCode()));
}
return $response->getContent();
}
示例15: assertSuccessResponse
protected function assertSuccessResponse($expected, Response $response)
{
$this->assertTrue($response->isSuccessful(), 'request is successful');
$this->assertJson($response->getContent(), 'response is json');
$this->assertJsonResponse($expected, $response);
}