Renamed EventArgs classes and adapted remaining code to EventManager
The only missing part is ContainerAwareEventManager::addEventSubscriberService(), because I'm not sure how to find out the class name of a service in the DIC. Also, inline documentation of this code needs to be finished once it is accepted.
This commit is contained in:
parent
a54d3e6fb0
commit
2cf3779a2c
@ -14,26 +14,27 @@ namespace Symfony\Bundle\AsseticBundle\CacheWarmer;
|
||||
use Assetic\AssetManager;
|
||||
use Assetic\AssetWriter;
|
||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Bundle\AsseticBundle\Event\WriteEventArgs;
|
||||
use Symfony\Bundle\AsseticBundle\Events;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
class AssetWriterCacheWarmer extends CacheWarmer
|
||||
{
|
||||
protected $am;
|
||||
protected $writer;
|
||||
protected $dispatcher;
|
||||
protected $evm;
|
||||
|
||||
public function __construct(AssetManager $am, AssetWriter $writer, EventDispatcher $dispatcher)
|
||||
public function __construct(AssetManager $am, AssetWriter $writer, EventManager $evm)
|
||||
{
|
||||
$this->am = $am;
|
||||
$this->writer = $writer;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->evm = $evm;
|
||||
}
|
||||
|
||||
public function warmUp($cacheDir)
|
||||
{
|
||||
// notify an event so custom stream wrappers can be registered lazily
|
||||
$this->dispatcher->notify(new Event(null, 'assetic.write'));
|
||||
$this->evm->dispatchEvent(Events::onAsseticWrite, new WriteEventArgs());
|
||||
|
||||
$this->writer->writeManagerAssets($this->am);
|
||||
}
|
||||
|
@ -14,11 +14,13 @@ namespace Symfony\Bundle\AsseticBundle\Command;
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Factory\LazyAssetManager;
|
||||
use Symfony\Bundle\FrameworkBundle\Command\Command;
|
||||
use Symfony\Bundle\AsseticBundle\Event\WriteEventArgs;
|
||||
use Symfony\Bundle\AsseticBundle\Events;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
/**
|
||||
* Dumps assets to the filesystem.
|
||||
@ -46,7 +48,8 @@ class DumpCommand extends Command
|
||||
$am = $this->container->get('assetic.asset_manager');
|
||||
|
||||
// notify an event so custom stream wrappers can be registered lazily
|
||||
$this->container->get('event_dispatcher')->notify(new Event(null, 'assetic.write', array('path' => $basePath)));
|
||||
$eventArgs = new WriteEventArgs($basePath);
|
||||
$this->container->get('event_manager')->dispatchEvent(Events::onAsseticWrite, $writeEventArgs);
|
||||
|
||||
if ($input->getOption('watch')) {
|
||||
return $this->watch($am, $basePath, $output, $this->container->getParameter('kernel.debug'));
|
||||
|
32
src/Symfony/Bundle/AsseticBundle/Event/WriteEventArgs.php
Normal file
32
src/Symfony/Bundle/AsseticBundle/Event/WriteEventArgs.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\AsseticBundle\Event;
|
||||
|
||||
use Doctrine\Common\EventArgs;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
*/
|
||||
class WriteEventArgs extends EventArgs
|
||||
{
|
||||
private $targetPath;
|
||||
|
||||
public function __construct($targetPath = null)
|
||||
{
|
||||
$this->targetPath = $targetPath;
|
||||
}
|
||||
|
||||
public function getTargetPath()
|
||||
{
|
||||
return $this->targetPath;
|
||||
}
|
||||
}
|
20
src/Symfony/Bundle/AsseticBundle/Events.php
Normal file
20
src/Symfony/Bundle/AsseticBundle/Events.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\AsseticBundle;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
*/
|
||||
final class Events
|
||||
{
|
||||
const onAsseticWrite = 'onAsseticWrite';
|
||||
}
|
@ -12,7 +12,8 @@
|
||||
namespace Symfony\Bundle\AsseticBundle\Tests\CacheWarmer;
|
||||
|
||||
use Symfony\Bundle\AsseticBundle\CacheWarmer\AssetWriterCacheWarmer;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Bundle\AsseticBundle\Event\WriteEventArgs;
|
||||
use Symfony\Bundle\AsseticBundle\Events;
|
||||
|
||||
class AssetWriterCacheWarmerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@ -29,18 +30,18 @@ class AssetWriterCacheWarmerTest extends \PHPUnit_Framework_TestCase
|
||||
$writer = $this->getMockBuilder('Assetic\\AssetWriter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcher');
|
||||
$evm = $this->getMock('Doctrine\\Common\\EventManager');
|
||||
|
||||
$event = new Event(null, 'assetic.write');
|
||||
$eventArgs = new WriteEventArgs();
|
||||
|
||||
$dispatcher->expects($this->once())
|
||||
->method('notify')
|
||||
->with($event);
|
||||
$evm->expects($this->once())
|
||||
->method('dispatchEvent')
|
||||
->with(Events::onAsseticWrite, $eventArgs);
|
||||
$writer->expects($this->once())
|
||||
->method('writeManagerAssets')
|
||||
->with($am);
|
||||
|
||||
$warmer = new AssetWriterCacheWarmer($am, $writer, $dispatcher);
|
||||
$warmer = new AssetWriterCacheWarmer($am, $writer, $evm);
|
||||
$warmer->warmUp('/path/to/cache');
|
||||
}
|
||||
}
|
||||
|
@ -12,17 +12,29 @@
|
||||
namespace Symfony\Bundle\FrameworkBundle;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventInterface;
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\Common\EventArgs;
|
||||
|
||||
/**
|
||||
* This EventDispatcher automatically gets the kernel listeners injected
|
||||
* Lazily loads listeners and subscribers from the dependency injection
|
||||
* container
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony.com>
|
||||
*/
|
||||
class ContainerAwareEventManager extends EventManager
|
||||
{
|
||||
protected $container;
|
||||
/**
|
||||
* The container from where services are loaded
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $container;
|
||||
|
||||
/**
|
||||
* The service IDs of the event listeners and subscribers
|
||||
* @var array
|
||||
*/
|
||||
private $listenerIds;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -34,53 +46,60 @@ class ContainerAwareEventManager extends EventManager
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function registerKernelListeners(array $listeners)
|
||||
{
|
||||
$this->listeners = $listeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Adds a service as event listener
|
||||
*
|
||||
* @param string|array $events One or more events for which the listener
|
||||
* is added
|
||||
* @param string $serviceId The ID of the listener service
|
||||
* @param integer $priority The higher this value, the earlier an event
|
||||
* listener will be triggered in the chain.
|
||||
* Defaults to 0.
|
||||
*/
|
||||
public function notify(EventInterface $event)
|
||||
public function addEventListenerService($events, $serviceId, $priority = 0)
|
||||
{
|
||||
foreach ($this->getListeners($event->getName()) as $listener) {
|
||||
if (is_array($listener) && is_string($listener[0])) {
|
||||
$listener[0] = $this->container->get($listener[0]);
|
||||
}
|
||||
call_user_func($listener, $event);
|
||||
if (!is_string($serviceId)) {
|
||||
throw new \InvalidArgumentException('Expected a string argument');
|
||||
}
|
||||
|
||||
foreach ((array)$events as $event) {
|
||||
// Prevent duplicate entries
|
||||
$this->listenerIds[$event][$serviceId] = $priority;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Adds a service as event subscriber
|
||||
*
|
||||
* @param string $serviceId The ID of the subscriber service
|
||||
* @param integer $priority The higher this value, the earlier an event
|
||||
* listener will be triggered in the chain.
|
||||
* Defaults to 0.
|
||||
*/
|
||||
public function notifyUntil(EventInterface $event)
|
||||
public function addEventSuscriberService($serviceId, $priority = 0)
|
||||
{
|
||||
foreach ($this->getListeners($event->getName()) as $listener) {
|
||||
if (is_array($listener) && is_string($listener[0])) {
|
||||
$listener[0] = $this->container->get($listener[0]);
|
||||
}
|
||||
|
||||
$ret = call_user_func($listener, $event);
|
||||
if ($event->isProcessed()) {
|
||||
return $ret;
|
||||
}
|
||||
if (!is_string($serviceId)) {
|
||||
throw new \InvalidArgumentException('Expected a string argument');
|
||||
}
|
||||
|
||||
// TODO get class name, call static method getSubscribedEvents()
|
||||
// and pass to addEventListenerService
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* Lazily loads listeners for this event from the dependency injection
|
||||
* container.
|
||||
*/
|
||||
public function filter(EventInterface $event, $value)
|
||||
public function dispatchEvent($eventName, EventArgs $eventArgs = null)
|
||||
{
|
||||
foreach ($this->getListeners($event->getName()) as $listener) {
|
||||
if (is_array($listener) && is_string($listener[0])) {
|
||||
$listener[0] = $this->container->get($listener[0]);
|
||||
if (isset($this->listenerIds[$eventName])) {
|
||||
foreach ($this->listenerIds[$eventName] as $serviceId => $priority) {
|
||||
$this->addEventListener($eventName, $this->container->get($serviceId), $priority);
|
||||
}
|
||||
$value = call_user_func($listener, $event, $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
parent::dispatchEvent($eventName, $eventArgs);
|
||||
}
|
||||
}
|
||||
|
@ -11,18 +11,18 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Debug;
|
||||
|
||||
use Doctrine\Common\EventManager;
|
||||
use Symfony\Component\EventDispatcher\EventInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\ContainerAwareEventManager;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Debug\TraceableEventManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\Common\EventArgs;
|
||||
|
||||
/**
|
||||
* EventDispatcher extends the original EventDispatcher class to add some debugging tools.
|
||||
* Extends the ContainerAwareEventManager to add some debugging tools.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class TraceableEventManager extends EventManager implements TraceableEventManagerInterface
|
||||
class TraceableEventManager extends ContainerAwareEventManager implements TraceableEventManagerInterface
|
||||
{
|
||||
protected $logger;
|
||||
protected $called;
|
||||
@ -41,6 +41,14 @@ class TraceableEventManager extends EventManager implements TraceableEventManage
|
||||
$this->called = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function dispatchEvent($eventName, EventArgs $eventArgs = null)
|
||||
{
|
||||
parent::dispatchEvent($eventName, $eventArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@ -57,52 +65,6 @@ class TraceableEventManager extends EventManager implements TraceableEventManage
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function notifyUntil(EventInterface $event)
|
||||
{
|
||||
foreach ($this->getListeners($event->getName()) as $i => $listener) {
|
||||
if (is_array($listener) && is_string($listener[0])) {
|
||||
$listener[0] = $this->container->get($listener[0]);
|
||||
}
|
||||
|
||||
$this->addCall($event, $listener, 'notifyUntil');
|
||||
|
||||
$ret = call_user_func($listener, $event);
|
||||
if ($event->isProcessed()) {
|
||||
if (null !== $this->logger) {
|
||||
$this->logger->debug(sprintf('Listener "%s" processed the event "%s"', $this->listenerToString($listener), $event->getName()));
|
||||
|
||||
$listeners = $this->getListeners($event->getName());
|
||||
while (++$i < count($listeners)) {
|
||||
$this->logger->debug(sprintf('Listener "%s" was not called for event "%s"', $this->listenerToString($listeners[$i]), $event->getName()));
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function filter(EventInterface $event, $value)
|
||||
{
|
||||
foreach ($this->getListeners($event->getName()) as $listener) {
|
||||
if (is_array($listener) && is_string($listener[0])) {
|
||||
$listener[0] = $this->container->get($listener[0]);
|
||||
}
|
||||
|
||||
$this->addCall($event, $listener, 'filter');
|
||||
|
||||
$value = call_user_func($listener, $event, $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@ -163,7 +125,6 @@ class TraceableEventManager extends EventManager implements TraceableEventManage
|
||||
|
||||
$this->called[$event->getName().'.'.$listener] = array(
|
||||
'event' => $event->getName(),
|
||||
'caller' => null !== $event->getSubject() ? get_class($event->getSubject()) : null,
|
||||
'listener' => $listener,
|
||||
);
|
||||
}
|
||||
|
@ -19,35 +19,25 @@ class RegisterKernelListenersPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('event_dispatcher')) {
|
||||
if (!$container->hasDefinition('event_manager')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$listeners = array();
|
||||
$definition = $container->getDefinition('event_manager');
|
||||
|
||||
foreach ($container->findTaggedServiceIds('kernel.listener') as $id => $events) {
|
||||
foreach ($events as $event) {
|
||||
$priority = isset($event['priority']) ? $event['priority'] : 0;
|
||||
|
||||
var_dump($id);
|
||||
|
||||
if (!isset($event['event'])) {
|
||||
throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "kernel.listener" tags.', $id));
|
||||
$definition->addMethodCall('addEventSubscriberService', array($id, $priority));
|
||||
} else {
|
||||
$definition->addMethodCall('addEventListenerService', array($event['event'], $id, $priority));
|
||||
}
|
||||
if (!isset($event['method'])) {
|
||||
throw new \InvalidArgumentException(sprintf('Service "%s" must define the "method" attribute on "kernel.listener" tags.', $id));
|
||||
}
|
||||
|
||||
if (!isset($listeners[$event['event']][$priority])) {
|
||||
if (!isset($listeners[$event['event']])) {
|
||||
$listeners[$event['event']] = array();
|
||||
}
|
||||
$listeners[$event['event']][$priority] = array();
|
||||
}
|
||||
|
||||
$listeners[$event['event']][$priority][] = array($id, $event['method']);
|
||||
}
|
||||
}
|
||||
|
||||
$container
|
||||
->getDefinition('event_dispatcher')
|
||||
->addMethodCall('registerKernelListeners', array($listeners))
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ class FrameworkExtension extends Extension
|
||||
|
||||
if ($container->getParameter('kernel.debug')) {
|
||||
$loader->load('debug.xml');
|
||||
$container->setDefinition('event_dispatcher', $container->findDefinition('debug.event_dispatcher'));
|
||||
$container->setAlias('debug.event_dispatcher', 'event_dispatcher');
|
||||
$container->setDefinition('event_manager', $container->findDefinition('debug.event_manager'));
|
||||
$container->setAlias('debug.event_manager', 'event_manager');
|
||||
}
|
||||
|
||||
$processor = new Processor();
|
||||
@ -140,10 +140,13 @@ class FrameworkExtension extends Extension
|
||||
'Symfony\\Component\\HttpKernel\\ResponseListener',
|
||||
'Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver',
|
||||
'Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface',
|
||||
'Symfony\\Component\\HttpKernel\\Event\\RequestEventArgs',
|
||||
'Symfony\\Component\\HttpKernel\\Event\\ControllerEventArgs',
|
||||
'Symfony\\Component\\HttpKernel\\Event\\ViewEventArgs',
|
||||
'Symfony\\Component\\HttpKernel\\Event\\ExceptionEventArgs',
|
||||
'Symfony\\Component\\HttpKernel\\Event\\KernelEventArgs',
|
||||
'Symfony\\Component\\HttpKernel\\Event\\FilterControllerEventArgs',
|
||||
'Symfony\\Component\\HttpKernel\\Event\\FilterResponseEventArgs',
|
||||
'Symfony\\Component\\HttpKernel\\Event\\GetResponseEventArgs',
|
||||
'Symfony\\Component\\HttpKernel\\Event\\GetResponseForControllerResultEventArgs',
|
||||
'Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEventArgs',
|
||||
'Symfony\\Component\\HttpKernel\\Events',
|
||||
|
||||
'Symfony\\Bundle\\FrameworkBundle\\RequestListener',
|
||||
'Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerNameParser',
|
||||
|
@ -14,7 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\HttpFoundation;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEventArgs;
|
||||
|
||||
/**
|
||||
* SessionListener.
|
||||
@ -29,12 +29,12 @@ class SessionListener
|
||||
* Checks if session was initialized and saves if current request is master
|
||||
* Runs on 'filterCoreResponse' in test environment
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs
|
||||
* @param FilterResponseEventArgs $eventArgs
|
||||
*/
|
||||
public function filterCoreResponse(RequestEventArgs $eventArgs)
|
||||
public function filterCoreResponse(FilterResponseEventArgs $eventArgs)
|
||||
{
|
||||
if ($request = $event->getRequest()) {
|
||||
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
|
||||
if ($request = $eventArgs->getRequest()) {
|
||||
if (HttpKernelInterface::MASTER_REQUEST === $eventArgs->getRequestType()) {
|
||||
if ($session = $request->getSession()) {
|
||||
$session->save();
|
||||
}
|
||||
|
@ -16,13 +16,14 @@ use Doctrine\Common\EventManager;
|
||||
*/
|
||||
class HttpKernel extends BaseHttpKernel
|
||||
{
|
||||
protected $container;
|
||||
protected $esiSupport;
|
||||
private $container;
|
||||
private $esiSupport;
|
||||
|
||||
public function __construct(ContainerInterface $container, ControllerResolverInterface $controllerResolver)
|
||||
public function __construct(EventManager $evm, ContainerInterface $container, ControllerResolverInterface $controllerResolver)
|
||||
{
|
||||
parent::__construct($evm, $controllerResolver);
|
||||
|
||||
$this->container = $container;
|
||||
$this->resolver = $controllerResolver;
|
||||
}
|
||||
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
|
||||
|
@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Profiler;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEventArgs;
|
||||
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
@ -62,7 +62,7 @@ class ProfilerListener
|
||||
*
|
||||
* @param EventInterface $eventArgs An EventInterface instance
|
||||
*/
|
||||
public function filterCoreResponse(RequestEventArgs $eventArgs)
|
||||
public function filterCoreResponse(FilterResponseEventArgs $eventArgs)
|
||||
{
|
||||
if (HttpKernelInterface::MASTER_REQUEST !== $eventArgs->getRequestType()) {
|
||||
return;
|
||||
|
@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
@ -36,7 +36,7 @@ class RequestListener
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function onCoreRequest(RequestEventArgs $eventArgs)
|
||||
public function onCoreRequest(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
$request = $eventArgs->getRequest();
|
||||
$master = HttpKernelInterface::MASTER_REQUEST === $eventArgs->getRequestType();
|
||||
|
@ -25,9 +25,9 @@
|
||||
</service>
|
||||
|
||||
<service id="http_kernel" class="%http_kernel.class%">
|
||||
<argument type="service" id="event_manager" />
|
||||
<argument type="service" id="service_container" />
|
||||
<argument type="service" id="controller_resolver" />
|
||||
<call method="setEventManager"><argument type="service" id="event_manager" /></call>
|
||||
</service>
|
||||
|
||||
<service id="cache_warmer" class="%cache_warmer.class%">
|
||||
|
@ -12,10 +12,10 @@
|
||||
namespace Symfony\Bundle\FrameworkBundle\Tests\HttpFoundation;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\HttpFoundation\SessionListener;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEventArgs;
|
||||
|
||||
/**
|
||||
* SessionListenerTest.
|
||||
@ -53,10 +53,12 @@ class SessionListenerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$request->setSession($this->session);
|
||||
$response = new Response();
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
$eventArgs = new FilterResponseEventArgs($kernel, $request, $type, $response);
|
||||
|
||||
$this->assertSame($response, $this->listener->filter(new Event(
|
||||
$this, 'filterCoreResponse', array('request' => $request, 'request_type' => $type)
|
||||
), $response));
|
||||
$this->listener->filterCoreResponse($eventArgs);
|
||||
|
||||
$this->assertSame($response, $eventArgs->getResponse());
|
||||
}
|
||||
|
||||
private function sessionMustNotBeSaved()
|
||||
|
@ -5,9 +5,9 @@ namespace Symfony\Bundle\FrameworkBundle\Tests;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Bundle\FrameworkBundle\HttpKernel;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@ -36,10 +36,9 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
->with($this->equalTo('request'), $this->equalTo($request), $this->equalTo('request'))
|
||||
;
|
||||
|
||||
$dispatcher = new EventDispatcher();
|
||||
$evm = new EventManager();
|
||||
$resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
|
||||
$kernel = new HttpKernel($container, $resolver);
|
||||
$kernel->setEventDispatcher($dispatcher);
|
||||
$kernel = new HttpKernel($evm, $container, $resolver);
|
||||
|
||||
$controller = function() use($expected)
|
||||
{
|
||||
@ -85,10 +84,9 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
->with($this->equalTo('request'), $this->equalTo($request), $this->equalTo('request'))
|
||||
;
|
||||
|
||||
$dispatcher = new EventDispatcher();
|
||||
$evm = new EventManager();
|
||||
$resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
|
||||
$kernel = new HttpKernel($container, $resolver);
|
||||
$kernel->setEventDispatcher($dispatcher);
|
||||
$kernel = new HttpKernel($evm, $container, $resolver);
|
||||
|
||||
$controller = function() use ($expected)
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Bundle\FrameworkBundle\HttpKernel;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEventArgs;
|
||||
use Symfony\Bundle\TwigBundle\TwigEngine;
|
||||
|
||||
/**
|
||||
@ -41,7 +41,7 @@ class WebDebugToolbarListener
|
||||
$this->interceptRedirects = $interceptRedirects;
|
||||
}
|
||||
|
||||
public function filterCoreResponse(RequestEventArgs $eventArgs)
|
||||
public function filterCoreResponse(FilterResponseEventArgs $eventArgs)
|
||||
{
|
||||
if (HttpKernelInterface::MASTER_REQUEST !== $eventArgs->getRequestType()) {
|
||||
return;
|
||||
|
@ -13,7 +13,7 @@ namespace Symfony\Component\HttpKernel\Debug;
|
||||
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Event\ExceptionEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEventArgs;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\FlattenException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@ -34,7 +34,7 @@ class ExceptionListener
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function onCoreException(ExceptionEventArgs $eventArgs)
|
||||
public function onCoreException(GetResponseForExceptionEventArgs $eventArgs)
|
||||
{
|
||||
static $handling;
|
||||
|
||||
@ -44,8 +44,8 @@ class ExceptionListener
|
||||
|
||||
$handling = true;
|
||||
|
||||
$exception = $eventArgs->get('exception');
|
||||
$request = $eventArgs->get('request');
|
||||
$exception = $eventArgs->getException();
|
||||
$request = $eventArgs->getRequest();
|
||||
|
||||
if (null !== $this->logger) {
|
||||
$this->logger->err(sprintf('%s: %s (uncaught exception)', get_class($exception), $exception->getMessage()));
|
||||
@ -66,7 +66,7 @@ class ExceptionListener
|
||||
$request = $request->duplicate(null, null, $attributes);
|
||||
|
||||
try {
|
||||
$response = $eventArgs->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
|
||||
$response = $eventArgs->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
|
||||
} catch (\Exception $e) {
|
||||
$message = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage());
|
||||
if (null !== $this->logger) {
|
||||
@ -77,12 +77,11 @@ class ExceptionListener
|
||||
|
||||
// set handling to false otherwise it wont be able to handle further more
|
||||
$handling = false;
|
||||
|
||||
|
||||
// re-throw the exception as this is a catch-all
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$eventArgs->setHandled(true);
|
||||
$eventArgs->setResponse($response);
|
||||
|
||||
$handling = false;
|
||||
|
@ -11,23 +11,18 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Event;
|
||||
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class ControllerEventArgs extends RequestEventArgs
|
||||
class FilterControllerEventArgs extends KernelEventArgs
|
||||
{
|
||||
private $controller;
|
||||
|
||||
public function __construct(KernelInterface $kernel, $controller, Request $request, $requestType)
|
||||
public function __construct(HttpKernelInterface $kernel, $controller, Request $request, $requestType)
|
||||
{
|
||||
// controller must be a callable
|
||||
if (!is_callable($controller)) {
|
||||
throw new \LogicException(sprintf('The controller must be a callable (%s given).', $this->varToString($controller)));
|
||||
}
|
||||
|
||||
parent::__construct($kernel, $request, $requestType);
|
||||
|
||||
$this->controller = $controller;
|
||||
$this->setController($controller);
|
||||
}
|
||||
|
||||
public function getController()
|
@ -0,0 +1,38 @@
|
||||
<?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\Component\HttpKernel\Event;
|
||||
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class FilterResponseEventArgs extends KernelEventArgs
|
||||
{
|
||||
private $response;
|
||||
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, $requestType, Response $response)
|
||||
{
|
||||
parent::__construct($kernel, $request, $requestType);
|
||||
|
||||
$this->setResponse($response);
|
||||
}
|
||||
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
public function setResponse(Response $response)
|
||||
{
|
||||
$this->response = $response;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?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\Component\HttpKernel\Event;
|
||||
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class GetResponseEventArgs extends KernelEventArgs
|
||||
{
|
||||
private $response;
|
||||
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
public function setResponse(Response $response)
|
||||
{
|
||||
$this->response = $response;
|
||||
|
||||
$this->stopPropagation();
|
||||
}
|
||||
|
||||
public function hasResponse()
|
||||
{
|
||||
return null !== $this->response;
|
||||
}
|
||||
}
|
@ -11,14 +11,14 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Event;
|
||||
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class ViewEventArgs extends RequestEventArgs
|
||||
class GetResponseForControllerResultEventArgs extends GetResponseEventArgs
|
||||
{
|
||||
private $controllerResult;
|
||||
|
||||
public function __construct(KernelInterface $kernel, $controllerResult, Request $request, $requestType)
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, $requestType, $controllerResult)
|
||||
{
|
||||
parent::__construct($kernel, $request, $requestType);
|
||||
|
@ -11,20 +11,18 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Event;
|
||||
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class ExceptionEventArgs extends RequestEventArgs
|
||||
class GetResponseForExceptionEventArgs extends GetResponseEventArgs
|
||||
{
|
||||
private $exception;
|
||||
|
||||
private $handled = false;
|
||||
|
||||
public function __construct(KernelInterface $kernel, \Exception $e, Request $request, $requestType)
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, $requestType, \Exception $e)
|
||||
{
|
||||
parent::__construct($kernel, $request, $requestType);
|
||||
|
||||
$this->exception = $e;
|
||||
$this->setException($e);
|
||||
}
|
||||
|
||||
public function getException()
|
||||
@ -36,16 +34,4 @@ class ExceptionEventArgs extends RequestEventArgs
|
||||
{
|
||||
$this->exception = $exception;
|
||||
}
|
||||
|
||||
public function setHandled($handled)
|
||||
{
|
||||
$this->handled = $handled;
|
||||
|
||||
$this->stopPropagation();
|
||||
}
|
||||
|
||||
public function isHandled()
|
||||
{
|
||||
return $this->handled;
|
||||
}
|
||||
}
|
@ -11,12 +11,11 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Event;
|
||||
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Doctrine\Common\EventArgs;
|
||||
|
||||
class RequestEventArgs extends EventArgs
|
||||
class KernelEventArgs extends EventArgs
|
||||
{
|
||||
private $kernel;
|
||||
|
||||
@ -24,14 +23,11 @@ class RequestEventArgs extends EventArgs
|
||||
|
||||
private $requestType;
|
||||
|
||||
private $response;
|
||||
|
||||
public function __construct(KernelInterface $kernel, Request $request, $requestType, Response $response = null)
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, $requestType)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
$this->request = $request;
|
||||
$this->requestType = $requestType;
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
public function getKernel()
|
||||
@ -48,21 +44,4 @@ class RequestEventArgs extends EventArgs
|
||||
{
|
||||
return $this->requestType;
|
||||
}
|
||||
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
public function setResponse(Response $response)
|
||||
{
|
||||
$this->response = $response;
|
||||
|
||||
$this->stopPropagation();
|
||||
}
|
||||
|
||||
public function hasResponse()
|
||||
{
|
||||
return null !== $this->response;
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ final class Events
|
||||
|
||||
const onCoreView = 'onCoreView';
|
||||
|
||||
const filterCoreRespone = 'filterCoreResponse';
|
||||
const filterCoreResponse = 'filterCoreResponse';
|
||||
|
||||
const onCoreSecurity = 'onCoreSecurity';
|
||||
}
|
@ -13,7 +13,7 @@ namespace Symfony\Component\HttpKernel\HttpCache;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEventArgs;
|
||||
|
||||
/**
|
||||
* EsiListener adds a Surrogate-Control HTTP header when the Response needs to be parsed for ESI.
|
||||
@ -38,9 +38,9 @@ class EsiListener
|
||||
/**
|
||||
* Filters the Response.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs A RequestEventArgs instance
|
||||
* @param FilterResponseEventArgs $eventArgs A FilterResponseEventArgs instance
|
||||
*/
|
||||
public function filterCoreResponse(RequestEventArgs $eventArgs)
|
||||
public function filterCoreResponse(FilterResponseEventArgs $eventArgs)
|
||||
{
|
||||
if (HttpKernelInterface::MASTER_REQUEST !== $eventArgs->getRequestType() || null === $this->esi) {
|
||||
return;
|
||||
|
@ -13,10 +13,11 @@ namespace Symfony\Component\HttpKernel;
|
||||
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Event\ControllerEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\ExceptionEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\ViewEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\FilterControllerEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEventArgs;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Doctrine\Common\EventManager;
|
||||
@ -28,8 +29,8 @@ use Doctrine\Common\EventManager;
|
||||
*/
|
||||
class HttpKernel implements HttpKernelInterface
|
||||
{
|
||||
protected $evm;
|
||||
protected $resolver;
|
||||
private $evm;
|
||||
private $resolver;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -56,10 +57,10 @@ class HttpKernel implements HttpKernelInterface
|
||||
}
|
||||
|
||||
// exception
|
||||
$eventArgs = new ExceptionEventArgs($this, $e, $request, $type);
|
||||
$eventArgs = new GetResponseForExceptionEventArgs($this, $request, $type, $e);
|
||||
$this->evm->dispatchEvent(Events::onCoreException, $eventArgs);
|
||||
|
||||
if (!$eventArgs->isHandled()) {
|
||||
if (!$eventArgs->hasResponse()) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
@ -85,7 +86,7 @@ class HttpKernel implements HttpKernelInterface
|
||||
protected function handleRaw(Request $request, $type = self::MASTER_REQUEST)
|
||||
{
|
||||
// request
|
||||
$eventArgs = new RequestEventArgs($this, $request, $type);
|
||||
$eventArgs = new GetResponseEventArgs($this, $request, $type);
|
||||
$this->evm->dispatchEvent(Events::onCoreRequest, $eventArgs);
|
||||
|
||||
if ($eventArgs->hasResponse()) {
|
||||
@ -97,7 +98,7 @@ class HttpKernel implements HttpKernelInterface
|
||||
throw new NotFoundHttpException(sprintf('Unable to find the controller for path "%s". Maybe you forgot to add the matching route in your routing configuration?', $request->getPathInfo()));
|
||||
}
|
||||
|
||||
$eventArgs = new ControllerEventArgs($this, $controller, $request, $type);
|
||||
$eventArgs = new FilterControllerEventArgs($this, $controller, $request, $type);
|
||||
$this->evm->dispatchEvent(Events::filterCoreController, $eventArgs);
|
||||
$controller = $eventArgs->getController();
|
||||
|
||||
@ -109,8 +110,8 @@ class HttpKernel implements HttpKernelInterface
|
||||
|
||||
// view
|
||||
if (!$response instanceof Response) {
|
||||
$eventArgs = new ViewEventArgs($this, $response, $request, $type);
|
||||
$this->dispatchEvent(Events::onCoreView, $eventArgs);
|
||||
$eventArgs = new GetResponseForControllerResultEventArgs($this, $request, $type, $response);
|
||||
$this->evm->dispatchEvent(Events::onCoreView, $eventArgs);
|
||||
|
||||
if ($eventArgs->hasResponse()) {
|
||||
$response = $eventArgs->getResponse();
|
||||
@ -137,11 +138,11 @@ class HttpKernel implements HttpKernelInterface
|
||||
*/
|
||||
protected function filterResponse(Response $response, Request $request, $type)
|
||||
{
|
||||
$eventArgs = new RequestEventArgs($this, $request, $type, $response);
|
||||
$eventArgs = new FilterResponseEventArgs($this, $request, $type, $response);
|
||||
|
||||
$this->evm->dispatchEvent(Events::filterCoreResponse, $eventArgs);
|
||||
|
||||
return $event->getResponse();
|
||||
return $eventArgs->getResponse();
|
||||
}
|
||||
|
||||
protected function varToString($var)
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel;
|
||||
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEventArgs;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
@ -31,11 +31,11 @@ class ResponseListener
|
||||
/**
|
||||
* Filters the Response.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs A RequestEventArgs instance
|
||||
* @param FilterResponseEventArgs $eventArgs A FilterResponseEventArgs instance
|
||||
*/
|
||||
public function filterCoreResponse(RequestEventArgs $eventArgs)
|
||||
public function filterCoreResponse(FilterResponseEventArgs $eventArgs)
|
||||
{
|
||||
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
|
||||
if (HttpKernelInterface::MASTER_REQUEST !== $eventArgs->getRequestType()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ class ResponseListener
|
||||
return;
|
||||
}
|
||||
|
||||
$request = $event->getRequest();
|
||||
$request = $eventArgs->getRequest();
|
||||
$format = $request->getRequestFormat();
|
||||
if ((null !== $format) && $mimeType = $request->getMimeType($format)) {
|
||||
$response->headers->set('Content-Type', $mimeType);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Symfony\Component\Security\Http\Authentication;
|
||||
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
@ -22,12 +22,12 @@ interface AuthenticationFailureHandlerInterface
|
||||
* called by authentication listeners inheriting from
|
||||
* AbstractAuthenticationListener.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs the "onCoreSecurity" event, this event always
|
||||
* @param GetResponseEventArgs $eventArgs the "onCoreSecurity" event, this event always
|
||||
* has the kernel as target
|
||||
* @param Request $request
|
||||
* @param AuthenticationException $exception
|
||||
*
|
||||
* @return Response the response to return
|
||||
*/
|
||||
function onAuthenticationFailure(RequestEventArgs $eventArgs, Request $request, AuthenticationException $exception);
|
||||
function onAuthenticationFailure(GetResponseEventArgs $eventArgs, Request $request, AuthenticationException $exception);
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Symfony\Component\Security\Http\Authentication;
|
||||
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
@ -22,12 +22,12 @@ interface AuthenticationSuccessHandlerInterface
|
||||
* is called by authentication listeners inheriting from
|
||||
* AbstractAuthenticationListener.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs the "onCoreSecurity" event, this event always
|
||||
* @param GetResponseEventArgs $eventArgs the "onCoreSecurity" event, this event always
|
||||
* has the kernel as target
|
||||
* @param Request $request
|
||||
* @param TokenInterface $token
|
||||
*
|
||||
* @return Response the response to return
|
||||
*/
|
||||
function onAuthenticationSuccess(RequestEventArgs $eventArgs, Request $request, TokenInterface $token);
|
||||
function onAuthenticationSuccess(GetResponseEventArgs $eventArgs, Request $request, TokenInterface $token);
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Security\Http\EntryPoint;
|
||||
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
@ -26,9 +26,9 @@ interface AuthenticationEntryPointInterface
|
||||
/**
|
||||
* Starts the authentication scheme.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs The "onCoreSecurity" event
|
||||
* @param GetResponseEventArgs $eventArgs The "onCoreSecurity" event
|
||||
* @param object $request The request that resulted in an AuthenticationException
|
||||
* @param AuthenticationException $authException The exception that started the authentication process
|
||||
*/
|
||||
function start(RequestEventArgs $eventArgs, Request $request, AuthenticationException $authException = null);
|
||||
function start(GetResponseEventArgs $eventArgs, Request $request, AuthenticationException $authException = null);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
|
||||
/**
|
||||
* BasicAuthenticationEntryPoint starts an HTTP Basic authentication.
|
||||
@ -31,7 +31,7 @@ class BasicAuthenticationEntryPoint implements AuthenticationEntryPointInterface
|
||||
$this->realmName = $realmName;
|
||||
}
|
||||
|
||||
public function start(RequestEventArgs $event, Request $request, AuthenticationException $authException = null)
|
||||
public function start(GetResponseEventArgs $event, Request $request, AuthenticationException $authException = null)
|
||||
{
|
||||
$response = new Response();
|
||||
$response->headers->set('WWW-Authenticate', sprintf('Basic realm="%s"', $this->realmName));
|
||||
|
@ -17,7 +17,7 @@ use Symfony\Component\Security\Core\Exception\NonceExpiredException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
|
||||
/**
|
||||
* DigestAuthenticationEntryPoint starts an HTTP Digest authentication.
|
||||
@ -39,7 +39,7 @@ class DigestAuthenticationEntryPoint implements AuthenticationEntryPointInterfac
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function start(RequestEventArgs $eventArgs, Request $request, AuthenticationException $authException = null)
|
||||
public function start(GetResponseEventArgs $eventArgs, Request $request, AuthenticationException $authException = null)
|
||||
{
|
||||
$expiryTime = microtime(true) + $this->nonceValiditySeconds * 1000;
|
||||
$signatureValue = md5($expiryTime.':'.$this->key);
|
||||
|
@ -17,7 +17,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
|
||||
/**
|
||||
* FormAuthenticationEntryPoint starts an authentication via a login form.
|
||||
@ -44,7 +44,7 @@ class FormAuthenticationEntryPoint implements AuthenticationEntryPointInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function start(RequestEventArgs $eventArgs, Request $request, AuthenticationException $authException = null)
|
||||
public function start(GetResponseEventArgs $eventArgs, Request $request, AuthenticationException $authException = null)
|
||||
{
|
||||
if ($this->useForward) {
|
||||
return $event->getKernel()->handle(Request::create($this->loginPath), HttpKernelInterface::SUB_REQUEST);
|
||||
|
@ -16,7 +16,7 @@ use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
|
||||
/**
|
||||
* RetryAuthenticationEntryPoint redirects URL based on the configured scheme.
|
||||
@ -36,7 +36,7 @@ class RetryAuthenticationEntryPoint implements AuthenticationEntryPointInterface
|
||||
$this->httpsPort = $httpsPort;
|
||||
}
|
||||
|
||||
public function start(RequestEventArgs $eventArgs, Request $request, AuthenticationException $authException = null)
|
||||
public function start(GetResponseEventArgs $eventArgs, Request $request, AuthenticationException $authException = null)
|
||||
{
|
||||
$scheme = $request->isSecure() ? 'http' : 'https';
|
||||
if ('http' === $scheme && 80 != $this->httpPort) {
|
||||
|
@ -13,7 +13,7 @@ namespace Symfony\Component\Security\Http;
|
||||
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Events;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
@ -48,9 +48,9 @@ class Firewall
|
||||
/**
|
||||
* Handles security.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs An RequestEventArgs instance
|
||||
* @param GetResponseEventArgs $eventArgs An GetResponseEventArgs instance
|
||||
*/
|
||||
public function onCoreRequest(RequestEventArgs $eventArgs)
|
||||
public function onCoreRequest(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
if (HttpKernelInterface::MASTER_REQUEST !== $eventArgs->getRequestType()) {
|
||||
return;
|
||||
@ -83,7 +83,7 @@ class Firewall
|
||||
}
|
||||
|
||||
// initiate the listener chain
|
||||
$securityEventArgs = new RequestEventArgs($eventArgs->getKernel(), $request, $eventArgs->getRequestType());
|
||||
$securityEventArgs = new GetResponseEventArgs($eventArgs->getKernel(), $request, $eventArgs->getRequestType());
|
||||
$this->evm->dispatchEvent($securityEventArgs);
|
||||
|
||||
if ($securityEventArgs->hasResponse()) {
|
||||
|
@ -21,7 +21,7 @@ use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Events as KernelEvents;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
@ -125,7 +125,7 @@ abstract class AbstractAuthenticationListener implements ListenerInterface
|
||||
*
|
||||
* @param Event $event An Event instance
|
||||
*/
|
||||
public function onCoreSecurity(RequestEventArgs $eventArgs)
|
||||
public function onCoreSecurity(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
$request = $eventArgs->getRequest();
|
||||
|
||||
@ -170,7 +170,7 @@ abstract class AbstractAuthenticationListener implements ListenerInterface
|
||||
return $this->options['check_path'] === $request->getPathInfo();
|
||||
}
|
||||
|
||||
protected function onFailure(RequestEventArgs $eventArgs, Request $request, AuthenticationException $failed)
|
||||
protected function onFailure(GetResponseEventArgs $eventArgs, Request $request, AuthenticationException $failed)
|
||||
{
|
||||
if (null !== $this->logger) {
|
||||
$this->logger->debug(sprintf('Authentication request failed: %s', $failed->getMessage()));
|
||||
@ -206,7 +206,7 @@ abstract class AbstractAuthenticationListener implements ListenerInterface
|
||||
return new RedirectResponse(0 !== strpos($this->options['failure_path'], 'http') ? $request->getUriForPath($this->options['failure_path']) : $this->options['failure_path'], 302);
|
||||
}
|
||||
|
||||
protected function onSuccess(RequestEventArgs $eventArgs, Request $request, TokenInterface $token)
|
||||
protected function onSuccess(GetResponseEventArgs $eventArgs, Request $request, TokenInterface $token)
|
||||
{
|
||||
if (null !== $this->logger) {
|
||||
$this->logger->debug('User has been authenticated successfully');
|
||||
|
@ -17,7 +17,7 @@ use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\Security\Http\Event\InteractiveLoginEventArgs;
|
||||
use Symfony\Component\Security\Http\Events;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Events as KernelEvents;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@ -70,7 +70,7 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface
|
||||
*
|
||||
* @param EventInterface $event An EventInterface instance
|
||||
*/
|
||||
public function onCoreSecurity(RequestEventArgs $eventArgs)
|
||||
public function onCoreSecurity(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
$request = $eventArgs->getRequest();
|
||||
|
||||
|
@ -16,7 +16,7 @@ use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface
|
||||
use Symfony\Component\Security\Http\AccessMap;
|
||||
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Events;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
@ -64,9 +64,9 @@ class AccessListener implements ListenerInterface
|
||||
/**
|
||||
* Handles access authorization.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs A RequestEventArgs instance
|
||||
* @param GetResponseEventArgs $eventArgs A GetResponseEventArgs instance
|
||||
*/
|
||||
public function onCoreSecurity(RequestEventArgs $eventArgs)
|
||||
public function onCoreSecurity(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
if (null === $token = $this->context->getToken()) {
|
||||
throw new AuthenticationCredentialsNotFoundException('A Token was not found in the SecurityContext.');
|
||||
|
@ -13,7 +13,7 @@ namespace Symfony\Component\Security\Http\Firewall;
|
||||
|
||||
use Symfony\Component\Security\Core\SecurityContextInterface;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Events;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
|
||||
use Doctrine\Common\EventManager;
|
||||
@ -58,9 +58,9 @@ class AnonymousAuthenticationListener implements ListenerInterface
|
||||
/**
|
||||
* Handles anonymous authentication.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs A RequestEventArgs instance
|
||||
* @param GetResponseEventArgs $eventArgs A GetResponseEventArgs instance
|
||||
*/
|
||||
public function onCoreSecurity(RequestEventArgs $eventArgs)
|
||||
public function onCoreSecurity(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
if (null !== $this->context->getToken()) {
|
||||
return;
|
||||
|
@ -15,7 +15,7 @@ use Symfony\Component\Security\Core\SecurityContextInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
|
||||
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Events;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
@ -69,11 +69,11 @@ class BasicAuthenticationListener implements ListenerInterface
|
||||
/**
|
||||
* Handles basic authentication.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs A RequestEventArgs instance
|
||||
* @param GetResponseEventArgs $eventArgs A GetResponseEventArgs instance
|
||||
*/
|
||||
public function onCoreSecurity(RequestEventArgs $eventArgs)
|
||||
public function onCoreSecurity(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
$request = $event->get('request');
|
||||
$request = $eventArgs->getRequest();
|
||||
|
||||
if (false === $username = $request->server->get('PHP_AUTH_USER', false)) {
|
||||
return;
|
||||
|
@ -14,7 +14,7 @@ namespace Symfony\Component\Security\Http\Firewall;
|
||||
use Symfony\Component\Security\Http\AccessMap;
|
||||
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Events;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
@ -57,9 +57,9 @@ class ChannelListener implements ListenerInterface
|
||||
/**
|
||||
* Handles channel management.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs A RequestEventArgs instance
|
||||
* @param GetResponseEventArgs $eventArgs A GetResponseEventArgs instance
|
||||
*/
|
||||
public function onCoreSecurity(RequestEventArgs $eventArgs)
|
||||
public function onCoreSecurity(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
$request = $eventArgs->getRequest();
|
||||
|
||||
|
@ -14,7 +14,8 @@ namespace Symfony\Component\Security\Http\Firewall;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEventArgs;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
||||
@ -73,9 +74,9 @@ class ContextListener implements ListenerInterface
|
||||
/**
|
||||
* Reads the SecurityContext from the session.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs A RequestEventArgs instance
|
||||
* @param GetResponseEventArgs $eventArgs A GetResponseEventArgs instance
|
||||
*/
|
||||
public function onCoreSecurity(RequestEventArgs $eventArgs)
|
||||
public function onCoreSecurity(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
$request = $eventArgs->getRequest();
|
||||
|
||||
@ -103,7 +104,7 @@ class ContextListener implements ListenerInterface
|
||||
*
|
||||
* @param EventInterface $event An EventInterface instance
|
||||
*/
|
||||
public function filterCoreResponse(RequestEventArgs $eventArgs)
|
||||
public function filterCoreResponse(FilterResponseEventArgs $eventArgs)
|
||||
{
|
||||
if (HttpKernelInterface::MASTER_REQUEST !== $eventArgs->getRequestType()) {
|
||||
return;
|
||||
|
@ -15,7 +15,7 @@ use Symfony\Component\Security\Core\SecurityContextInterface;
|
||||
use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||||
use Symfony\Component\Security\Http\EntryPoint\DigestAuthenticationEntryPoint;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Events;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
||||
@ -72,9 +72,9 @@ class DigestAuthenticationListener implements ListenerInterface
|
||||
/**
|
||||
* Handles digest authentication.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs A RequestEventArgs instance
|
||||
* @param GetResponseEventArgs $eventArgs A GetResponseEventArgs instance
|
||||
*/
|
||||
public function onCoreSecurity(RequestEventArgs $eventArgs)
|
||||
public function onCoreSecurity(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
$request = $eventArgs->getRequest();
|
||||
|
||||
|
@ -142,7 +142,6 @@ class ExceptionListener implements ListenerInterface
|
||||
return;
|
||||
}
|
||||
|
||||
$eventArgs->setHandled(true);
|
||||
$eventArgs->setResponse($response);
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
|
||||
use Symfony\Component\Security\Core\SecurityContextInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\Kernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\Kernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\Kernel\Events;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
@ -81,9 +81,9 @@ class LogoutListener implements ListenerInterface
|
||||
/**
|
||||
* Performs the logout if requested
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs A RequestEventArgs instance
|
||||
* @param GetResponseEventArgs $eventArgs A GetResponseEventArgs instance
|
||||
*/
|
||||
public function onCoreSecurity(RequestEventArgs $eventArgs)
|
||||
public function onCoreSecurity(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
$request = $eventArgs->getRequest();
|
||||
|
||||
|
@ -4,7 +4,8 @@ namespace Symfony\Component\Security\Http\Firewall;
|
||||
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Events as KernelEvents;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
@ -82,9 +83,9 @@ class RememberMeListener implements ListenerInterface
|
||||
/**
|
||||
* Handles remember-me cookie based authentication.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs A RequestEventArgs instance
|
||||
* @param GetResponseEventArgs $eventArgs A GetResponseEventArgs instance
|
||||
*/
|
||||
public function onCoreSecurity(RequestEventArgs $eventArgs)
|
||||
public function onCoreSecurity(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
$this->lastState = null;
|
||||
|
||||
@ -143,7 +144,7 @@ class RememberMeListener implements ListenerInterface
|
||||
* Update cookies
|
||||
* @param Event $event
|
||||
*/
|
||||
public function filterCoreResponse(RequestEventArgs $eventArgs)
|
||||
public function filterCoreResponse(FilterResponseEventArgs $eventArgs)
|
||||
{
|
||||
if (HttpKernelInterface::MASTER_REQUEST !== $eventArgs->getRequestType()) {
|
||||
return;
|
||||
|
@ -16,7 +16,7 @@ use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||||
use Symfony\Component\Security\Core\User\AccountCheckerInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Events;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@ -89,9 +89,9 @@ class SwitchUserListener implements ListenerInterface
|
||||
/**
|
||||
* Handles digest authentication.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs A RequestEventArgs instance
|
||||
* @param GetResponseEventArgs $eventArgs A GetResponseEventArgs instance
|
||||
*/
|
||||
public function onCoreSecurity(RequestEventArgs $eventArgs)
|
||||
public function onCoreSecurity(GetResponseEventArgs $eventArgs)
|
||||
{
|
||||
$request = $eventArgs->getRequest();
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace Symfony\Component\Security\Http\Logout;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEventArgs;
|
||||
|
||||
/**
|
||||
* LogoutSuccesshandlerInterface.
|
||||
@ -21,9 +21,9 @@ interface LogoutSuccessHandlerInterface
|
||||
/**
|
||||
* Creates a Response object to send upon a successful logout.
|
||||
*
|
||||
* @param RequestEventArgs $eventArgs
|
||||
* @param GetResponseEventArgs $eventArgs
|
||||
* @param Request $request
|
||||
* @return Response never null
|
||||
*/
|
||||
function onLogoutSuccess(RequestEventArgs $eventArgs, Request $request);
|
||||
function onLogoutSuccess(GetResponseEventArgs $eventArgs, Request $request);
|
||||
}
|
@ -15,8 +15,6 @@ use Symfony\Component\HttpKernel\Client;
|
||||
use Symfony\Component\HttpKernel\HttpKernel;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
require_once __DIR__.'/TestHttpKernel.php';
|
||||
|
||||
|
@ -14,8 +14,8 @@ namespace Symfony\Tests\Component\HttpKernel\DataCollector;
|
||||
use Symfony\Component\HttpKernel\DataCollector\EventDataCollector;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Debug\EventDispatcherTraceableInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpKernel\Debug\TraceableEventManagerInterface;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
|
||||
class EventDataCollectorTest extends \PHPUnit_Framework_TestCase
|
||||
@ -23,18 +23,18 @@ class EventDataCollectorTest extends \PHPUnit_Framework_TestCase
|
||||
public function testCollect()
|
||||
{
|
||||
$c = new EventDataCollector();
|
||||
$c->setEventDispatcher(new TestEventDispatcher());
|
||||
|
||||
$c->setEventManager(new TestEventManager());
|
||||
|
||||
$c->collect(new Request(), new Response());
|
||||
|
||||
|
||||
$this->assertSame('events',$c->getName());
|
||||
$this->assertSame(array('foo'),$c->getCalledListeners());
|
||||
$this->assertSame(array('bar'),$c->getNotCalledListeners());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class TestEventDispatcher extends EventDispatcher implements EventDispatcherTraceableInterface
|
||||
class TestEventManager extends EventManager implements TraceableEventManagerInterface
|
||||
{
|
||||
function getCalledListeners()
|
||||
{
|
||||
|
@ -11,11 +11,13 @@
|
||||
|
||||
namespace Symfony\Tests\Component\HttpKernel\Debug;
|
||||
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Debug\ExceptionListener;
|
||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Debug\ErrorException;
|
||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEventArgs;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Tests\Component\HttpKernel\Logger;
|
||||
|
||||
/**
|
||||
@ -29,72 +31,74 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$logger = new TestLogger();
|
||||
$l = new ExceptionListener('foo', $logger);
|
||||
|
||||
$_logger = new \ReflectionProperty(get_class($l),'logger');
|
||||
|
||||
$_logger = new \ReflectionProperty(get_class($l), 'logger');
|
||||
$_logger->setAccessible(true);
|
||||
$_controller = new \ReflectionProperty(get_class($l),'controller');
|
||||
$_controller = new \ReflectionProperty(get_class($l), 'controller');
|
||||
$_controller->setAccessible(true);
|
||||
|
||||
$this->assertSame($logger,$_logger->getValue($l));
|
||||
$this->assertSame('foo',$_controller->getValue($l));
|
||||
|
||||
$this->assertSame($logger, $_logger->getValue($l));
|
||||
$this->assertSame('foo', $_controller->getValue($l));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testHandleWithoutLogger($event,$event2)
|
||||
public function testHandleWithoutLogger($eventArgs, $eventArgs2)
|
||||
{
|
||||
//store the current error_log, and set the new one to dev/null
|
||||
$error_log = ini_get('error_log');
|
||||
ini_set('error_log','/dev/null');
|
||||
|
||||
$l = new ExceptionListener('foo');
|
||||
ini_set('error_log', '/dev/null');
|
||||
|
||||
$this->assertEquals('foo', $l->handle($event));
|
||||
|
||||
try{
|
||||
$response = $l->handle($event2);
|
||||
}catch(\Exception $e){
|
||||
$this->assertSame('foo',$e->getMessage());
|
||||
$l = new ExceptionListener('foo');
|
||||
$l->onCoreException($eventArgs);
|
||||
|
||||
$this->assertEquals(new Response('foo'), $eventArgs->getResponse());
|
||||
|
||||
try {
|
||||
$l->onCoreException($eventArgs2);
|
||||
} catch(\Exception $e) {
|
||||
$this->assertSame('foo', $e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
//restore the old error_log
|
||||
ini_set('error_log',$error_log);
|
||||
ini_set('error_log', $error_log);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testHandleWithLogger($event, $event2)
|
||||
public function testHandleWithLogger($eventArgs, $eventArgs2)
|
||||
{
|
||||
$logger = new TestLogger();
|
||||
|
||||
$l = new ExceptionListener('foo',$logger);
|
||||
|
||||
$this->assertSame('foo', $l->handle($event));
|
||||
|
||||
try{
|
||||
$response = $l->handle($event2);
|
||||
}catch(\Exception $e){
|
||||
$this->assertSame('foo',$e->getMessage());
|
||||
|
||||
$l = new ExceptionListener('foo', $logger);
|
||||
$l->onCoreException($eventArgs);
|
||||
|
||||
$this->assertEquals(new Response('foo'), $eventArgs->getResponse());
|
||||
|
||||
try {
|
||||
$l->onCoreException($eventArgs2);
|
||||
} catch(\Exception $e) {
|
||||
$this->assertSame('foo', $e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertEquals(3,$logger->countErrors());
|
||||
$this->assertEquals(3,count($logger->getLogs('err')));
|
||||
|
||||
$this->assertEquals(3, $logger->countErrors());
|
||||
$this->assertEquals(3, count($logger->getLogs('err')));
|
||||
}
|
||||
|
||||
|
||||
public function provider()
|
||||
{
|
||||
$args = array('exception'=>new ErrorException('foo'),'request'=>new Request());
|
||||
|
||||
$event = new Event(new Subject(),'bar',$args);
|
||||
$event2 = new Event(new SubjectException(),'bar',$args);
|
||||
$request = new Request();
|
||||
$exception = new ErrorException('foo');
|
||||
$eventArgs = new GetResponseForExceptionEventArgs(new TestKernel(), $request, 'foo', $exception);
|
||||
$eventArgs2 = new GetResponseForExceptionEventArgs(new TestKernelThatThrowsException(), $request, 'foo', $exception);
|
||||
|
||||
return array(
|
||||
array($event,$event2)
|
||||
array($eventArgs, $eventArgs2)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class TestLogger extends Logger implements DebugLoggerInterface
|
||||
@ -103,25 +107,25 @@ class TestLogger extends Logger implements DebugLoggerInterface
|
||||
{
|
||||
return count($this->logs['err']);
|
||||
}
|
||||
|
||||
|
||||
public function getDebugLogger()
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
}
|
||||
|
||||
class Subject
|
||||
class TestKernel implements HttpKernelInterface
|
||||
{
|
||||
public function handle()
|
||||
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
|
||||
{
|
||||
return 'foo';
|
||||
return new Response('foo');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class SubjectException
|
||||
class TestKernelThatThrowsException implements HttpKernelInterface
|
||||
{
|
||||
public function handle()
|
||||
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
|
||||
{
|
||||
throw new \Exception('bar');
|
||||
}
|
||||
|
@ -13,46 +13,54 @@ namespace Symfony\Tests\Component\HttpKernel\HttpCache;
|
||||
|
||||
use Symfony\Component\HttpKernel\HttpCache\Esi;
|
||||
use Symfony\Component\HttpKernel\HttpCache\EsiListener;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Events;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
class EsiListenerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFilterDoesNothingForSubRequests()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$evm = new EventManager();
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
$response = new Response('foo <esi:include src="" />');
|
||||
$listener = new EsiListener(new Esi());
|
||||
$dispatcher->connect('core.response', array($listener, 'filter'));
|
||||
|
||||
$event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::SUB_REQUEST));
|
||||
$dispatcher->filter($event, $response = new Response('foo <esi:include src="" />'));
|
||||
$evm->addEventListener(Events::filterCoreResponse, $listener);
|
||||
$eventArgs = new FilterResponseEventArgs($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
|
||||
$evm->dispatchEvent(Events::filterCoreResponse, $eventArgs);
|
||||
|
||||
$this->assertEquals('', $response->headers->get('Surrogate-Control'));
|
||||
$this->assertEquals('', $eventArgs->getResponse()->headers->get('Surrogate-Control'));
|
||||
}
|
||||
|
||||
public function testFilterWhenThereIsSomeEsiIncludes()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$evm = new EventManager();
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
$response = new Response('foo <esi:include src="" />');
|
||||
$listener = new EsiListener(new Esi());
|
||||
$dispatcher->connect('core.response', array($listener, 'filter'));
|
||||
|
||||
$event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST));
|
||||
$dispatcher->filter($event, $response = new Response('foo <esi:include src="" />'));
|
||||
$evm->addEventListener(Events::filterCoreResponse, $listener);
|
||||
$eventArgs = new FilterResponseEventArgs($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
$evm->dispatchEvent(Events::filterCoreResponse, $eventArgs);
|
||||
|
||||
$this->assertEquals('content="ESI/1.0"', $response->headers->get('Surrogate-Control'));
|
||||
$this->assertEquals('content="ESI/1.0"', $eventArgs->getResponse()->headers->get('Surrogate-Control'));
|
||||
}
|
||||
|
||||
public function testFilterWhenThereIsNoEsiIncludes()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$evm = new EventManager();
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
$response = new Response('foo');
|
||||
$listener = new EsiListener(new Esi());
|
||||
$dispatcher->connect('core.response', array($listener, 'filter'));
|
||||
|
||||
$event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST));
|
||||
$dispatcher->filter($event, $response = new Response('foo'));
|
||||
$evm->addEventListener(Events::filterCoreResponse, $listener);
|
||||
$eventArgs = new FilterResponseEventArgs($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
$evm->dispatchEvent(Events::filterCoreResponse, $eventArgs);
|
||||
|
||||
$this->assertEquals('', $response->headers->get('Surrogate-Control'));
|
||||
$this->assertEquals('', $eventArgs->getResponse()->headers->get('Surrogate-Control'));
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ 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;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
class TestHttpKernel extends HttpKernel implements ControllerResolverInterface
|
||||
{
|
||||
@ -36,7 +36,7 @@ class TestHttpKernel extends HttpKernel implements ControllerResolverInterface
|
||||
$this->called = false;
|
||||
$this->catch = false;
|
||||
|
||||
parent::__construct(new EventDispatcher(), $this);
|
||||
parent::__construct(new EventManager(), $this);
|
||||
}
|
||||
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
|
||||
|
@ -15,8 +15,8 @@ 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;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInterface
|
||||
{
|
||||
@ -39,7 +39,7 @@ class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInt
|
||||
$this->headers[] = $response['headers'];
|
||||
}
|
||||
|
||||
parent::__construct(new EventDispatcher(), $this);
|
||||
parent::__construct(new EventManager(), $this);
|
||||
}
|
||||
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
|
||||
|
@ -13,9 +13,10 @@ namespace Symfony\Tests\Component\HttpKernel;
|
||||
|
||||
use Symfony\Component\HttpKernel\HttpKernel;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Events;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@ -24,7 +25,7 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testHandleWhenControllerThrowsAnExceptionAndRawIsTrue()
|
||||
{
|
||||
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));
|
||||
$kernel = new HttpKernel(new EventManager(), $this->getResolver(function () { throw new \RuntimeException(); }));
|
||||
|
||||
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
|
||||
}
|
||||
@ -34,37 +35,33 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testHandleWhenControllerThrowsAnExceptionAndRawIsFalseAndNoListenerIsRegistered()
|
||||
{
|
||||
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));
|
||||
$kernel = new HttpKernel(new EventManager(), $this->getResolver(function () { throw new \RuntimeException(); }));
|
||||
|
||||
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false);
|
||||
}
|
||||
|
||||
public function testHandleWhenControllerThrowsAnExceptionAndRawIsFalse()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->connect('core.exception', function ($event)
|
||||
$evm = new EventManager();
|
||||
$evm->addEventListener(Events::onCoreException, function ($eventArgs)
|
||||
{
|
||||
$event->setProcessed();
|
||||
|
||||
return new Response($event->get('exception')->getMessage());
|
||||
$eventArgs->setResponse(new Response($eventArgs->getException()->getMessage()));
|
||||
});
|
||||
|
||||
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { throw new \RuntimeException('foo'); }));
|
||||
$kernel = new HttpKernel($evm, $this->getResolver(function () { throw new \RuntimeException('foo'); }));
|
||||
|
||||
$this->assertEquals('foo', $kernel->handle(new Request())->getContent());
|
||||
}
|
||||
|
||||
public function testHandleWhenAListenerReturnsAResponse()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->connect('core.request', function ($event)
|
||||
$evm = new EventManager();
|
||||
$evm->addEventListener(Events::onCoreRequest, function ($eventArgs)
|
||||
{
|
||||
$event->setProcessed();
|
||||
|
||||
return new Response('hello');
|
||||
$eventArgs->setResponse(new Response('hello'));
|
||||
});
|
||||
|
||||
$kernel = new HttpKernel($dispatcher, $this->getResolver());
|
||||
$kernel = new HttpKernel($evm, $this->getResolver());
|
||||
|
||||
$this->assertEquals('hello', $kernel->handle(new Request())->getContent());
|
||||
}
|
||||
@ -74,8 +71,8 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testHandleWhenNoControllerIsFound()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$kernel = new HttpKernel($dispatcher, $this->getResolver(false));
|
||||
$evm = new EventManager();
|
||||
$kernel = new HttpKernel($evm, $this->getResolver(false));
|
||||
|
||||
$kernel->handle(new Request());
|
||||
}
|
||||
@ -85,77 +82,43 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testHandleWhenNoControllerIsNotACallable()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$kernel = new HttpKernel($dispatcher, $this->getResolver('foobar'));
|
||||
$evm = new EventManager();
|
||||
$kernel = new HttpKernel($evm, $this->getResolver('foobar'));
|
||||
|
||||
$kernel->handle(new Request());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException RuntimeException
|
||||
* @expectedException LogicException
|
||||
*/
|
||||
public function testHandleWhenControllerDoesNotReturnAResponse()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { return 'foo'; }));
|
||||
$evm = new EventManager();
|
||||
$kernel = new HttpKernel($evm, $this->getResolver(function () { return 'foo'; }));
|
||||
|
||||
$kernel->handle(new Request());
|
||||
}
|
||||
|
||||
public function testHandleWhenControllerDoesNotReturnAResponseButAViewIsRegistered()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->connect('core.view', function ($event)
|
||||
$evm = new EventManager();
|
||||
$evm->addEventListener(Events::onCoreView, function ($eventArgs)
|
||||
{
|
||||
$event->setProcessed();
|
||||
|
||||
return new Response($event->get('controller_value'));
|
||||
$eventArgs->setResponse(new Response($eventArgs->getControllerResult()));
|
||||
});
|
||||
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { return 'foo'; }));
|
||||
$kernel = new HttpKernel($evm, $this->getResolver(function () { return 'foo'; }));
|
||||
|
||||
$this->assertEquals('foo', $kernel->handle(new Request())->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException RuntimeException
|
||||
*/
|
||||
public function testHandleWhenAViewDoesNotReturnAResponse()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->connect('core.view', function ($event)
|
||||
{
|
||||
$event->setProcessed();
|
||||
|
||||
return $event->get('controller_value');
|
||||
});
|
||||
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { return 'foo'; }));
|
||||
|
||||
$kernel->handle(new Request());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException RuntimeException
|
||||
*/
|
||||
public function testHandleWhenAResponseListenerDoesNotReturnAResponse()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->connect('core.response', function ($event, $response)
|
||||
{
|
||||
return 'foo';
|
||||
});
|
||||
$kernel = new HttpKernel($dispatcher, $this->getResolver());
|
||||
|
||||
$kernel->handle(new Request());
|
||||
}
|
||||
|
||||
public function testHandleWithAResponseListener()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->connect('core.response', function ($event, $response)
|
||||
$evm = new EventManager();
|
||||
$evm->addEventListener(Events::filterCoreResponse, function ($eventArgs)
|
||||
{
|
||||
return new Response('foo');
|
||||
$eventArgs->setResponse(new Response('foo'));
|
||||
});
|
||||
$kernel = new HttpKernel($dispatcher, $this->getResolver());
|
||||
$kernel = new HttpKernel($evm, $this->getResolver());
|
||||
|
||||
$this->assertEquals('foo', $kernel->handle(new Request())->getContent());
|
||||
}
|
||||
|
@ -12,56 +12,68 @@
|
||||
namespace Symfony\Tests\Component\HttpKernel;
|
||||
|
||||
use Symfony\Component\HttpKernel\ResponseListener;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEventArgs;
|
||||
use Symfony\Component\HttpKernel\Events;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
class ResponseListenerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $evm;
|
||||
|
||||
private $kernel;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->evm = new EventManager();
|
||||
$listener = new ResponseListener('UTF-8');
|
||||
$this->evm->addEventListener(Events::filterCoreResponse, $listener);
|
||||
|
||||
$this->kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
|
||||
}
|
||||
public function testFilterDoesNothingForSubRequests()
|
||||
{
|
||||
$event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::SUB_REQUEST));
|
||||
$this->getDispatcher()->filter($event, $response = new Response('foo'));
|
||||
$response = new Response('foo');
|
||||
|
||||
$this->assertEquals('', $response->headers->get('content-type'));
|
||||
$eventArgs = new FilterResponseEventArgs($this->kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
|
||||
$this->evm->dispatchEvent(Events::filterCoreResponse, $eventArgs);
|
||||
|
||||
$this->assertEquals('', $eventArgs->getResponse()->headers->get('content-type'));
|
||||
}
|
||||
|
||||
public function testFilterDoesNothingIfContentTypeIsSet()
|
||||
{
|
||||
$event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST));
|
||||
$response = new Response('foo');
|
||||
$response->headers->set('Content-Type', 'text/plain');
|
||||
$this->getDispatcher()->filter($event, $response);
|
||||
|
||||
$this->assertEquals('text/plain', $response->headers->get('content-type'));
|
||||
$eventArgs = new FilterResponseEventArgs($this->kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
$this->evm->dispatchEvent(Events::filterCoreResponse, $eventArgs);
|
||||
|
||||
$this->assertEquals('text/plain', $eventArgs->getResponse()->headers->get('content-type'));
|
||||
}
|
||||
|
||||
public function testFilterDoesNothingIfRequestFormatIsNotDefined()
|
||||
{
|
||||
$event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST, 'request' => Request::create('/')));
|
||||
$this->getDispatcher()->filter($event, $response = new Response('foo'));
|
||||
$response = new Response('foo');
|
||||
|
||||
$this->assertEquals('', $response->headers->get('content-type'));
|
||||
$eventArgs = new FilterResponseEventArgs($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
$this->evm->dispatchEvent(Events::filterCoreResponse, $eventArgs);
|
||||
|
||||
$this->assertEquals('', $eventArgs->getResponse()->headers->get('content-type'));
|
||||
}
|
||||
|
||||
public function testFilterSetContentType()
|
||||
{
|
||||
$response = new Response('foo');
|
||||
$request = Request::create('/');
|
||||
$request->setRequestFormat('json');
|
||||
$event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST, 'request' => $request));
|
||||
$this->getDispatcher()->filter($event, $response = new Response('foo'));
|
||||
|
||||
$this->assertEquals('application/json', $response->headers->get('content-type'));
|
||||
}
|
||||
$eventArgs = new FilterResponseEventArgs($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
|
||||
$this->evm->dispatchEvent(Events::filterCoreResponse, $eventArgs);
|
||||
|
||||
protected function getDispatcher()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$listener = new ResponseListener('UTF-8');
|
||||
$dispatcher->connect('core.response', array($listener, 'filter'));
|
||||
|
||||
return $dispatcher;
|
||||
$this->assertEquals('application/json', $eventArgs->getResponse()->headers->get('content-type'));
|
||||
}
|
||||
}
|
||||
|
@ -14,14 +14,14 @@ namespace Symfony\Tests\Component\HttpKernel;
|
||||
use Symfony\Component\HttpKernel\HttpKernel;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
|
||||
use Doctrine\Common\EventManager;
|
||||
|
||||
class TestHttpKernel extends HttpKernel implements ControllerResolverInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new EventDispatcher(), $this);
|
||||
parent::__construct(new EventManager(), $this);
|
||||
}
|
||||
|
||||
public function getController(Request $request)
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Symfony\Tests\Component\Security\Http\Firewall;
|
||||
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Events;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Exception\CookieTheftException;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
@ -15,22 +16,17 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
list($listener,,,,) = $this->getListener();
|
||||
|
||||
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcher');
|
||||
$dispatcher
|
||||
->expects($this->at(0))
|
||||
->method('connect')
|
||||
->with($this->equalTo('core.security'))
|
||||
;
|
||||
$dispatcher
|
||||
->expects($this->at(1))
|
||||
->method('connect')
|
||||
->with($this->equalTo('core.response'))
|
||||
$evm = $this->getMock('Doctrine\Common\EventManager');
|
||||
$evm
|
||||
->expects($this->once())
|
||||
->method('addEventListener')
|
||||
->with($this->equalTo(array(Events::onCoreSecurity, Events::filterCoreResponse)))
|
||||
;
|
||||
|
||||
$listener->register($dispatcher);
|
||||
$listener->register($evm);
|
||||
}
|
||||
|
||||
public function testCheckCookiesDoesNotTryToPopulateNonEmptySecurityContext()
|
||||
public function testOnCoreSecurityDoesNotTryToPopulateNonEmptySecurityContext()
|
||||
{
|
||||
list($listener, $context, $service,,) = $this->getListener();
|
||||
|
||||
@ -46,11 +42,11 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
;
|
||||
|
||||
$this->assertNull($this->getLastState($listener));
|
||||
$this->assertNull($listener->checkCookies($this->getEvent()));
|
||||
$this->assertNull($listener->onCoreSecurity($this->getGetResponseEvent()));
|
||||
$this->assertNull($this->getLastState($listener));
|
||||
}
|
||||
|
||||
public function testCheckCookiesDoesNothingWhenNoCookieIsSet()
|
||||
public function testOnCoreSecurityDoesNothingWhenNoCookieIsSet()
|
||||
{
|
||||
list($listener, $context, $service,,) = $this->getListener();
|
||||
|
||||
@ -66,20 +62,19 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
->will($this->returnValue(null))
|
||||
;
|
||||
|
||||
$event = $this->getEvent();
|
||||
$event = $this->getGetResponseEvent();
|
||||
$event
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('request')
|
||||
->method('getRequest')
|
||||
->will($this->returnValue(new Request()))
|
||||
;
|
||||
|
||||
$this->assertNull($this->getLastState($listener));
|
||||
$this->assertNull($listener->checkCookies($event));
|
||||
$this->assertNull($listener->onCoreSecurity($event));
|
||||
$this->assertNull($this->getLastState($listener));
|
||||
}
|
||||
|
||||
public function testCheckCookiesIgnoresAuthenticationExceptionThrownByTheRememberMeServicesImplementation()
|
||||
public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByTheRememberMeServicesImplementation()
|
||||
{
|
||||
list($listener, $context, $service,,) = $this->getListener();
|
||||
|
||||
@ -96,20 +91,19 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
->will($this->throwException($exception))
|
||||
;
|
||||
|
||||
$event = $this->getEvent();
|
||||
$event = $this->getGetResponseEvent();
|
||||
$event
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('request')
|
||||
->method('getRequest')
|
||||
->will($this->returnValue(new Request()))
|
||||
;
|
||||
|
||||
$this->assertNull($this->getLastState($listener));
|
||||
$this->assertNull($listener->checkCookies($event));
|
||||
$this->assertNull($listener->onCoreSecurity($event));
|
||||
$this->assertSame($exception, $this->getLastState($listener));
|
||||
}
|
||||
|
||||
public function testCheckCookiesThrowsCookieTheftExceptionIfThrownByTheRememberMeServicesImplementation()
|
||||
public function testOnCoreSecurityThrowsCookieTheftExceptionIfThrownByTheRememberMeServicesImplementation()
|
||||
{
|
||||
list($listener, $context, $service,,) = $this->getListener();
|
||||
|
||||
@ -126,16 +120,15 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
->will($this->throwException($exception))
|
||||
;
|
||||
|
||||
$event = $this->getEvent();
|
||||
$event = $this->getGetResponseEvent();
|
||||
$event
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('request')
|
||||
->method('getRequest')
|
||||
->will($this->returnValue(new Request()))
|
||||
;
|
||||
|
||||
try {
|
||||
$listener->checkCookies($event);
|
||||
$listener->onCoreSecurity($event);
|
||||
}
|
||||
catch (CookieTheftException $theft) {
|
||||
$this->assertSame($theft, $this->getLastState($listener));
|
||||
@ -146,7 +139,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->fail('Expected CookieTheftException was not thrown.');
|
||||
}
|
||||
|
||||
public function testCheckCookiesAuthenticationManagerDoesNotChangeListenerStateWhenTokenIsNotSupported()
|
||||
public function testOnCoreSecurityAuthenticationManagerDoesNotChangeListenerStateWhenTokenIsNotSupported()
|
||||
{
|
||||
list($listener, $context, $service, $manager,) = $this->getListener();
|
||||
|
||||
@ -162,20 +155,19 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
->will($this->returnValue($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')))
|
||||
;
|
||||
|
||||
$event = $this->getEvent();
|
||||
$event = $this->getGetResponseEvent();
|
||||
$event
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('request')
|
||||
->method('getRequest')
|
||||
->will($this->returnValue(new Request()))
|
||||
;
|
||||
|
||||
$this->assertNull($this->getLastState($listener));
|
||||
$this->assertNull($listener->checkCookies($event));
|
||||
$this->assertNull($listener->onCoreSecurity($event));
|
||||
$this->assertNull($this->getLastState($listener));
|
||||
}
|
||||
|
||||
public function testCheckCookiesIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation()
|
||||
public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation()
|
||||
{
|
||||
list($listener, $context, $service, $manager,) = $this->getListener();
|
||||
|
||||
@ -198,20 +190,19 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
->will($this->throwException($exception))
|
||||
;
|
||||
|
||||
$event = $this->getEvent();
|
||||
$event = $this->getGetResponseEvent();
|
||||
$event
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('request')
|
||||
->method('getRequest')
|
||||
->will($this->returnValue(new Request()))
|
||||
;
|
||||
|
||||
$this->assertNull($this->getLastState($listener));
|
||||
$this->assertNull($listener->checkCookies($event));
|
||||
$this->assertNull($listener->onCoreSecurity($event));
|
||||
$this->assertSame($exception, $this->getLastState($listener));
|
||||
}
|
||||
|
||||
public function testCheckCookies()
|
||||
public function testOnCoreSecurity()
|
||||
{
|
||||
list($listener, $context, $service, $manager,) = $this->getListener();
|
||||
|
||||
@ -240,37 +231,41 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
->will($this->returnValue($token))
|
||||
;
|
||||
|
||||
$event = $this->getEvent();
|
||||
$event = $this->getGetResponseEvent();
|
||||
$event
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('request')
|
||||
->method('getRequest')
|
||||
->will($this->returnValue(new Request()))
|
||||
;
|
||||
|
||||
$this->assertNull($this->getLastState($listener));
|
||||
$this->assertNull($listener->checkCookies($event));
|
||||
$this->assertNull($listener->onCoreSecurity($event));
|
||||
$this->assertSame($token, $this->getLastState($listener));
|
||||
}
|
||||
|
||||
public function testUpdateCookiesIgnoresAnythingButMasterRequests()
|
||||
public function testFilterCoreResponseIgnoresAnythingButMasterRequests()
|
||||
{
|
||||
list($listener,,,,) = $this->getListener();
|
||||
list($listener,, $service,,) = $this->getListener();
|
||||
|
||||
$event = $this->getEvent();
|
||||
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
|
||||
$this->setLastState($listener, $token);
|
||||
|
||||
$event = $this->getFilterResponseEvent();
|
||||
$event
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->equalTo('request_type'))
|
||||
->method('getRequestType')
|
||||
->will($this->returnValue('foo'))
|
||||
;
|
||||
|
||||
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
|
||||
$service
|
||||
->expects($this->never())
|
||||
->method('loginSuccess')
|
||||
;
|
||||
|
||||
$this->assertSame($response, $listener->updateCookies($event, $response));
|
||||
$listener->filterCoreResponse($event);
|
||||
}
|
||||
|
||||
public function testUpdateCookiesCallsLoginSuccessOnRememberMeServicesImplementationWhenAuthenticationWasSuccessful()
|
||||
public function testFilterCoreResponseCallsLoginSuccessOnRememberMeServicesImplementationWhenAuthenticationWasSuccessful()
|
||||
{
|
||||
list($listener,, $service,,) = $this->getListener();
|
||||
|
||||
@ -280,19 +275,22 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
|
||||
$this->setLastState($listener, $token);
|
||||
|
||||
$event = $this->getEvent();
|
||||
$event = $this->getFilterResponseEvent();
|
||||
$event
|
||||
->expects($this->at(0))
|
||||
->method('get')
|
||||
->with('request_type')
|
||||
->expects($this->any())
|
||||
->method('getRequestType')
|
||||
->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST))
|
||||
;
|
||||
$event
|
||||
->expects($this->at(1))
|
||||
->method('get')
|
||||
->with('request')
|
||||
->expects($this->any())
|
||||
->method('getRequest')
|
||||
->will($this->returnValue($request))
|
||||
;
|
||||
$event
|
||||
->expects($this->any())
|
||||
->method('getResponse')
|
||||
->will($this->returnValue($response))
|
||||
;
|
||||
|
||||
$service
|
||||
->expects($this->once())
|
||||
@ -301,10 +299,10 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
->will($this->returnValue(null))
|
||||
;
|
||||
|
||||
$this->assertSame($response, $listener->updateCookies($event, $response));
|
||||
$listener->filterCoreResponse($event);
|
||||
}
|
||||
|
||||
public function testUpdateCookiesCallsLoginFailOnRememberMeServicesImplementationWhenAuthenticationWasNotSuccessful()
|
||||
public function testFilterCoreResponseCallsLoginFailOnRememberMeServicesImplementationWhenAuthenticationWasNotSuccessful()
|
||||
{
|
||||
list($listener,, $service,,) = $this->getListener();
|
||||
|
||||
@ -314,19 +312,22 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$exception = new AuthenticationException('foo');
|
||||
$this->setLastState($listener, $exception);
|
||||
|
||||
$event = $this->getEvent();
|
||||
$event = $this->getFilterResponseEvent();
|
||||
$event
|
||||
->expects($this->at(0))
|
||||
->method('get')
|
||||
->with('request_type')
|
||||
->expects($this->any())
|
||||
->method('getRequestType')
|
||||
->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST))
|
||||
;
|
||||
$event
|
||||
->expects($this->at(1))
|
||||
->method('get')
|
||||
->with('request')
|
||||
->expects($this->any())
|
||||
->method('getRequest')
|
||||
->will($this->returnValue($request))
|
||||
;
|
||||
$event
|
||||
->expects($this->any())
|
||||
->method('getResponse')
|
||||
->will($this->returnValue($response))
|
||||
;
|
||||
|
||||
$service
|
||||
->expects($this->once())
|
||||
@ -335,7 +336,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
->will($this->returnValue(null))
|
||||
;
|
||||
|
||||
$this->assertSame($response, $listener->updateCookies($event, $response));
|
||||
$listener->filterCoreResponse($event);
|
||||
}
|
||||
|
||||
protected function setLastState($listener, $state)
|
||||
@ -355,9 +356,14 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
|
||||
return $p->getValue($listener);
|
||||
}
|
||||
|
||||
protected function getEvent()
|
||||
protected function getGetResponseEvent()
|
||||
{
|
||||
return $this->getMock('Symfony\Component\EventDispatcher\Event', array(), array(), '', false);
|
||||
return $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEventArgs', array(), array(), '', false);
|
||||
}
|
||||
|
||||
protected function getFilterResponseEvent()
|
||||
{
|
||||
return $this->getMock('Symfony\Component\HttpKernel\Event\FilterResponseEventArgs', array(), array(), '', false);
|
||||
}
|
||||
|
||||
protected function getListener()
|
||||
|
Reference in New Issue
Block a user