9133b9e5e4
The HttpFoundation component holds classes that wrap PHP native global arrays. The following classes has been moved: * Symfony\Components\HttpKernel\Response -> Symfony\Components\HttpFoundation\Response * Symfony\Components\HttpKernel\Request -> Symfony\Components\HttpFoundation\Request * Symfony\Framework\FoundationBundle\User -> Symfony\Components\HttpFoundation\Session * Symfony\Framework\FoundationBundle\Session\* -> Symfony\Components\HttpFoundation\SessionStorage\*Storage The web:user DI configuration has been moved to kernel:session. The user helper has been renamed to session.
70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the symfony package.
|
|
*
|
|
* (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\Components\HttpKernel\Cache;
|
|
|
|
use Symfony\Components\HttpKernel\HttpKernel;
|
|
use Symfony\Components\HttpFoundation\Request;
|
|
use Symfony\Components\HttpFoundation\Response;
|
|
use Symfony\Components\EventDispatcher\EventDispatcher;
|
|
use Symfony\Components\EventDispatcher\Event;
|
|
|
|
class TestHttpKernel extends HttpKernel
|
|
{
|
|
protected $body;
|
|
protected $status;
|
|
protected $headers;
|
|
protected $called;
|
|
protected $customizer;
|
|
|
|
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->dispatcher = new EventDispatcher();
|
|
$this->dispatcher->connect('core.load_controller', array($this, 'loadController'));
|
|
}
|
|
|
|
public function loadController(Event $event)
|
|
{
|
|
$event->setReturnValue(array(array($this, 'callController'), array($event['request'])));
|
|
|
|
return true;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|