2010-06-23 20:42:41 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-06-23 20:42:41 +01:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-06-23 20:42:41 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-01-26 20:38:45 +00:00
|
|
|
namespace Symfony\Tests\Component\HttpKernel\HttpCache;
|
2010-06-23 20:42:41 +01:00
|
|
|
|
2010-12-08 23:58:26 +00:00
|
|
|
use Symfony\Component\HttpKernel\HttpKernel;
|
2011-01-17 01:05:38 +00:00
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
|
2011-03-13 18:16:56 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
2010-06-23 20:42:41 +01:00
|
|
|
|
2010-12-08 23:58:26 +00: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;
|
2011-01-17 01:05:38 +00:00
|
|
|
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;
|
2011-01-17 01:05:38 +00:00
|
|
|
$this->catch = false;
|
2010-06-23 20:42:41 +01:00
|
|
|
|
2011-03-13 18:16:56 +00:00
|
|
|
parent::__construct(new EventDispatcher(), $this);
|
2010-06-23 20:42:41 +01:00
|
|
|
}
|
|
|
|
|
2011-01-17 01:05:38 +00:00
|
|
|
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
|
|
|
|
{
|
|
|
|
$this->catch = $catch;
|
2011-06-08 18:56:59 +01:00
|
|
|
|
2011-01-17 01:05:38 +00:00
|
|
|
return parent::handle($request, $type, $catch);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isCatchingExceptions()
|
|
|
|
{
|
|
|
|
return $this->catch;
|
|
|
|
}
|
|
|
|
|
2010-07-22 18:57:45 +01:00
|
|
|
public function getController(Request $request)
|
2010-06-23 20:42:41 +01:00
|
|
|
{
|
2010-07-22 18:57:45 +01:00
|
|
|
return array($this, 'callController');
|
|
|
|
}
|
2010-06-23 20:42:41 +01:00
|
|
|
|
2010-07-22 18:57:45 +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;
|
|
|
|
}
|
|
|
|
}
|