This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/Symfony/Tests/Component/HttpKernel/HttpCache/TestHttpKernel.php

86 lines
2.2 KiB
PHP
Raw Normal View History

2010-06-23 20:42:41 +01:00
<?php
/*
* This file is part of the Symfony package.
2010-06-23 20:42:41 +01:00
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Tests\Component\HttpKernel\HttpCache;
2010-06-23 20:42:41 +01:00
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
2010-06-23 20:42:41 +01:00
class TestHttpKernel extends HttpKernel implements ControllerResolverInterface
2010-06-23 20:42:41 +01:00
{
protected $body;
protected $status;
protected $headers;
protected $called;
protected $customizer;
protected $catch;
2010-06-23 20:42:41 +01:00
public function __construct($body, $status, $headers, \Closure $customizer = null)
{
$this->body = $body;
$this->status = $status;
$this->headers = $headers;
$this->customizer = $customizer;
$this->called = false;
$this->catch = false;
2010-06-23 20:42:41 +01:00
parent::__construct(new EventDispatcher(), $this);
2010-06-23 20:42:41 +01:00
}
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
{
$this->catch = $catch;
return parent::handle($request, $type, $catch);
}
public function isCatchingExceptions()
{
return $this->catch;
}
public function getController(Request $request)
2010-06-23 20:42:41 +01:00
{
return array($this, 'callController');
}
2010-06-23 20:42:41 +01:00
public function getArguments(Request $request, $controller)
{
return array($request);
2010-06-23 20:42:41 +01:00
}
public function callController(Request $request)
{
$this->called = true;
$response = new Response($this->body, $this->status, $this->headers);
if (null !== $this->customizer) {
call_user_func($this->customizer, $request, $response);
}
return $response;
}
public function hasBeenCalled()
{
return $this->called;
}
public function reset()
{
$this->called = false;
}
}