Changeset 32299
- Timestamp:
- 03/18/11 08:00:09 (2 years ago)
- Files:
-
- branches/2.0/src/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Bundle/AsseticBundle/Event (added)
- branches/2.0/src/Symfony/Bundle/AsseticBundle/Event/WriteEvent.php (added)
- branches/2.0/src/Symfony/Bundle/AsseticBundle/Events.php (added)
- branches/2.0/src/Symfony/Bundle/DoctrineBundle/ConnectionFactory.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/InfoDoctrineODMCommand.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php (added)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Debug/EventDispatcher.php (deleted)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php (added)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterKernelListenersPass.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/EventDispatcher.php (deleted)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/HttpFoundation/SessionListener.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php (modified) (4 diffs)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/RequestListener.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/esi.xml (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml (modified) (2 diffs)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml (modified) (2 diffs)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Tests/HttpFoundation/SessionListenerTest.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Tests/HttpKernelTest.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/SecurityBundle/ResponseListener.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Bundle/WebProfilerBundle/Resources/config/toolbar.xml (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig (modified) (2 diffs)
- branches/2.0/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php (modified) (4 diffs)
- branches/2.0/src/Symfony/Component/EventDispatcher/Event.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Component/EventDispatcher/EventDispatcher.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php (modified) (1 diff)
- branches/2.0/src/Symfony/Component/EventDispatcher/EventInterface.php (deleted)
- branches/2.0/src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php (added)
- branches/2.0/src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php (modified) (4 diffs)
- branches/2.0/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php (modified) (1 diff)
- branches/2.0/src/Symfony/Component/HttpKernel/Debug/ExceptionListener.php (modified) (6 diffs)
- branches/2.0/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcherInterface.php (moved) (moved from branches/2.0/src/Symfony/Component/HttpKernel/Debug/EventDispatcherTraceableInterface.php) (1 diff)
- branches/2.0/src/Symfony/Component/HttpKernel/Event (added)
- branches/2.0/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php (added)
- branches/2.0/src/Symfony/Component/HttpKernel/Event/FilterResponseEvent.php (added)
- branches/2.0/src/Symfony/Component/HttpKernel/Event/GetResponseEvent.php (added)
- branches/2.0/src/Symfony/Component/HttpKernel/Event/GetResponseForControllerResultEvent.php (added)
- branches/2.0/src/Symfony/Component/HttpKernel/Event/GetResponseForExceptionEvent.php (added)
- branches/2.0/src/Symfony/Component/HttpKernel/Event/KernelEvent.php (added)
- branches/2.0/src/Symfony/Component/HttpKernel/Events.php (added)
- branches/2.0/src/Symfony/Component/HttpKernel/HttpCache/EsiListener.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Component/HttpKernel/HttpKernel.php (modified) (7 diffs)
- branches/2.0/src/Symfony/Component/HttpKernel/ResponseListener.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Authentication/AuthenticationFailureHandlerInterface.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Authentication/AuthenticationSuccessHandlerInterface.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Authorization/AccessDeniedHandlerInterface.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/AuthenticationEntryPointInterface.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/BasicAuthenticationEntryPoint.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/DigestAuthenticationEntryPoint.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/FormAuthenticationEntryPoint.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/RetryAuthenticationEntryPoint.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Event (added)
- branches/2.0/src/Symfony/Component/Security/Http/Event/InteractiveLoginEvent.php (added)
- branches/2.0/src/Symfony/Component/Security/Http/Event/SwitchUserEvent.php (added)
- branches/2.0/src/Symfony/Component/Security/Http/Events.php (added)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall.php (modified) (6 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php (modified) (10 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php (modified) (5 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/AccessListener.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php (modified) (4 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/ContextListener.php (modified) (7 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php (modified) (7 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/ListenerInterface.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/LogoutListener.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php (modified) (7 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php (modified) (9 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordFormAuthenticationListener.php (modified) (4 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Component/Security/Http/Logout/LogoutSuccessHandlerInterface.php (modified) (2 diffs)
- branches/2.0/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php (modified) (1 diff)
- branches/2.0/tests/Symfony/Tests/Component/EventDispatcher/EventTest.php (deleted)
- branches/2.0/tests/Symfony/Tests/Component/HttpKernel/ClientTest.php (modified) (1 diff)
- branches/2.0/tests/Symfony/Tests/Component/HttpKernel/DataCollector/EventDataCollectorTest.php (modified) (2 diffs)
- branches/2.0/tests/Symfony/Tests/Component/HttpKernel/Debug/ExceptionListenerTest.php (modified) (5 diffs)
- branches/2.0/tests/Symfony/Tests/Component/HttpKernel/HttpCache/EsiListenerTest.php (modified) (4 diffs)
- branches/2.0/tests/Symfony/Tests/Component/HttpKernel/HttpCache/TestHttpKernel.php (modified) (1 diff)
- branches/2.0/tests/Symfony/Tests/Component/HttpKernel/HttpCache/TestMultipleHttpKernel.php (modified) (1 diff)
- branches/2.0/tests/Symfony/Tests/Component/HttpKernel/HttpKernelTest.php (modified) (6 diffs)
- branches/2.0/tests/Symfony/Tests/Component/HttpKernel/ResponseListenerTest.php (modified) (1 diff)
- branches/2.0/tests/Symfony/Tests/Component/HttpKernel/TestHttpKernel.php (modified) (1 diff)
- branches/2.0/tests/Symfony/Tests/Component/Security/Http/Firewall/RememberMeListenerTest.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2.0/src/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php
r32202 r32299 15 15 use Assetic\Factory\LazyAssetManager; 16 16 use Symfony\Bundle\FrameworkBundle\Command\Command; 17 use Symfony\Bundle\AsseticBundle\Event\WriteEvent; 18 use Symfony\Bundle\AsseticBundle\Events; 17 19 use Symfony\Component\Console\Input\InputArgument; 18 20 use Symfony\Component\Console\Input\InputInterface; 19 21 use Symfony\Component\Console\Input\InputOption; 20 22 use Symfony\Component\Console\Output\OutputInterface; 21 use Symfony\Component\EventDispatcher\Event;22 23 23 24 /** … … 47 48 48 49 // notify an event so custom stream wrappers can be registered lazily 49 $this->container->get('event_dispatcher')->notify(new Event(null, 'assetic.write', array('path' => $basePath))); 50 $event = new WriteEvent($basePath); 51 $this->container->get('event_dispatcher')->dispatch(Events::onAsseticWrite, $writeEvent); 50 52 51 53 if ($input->getOption('watch')) { branches/2.0/src/Symfony/Bundle/DoctrineBundle/ConnectionFactory.php
r32184 r32299 37 37 /** 38 38 * Create a connection by name. 39 * 39 * 40 40 * @param string $connectionName 41 41 * @return Doctrine\DBAL\Connection branches/2.0/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php
r31836 r32299 33 33 34 34 foreach ($subscribers as $id => $instances) { 35 $definition->addMethodCall('add EventSubscriber', array(new Reference($id)));35 $definition->addMethodCall('addSubscriber', array(new Reference($id))); 36 36 } 37 37 } … … 53 53 54 54 if (0 < count($events)) { 55 $definition->addMethodCall('add EventListener', array(55 $definition->addMethodCall('addListener', array( 56 56 $events, 57 57 new Reference($listenerId), branches/2.0/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/InfoDoctrineODMCommand.php
r32254 r32299 4 4 * This file is part of the Symfony package. 5 5 * 6 * (c) Fabien Potencier <fabien .potencier@symfony-project.com>6 * (c) Fabien Potencier <fabien@symfony.com> 7 7 * 8 8 * For the full copyright and license information, please view the LICENSE branches/2.0/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php
r31841 r32299 30 30 31 31 foreach ($subscribers as $id => $instances) { 32 $definition->addMethodCall('add EventSubscriber', array(new Reference($id)));32 $definition->addMethodCall('addSubscriber', array(new Reference($id))); 33 33 } 34 34 } … … 50 50 51 51 if (0 < count($events)) { 52 $definition->addMethodCall('add EventListener', array(52 $definition->addMethodCall('addListener', array( 53 53 $events, 54 54 new Reference($listenerId), branches/2.0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterKernelListenersPass.php
r32184 r32299 25 25 26 26 $listeners = array(); 27 $definition = $container->getDefinition('event_dispatcher'); 28 27 29 foreach ($container->findTaggedServiceIds('kernel.listener') as $id => $events) { 28 30 foreach ($events as $event) { 29 31 $priority = isset($event['priority']) ? $event['priority'] : 0; 32 30 33 if (!isset($event['event'])) { 31 34 throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "kernel.listener" tags.', $id)); 32 35 } 33 if (!isset($event['method'])) {34 throw new \InvalidArgumentException(sprintf('Service "%s" must define the "method" attribute on "kernel.listener" tags.', $id));35 }36 36 37 if (!isset($listeners[$event['event']][$priority])) { 38 if (!isset($listeners[$event['event']])) { 39 $listeners[$event['event']] = array(); 40 } 41 $listeners[$event['event']][$priority] = array(); 42 } 43 44 $listeners[$event['event']][$priority][] = array($id, $event['method']); 37 $definition->addMethodCall('addListenerService', array($event['event'], $id, $priority)); 45 38 } 46 39 } 47 48 $container49 ->getDefinition('event_dispatcher')50 ->addMethodCall('registerKernelListeners', array($listeners))51 ;52 40 } 53 41 } branches/2.0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
r32287 r32299 141 141 'Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver', 142 142 'Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface', 143 'Symfony\\Component\\HttpKernel\\Event\\KernelEvent', 144 'Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent', 145 'Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent', 146 'Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent', 147 'Symfony\\Component\\HttpKernel\\Event\\GetResponseForControllerResultEvent', 148 'Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent', 149 'Symfony\\Component\\HttpKernel\\Events', 150 151 'Symfony\\Component\\EventDispatcher\\EventDispatcher', 152 'Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', 153 'Symfony\\Component\\EventDispatcher\\Event', 154 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface', 143 155 144 156 'Symfony\\Bundle\\FrameworkBundle\\RequestListener', … … 146 158 'Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerResolver', 147 159 'Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller', 148 149 'Symfony\\Component\\EventDispatcher\\EventInterface', 150 'Symfony\\Component\\EventDispatcher\\Event', 151 'Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', 152 'Symfony\\Component\\EventDispatcher\\EventDispatcher', 153 'Symfony\\Bundle\\FrameworkBundle\\EventDispatcher', 160 'Symfony\\Bundle\\FrameworkBundle\\ContainerAwareEventDispatcher', 154 161 )); 155 162 } branches/2.0/src/Symfony/Bundle/FrameworkBundle/HttpFoundation/SessionListener.php
r32184 r32299 12 12 namespace Symfony\Bundle\FrameworkBundle\HttpFoundation; 13 13 14 use Symfony\Component\EventDispatcher\EventInterface;15 14 use Symfony\Component\HttpFoundation\Request; 16 15 use Symfony\Component\HttpFoundation\Response; 17 16 use Symfony\Component\HttpKernel\HttpKernelInterface; 17 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 18 18 19 19 /** … … 28 28 /** 29 29 * Checks if session was initialized and saves if current request is master 30 * Runs on ' core.response' in test environment30 * Runs on 'onCoreResponse' in test environment 31 31 * 32 * @param EventInterface $event 33 * @param Response $response 34 * 35 * @return Response 32 * @param FilterResponseEvent $event 36 33 */ 37 public function filter(EventInterface $event, Response $response)34 public function onCoreResponse(FilterResponseEvent $event) 38 35 { 39 if ($request = $event->get ('request')) {40 if (HttpKernelInterface::MASTER_REQUEST === $event->get ('request_type')) {36 if ($request = $event->getRequest()) { 37 if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) { 41 38 if ($session = $request->getSession()) { 42 39 $session->save(); … … 44 41 } 45 42 } 46 47 return $response;48 43 } 49 44 } branches/2.0/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php
r32076 r32299 17 17 class HttpKernel extends BaseHttpKernel 18 18 { 19 pr otected$container;20 pr otected$esiSupport;19 private $container; 20 private $esiSupport; 21 21 22 public function __construct( ContainerInterface $container, ControllerResolverInterface $controllerResolver)22 public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver) 23 23 { 24 parent::__construct($dispatcher, $controllerResolver); 25 24 26 $this->container = $container; 25 $this->resolver = $controllerResolver;26 }27 28 public function setEventDispatcher(EventDispatcherInterface $dispatcher)29 {30 $this->dispatcher = $dispatcher;31 27 } 32 28 branches/2.0/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php
r32288 r32299 12 12 namespace Symfony\Bundle\FrameworkBundle\Profiler; 13 13 14 use Symfony\Component\EventDispatcher\EventInterface;15 14 use Symfony\Component\HttpFoundation\Response; 16 15 use Symfony\Component\HttpKernel\HttpKernelInterface; 16 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 17 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 18 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 17 19 use Symfony\Component\HttpFoundation\RequestMatcherInterface; 18 20 use Symfony\Component\DependencyInjection\ContainerInterface; 19 21 20 22 /** 21 * ProfilerListener collects data for the current request by listening to the core.response event. 22 * 23 * The handleException method must be connected to the core.exception event. 24 * The handleResponse method must be connected to the core.response event. 23 * ProfilerListener collects data for the current request by listening to the onCoreResponse event. 25 24 * 26 25 * @author Fabien Potencier <fabien@symfony.com> … … 48 47 49 48 /** 50 * Handles the core.request event49 * Handles the onCoreRequest event 51 50 * 52 51 * This method initialize the profiler to be able to get it as a scoped 53 * service when handleResponse() will collect the sub request52 * service when onCoreResponse() will collect the sub request 54 53 * 55 * @param EventInterface $event An EventInterfaceinstance54 * @param GetResponseEvent $event A GetResponseEvent instance 56 55 */ 57 public function handleRequest(EventInterface$event)56 public function onCoreRequest(GetResponseEvent $event) 58 57 { 59 58 $this->container->get('profiler'); … … 61 60 62 61 /** 63 * Handles the core.exception event.62 * Handles the onCoreException event. 64 63 * 65 * @param EventInterface $event An EventInterfaceinstance64 * @param GetResponseForExceptionEvent $event A GetResponseForExceptionEvent instance 66 65 */ 67 public function handleException(EventInterface$event)66 public function onCoreException(GetResponseForExceptionEvent $event) 68 67 { 69 if (HttpKernelInterface::MASTER_REQUEST !== $event->get ('request_type')) {70 return false;68 if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { 69 return; 71 70 } 72 71 73 $this->exception = $event->get('exception'); 74 75 return false; 72 $this->exception = $event->getException(); 76 73 } 77 74 78 75 /** 79 * Handles the core.response event.76 * Handles the onCoreResponse event. 80 77 * 81 * @param EventInterface $event An EventInterface instance 82 * 83 * @return Response $response A Response instance 78 * @param FilterResponseEvent $event A FilterResponseEvent instance 84 79 */ 85 public function handleResponse(EventInterface $event, Response $response)80 public function onCoreResponse(FilterResponseEvent $event) 86 81 { 87 if (null !== $this->matcher && !$this->matcher->matches($event->get('request'))) { 82 $response = $event->getResponse(); 83 84 if (null !== $this->matcher && !$this->matcher->matches($event->getRequest())) { 88 85 return $response; 89 86 } 90 87 91 88 if ($this->onlyException && null === $this->exception) { 92 return $response;89 return; 93 90 } 94 91 … … 99 96 } 100 97 101 $profiler->collect($event->get ('request'), $response, $this->exception);98 $profiler->collect($event->getRequest(), $event->getResponse(), $this->exception); 102 99 $this->exception = null; 103 104 return $response;105 100 } 106 101 } branches/2.0/src/Symfony/Bundle/FrameworkBundle/RequestListener.php
r32184 r32299 14 14 use Symfony\Component\HttpKernel\Log\LoggerInterface; 15 15 use Symfony\Component\HttpKernel\HttpKernelInterface; 16 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 16 17 use Symfony\Component\HttpFoundation\Request; 17 use Symfony\Component\EventDispatcher\EventInterface;18 18 use Symfony\Component\Routing\RouterInterface; 19 19 use Symfony\Component\DependencyInjection\ContainerInterface; … … 21 21 /** 22 22 * RequestListener. 23 *24 * The handle method must be connected to the core.request event.25 23 * 26 24 * @author Fabien Potencier <fabien@symfony.com> … … 39 37 } 40 38 41 public function handle(EventInterface$event)39 public function onCoreRequest(GetResponseEvent $event) 42 40 { 43 $request = $event->get ('request');44 $master = HttpKernelInterface::MASTER_REQUEST === $event->get ('request_type');41 $request = $event->getRequest(); 42 $master = HttpKernelInterface::MASTER_REQUEST === $event->getRequestType(); 45 43 46 44 $this->initializeSession($request, $master); branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml
r32184 r32299 6 6 7 7 <parameters> 8 <parameter key="debug.event_dispatcher.class">Symfony\Bundle\FrameworkBundle\Debug\ EventDispatcher</parameter>8 <parameter key="debug.event_dispatcher.class">Symfony\Bundle\FrameworkBundle\Debug\TraceableEventDispatcher</parameter> 9 9 </parameters> 10 10 branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/esi.xml
r32184 r32299 14 14 15 15 <service id="esi_listener" class="%esi_listener.class%"> 16 <tag name="kernel.listener" event=" core.response" method="filter" />16 <tag name="kernel.listener" event="onCoreResponse" /> 17 17 <argument type="service" id="esi" on-invalid="ignore" /> 18 18 </service> branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml
r32288 r32299 24 24 25 25 <service id="profiler_listener" class="%profiler_listener.class%"> 26 <tag name="kernel.listener" event=" core.response" method="handleResponse" />27 <tag name="kernel.listener" event=" core.exception" method="handleException" />28 <tag name="kernel.listener" event=" core.request" method="handleRequest" />26 <tag name="kernel.listener" event="onCoreResponse" /> 27 <tag name="kernel.listener" event="onCoreException" /> 28 <tag name="kernel.listener" event="onCoreRequest" /> 29 29 <argument type="service" id="service_container" /> 30 30 <argument type="service" id="profiler.request_matcher" on-invalid="null" /> branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml
r32184 r32299 6 6 7 7 <parameters> 8 <parameter key="event_dispatcher.class">Symfony\Bundle\FrameworkBundle\ EventDispatcher</parameter>8 <parameter key="event_dispatcher.class">Symfony\Bundle\FrameworkBundle\ContainerAwareEventDispatcher</parameter> 9 9 <parameter key="http_kernel.class">Symfony\Bundle\FrameworkBundle\HttpKernel</parameter> 10 10 <parameter key="error_handler.class">Symfony\Component\HttpKernel\Debug\ErrorHandler</parameter> … … 26 26 27 27 <service id="http_kernel" class="%http_kernel.class%"> 28 <argument type="service" id="event_dispatcher" /> 28 29 <argument type="service" id="service_container" /> 29 30 <argument type="service" id="controller_resolver" /> 30 <call method="setEventDispatcher"><argument type="service" id="event_dispatcher" /></call>31 31 </service> 32 32 branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml
r32184 r32299 26 26 27 27 <service id="test.session.listener" class="%test.session.listener.class%"> 28 <tag name="kernel.listener" event=" core.response" method="filter" priority="-128" />28 <tag name="kernel.listener" event="onCoreResponse" priority="-128" /> 29 29 </service> 30 30 </services> branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml
r32184 r32299 27 27 28 28 <service id="request_listener" class="%request_listener.class%"> 29 <tag name="kernel.listener" event=" core.request" method="handle" />29 <tag name="kernel.listener" event="onCoreRequest" /> 30 30 <argument type="service" id="service_container" /> 31 31 <argument type="service" id="router" /> … … 34 34 35 35 <service id="response_listener" class="%response_listener.class%"> 36 <tag name="kernel.listener" event=" core.response" method="filter" />36 <tag name="kernel.listener" event="onCoreResponse" /> 37 37 <argument>%kernel.charset%</argument> 38 38 </service> 39 39 40 40 <service id="exception_listener" class="%exception_listener.class%"> 41 <tag name="kernel.listener" event=" core.exception" method="handle" priority="-128" />41 <tag name="kernel.listener" event="onCoreException" priority="-128" /> 42 42 <argument>%exception_listener.controller%</argument> 43 43 <argument type="service" id="logger" on-invalid="null" /> branches/2.0/src/Symfony/Bundle/FrameworkBundle/Tests/HttpFoundation/SessionListenerTest.php
r32184 r32299 13 13 14 14 use Symfony\Bundle\FrameworkBundle\HttpFoundation\SessionListener; 15 use Symfony\Component\EventDispatcher\Event;16 15 use Symfony\Component\HttpFoundation\Response; 17 16 use Symfony\Component\HttpFoundation\Request; 18 17 use Symfony\Component\HttpKernel\HttpKernelInterface; 18 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 19 19 20 20 /** … … 54 54 $request->setSession($this->session); 55 55 $response = new Response(); 56 $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); 57 $event = new FilterResponseEvent($kernel, $request, $type, $response); 56 58 57 $this-> assertSame($response, $this->listener->filter(new Event(58 $this, 'core.response', array('request' => $request, 'request_type' => $type) 59 ), $response));59 $this->listener->onCoreResponse($event); 60 61 $this->assertSame($response, $event->getResponse()); 60 62 } 61 63 branches/2.0/src/Symfony/Bundle/FrameworkBundle/Tests/HttpKernelTest.php
r31885 r32299 6 6 use Symfony\Component\HttpFoundation\Response; 7 7 use Symfony\Component\HttpFoundation\Request; 8 use Symfony\Component\EventDispatcher\EventDispatcher;9 8 use Symfony\Component\DependencyInjection\ContainerBuilder; 10 9 use Symfony\Bundle\FrameworkBundle\HttpKernel; 10 use Symfony\Component\EventDispatcher\EventDispatcher; 11 11 12 12 class HttpKernelTest extends \PHPUnit_Framework_TestCase … … 39 39 $dispatcher = new EventDispatcher(); 40 40 $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface'); 41 $kernel = new HttpKernel($container, $resolver); 42 $kernel->setEventDispatcher($dispatcher); 41 $kernel = new HttpKernel($dispatcher, $container, $resolver); 43 42 44 43 $controller = function() use($expected) … … 88 87 $dispatcher = new EventDispatcher(); 89 88 $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface'); 90 $kernel = new HttpKernel($container, $resolver); 91 $kernel->setEventDispatcher($dispatcher); 89 $kernel = new HttpKernel($dispatcher, $container, $resolver); 92 90 93 91 $controller = function() use ($expected) branches/2.0/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml
r32259 r32299 107 107 <!-- Firewall related services --> 108 108 <service id="security.firewall" class="%security.firewall.class%"> 109 <tag name="kernel.listener" event=" core.request" method="handle" priority="-128" />109 <tag name="kernel.listener" event="onCoreRequest" priority="-128" /> 110 110 <argument type="service" id="security.firewall.map" /> 111 111 <argument type="service" id="event_dispatcher" /> branches/2.0/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml
r32264 r32299 52 52 53 53 <service id="security.rememberme.response_listener" class="%security.rememberme.response_listener.class%"> 54 <tag name="kernel.listener" method="handle" event="core.response"/>54 <tag name="kernel.listener" event="onCoreResponse"/> 55 55 </service> 56 56 </services> branches/2.0/src/Symfony/Bundle/SecurityBundle/ResponseListener.php
r32227 r32299 4 4 5 5 use Symfony\Component\HttpFoundation\Response; 6 use Symfony\Component\ EventDispatcher\EventInterface;6 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 7 7 use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; 8 8 … … 14 14 class ResponseListener 15 15 { 16 public function handle(EventInterface $event, Response $response)16 public function onCoreResponse(FilterResponseEvent $event) 17 17 { 18 $request = $event->get('request'); 19 if (!$request->attributes->has(RememberMeServicesInterface::COOKIE_ATTR_NAME)) { 20 return $response; 18 $request = $event->getRequest(); 19 $response = $event->getResponse(); 20 21 if ($request->attributes->has(RememberMeServicesInterface::COOKIE_ATTR_NAME)) { 22 $response->headers->setCookie($request->attributes->get(RememberMeServicesInterface::COOKIE_ATTR_NAME)); 21 23 } 22 23 $response->headers->setCookie($request->attributes->get(RememberMeServicesInterface::COOKIE_ATTR_NAME));24 25 return $response;26 24 } 27 25 } branches/2.0/src/Symfony/Bundle/WebProfilerBundle/Resources/config/toolbar.xml
r32184 r32299 12 12 <services> 13 13 <service id="debug.toolbar" class="%debug.toolbar.class%"> 14 <tag name="kernel.listener" event=" core.response" method="handle" priority="-128" />14 <tag name="kernel.listener" event="onCoreResponse" priority="-128" /> 15 15 <argument type="service" id="http_kernel" /> 16 16 <argument type="service" id="templating.engine.twig" /> branches/2.0/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig
r32268 r32299 13 13 <table> 14 14 <tr> 15 <th>Class</th> 15 16 <th>Event</th> 16 <th>Caller</th>17 <th>Listener</th>18 17 </tr> 19 18 {% for elements in collector.calledlisteners %} 20 19 <tr> 20 <td><code>{{ elements.class|abbr_class }}</code></td> 21 21 <td><code>{{ elements.event }}</code></td> 22 <td><code>{{ elements.caller|abbr_class }}</code></td>23 <td><code>{{ elements.listener|abbr_method }}</code></td>24 22 </tr> 25 23 {% endfor %} … … 36 34 {% for elements in collector.notcalledlisteners %} 37 35 <tr> 36 <td><code>{{ elements.class|abbr_class }}</code></td> 38 37 <td><code>{{ elements.event }}</code></td> 39 <td><code>{{ elements.listener|abbr_method }}</code></td>40 38 </tr> 41 39 {% endfor %} branches/2.0/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php
r32236 r32299 12 12 namespace Symfony\Bundle\WebProfilerBundle; 13 13 14 use Symfony\Component\EventDispatcher\EventInterface;15 14 use Symfony\Component\HttpFoundation\Request; 16 15 use Symfony\Component\HttpFoundation\Response; 17 16 use Symfony\Bundle\FrameworkBundle\HttpKernel; 18 17 use Symfony\Component\HttpKernel\HttpKernelInterface; 18 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 19 19 use Symfony\Bundle\TwigBundle\TwigEngine; 20 20 … … 22 22 * WebDebugToolbarListener injects the Web Debug Toolbar. 23 23 * 24 * The handle method must be connected to the core.response event.24 * The handle method must be connected to the onCoreResponse event. 25 25 * 26 26 * The WDT is only injected on well-formed HTML (with a proper </body> tag). … … 42 42 } 43 43 44 public function handle(EventInterface $event, Response $response)44 public function onCoreResponse(FilterResponseEvent $event) 45 45 { 46 if (HttpKernelInterface::MASTER_REQUEST !== $event->get ('request_type')) {47 return $response;46 if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { 47 return; 48 48 } 49 49 50 $request = $event->get('request'); 50 $response = $event->getResponse(); 51 $request = $event->getRequest(); 52 51 53 if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) { 52 54 // keep current flashes for one more request … … 67 69 || $request->isXmlHttpRequest() 68 70 ) { 69 return $response;71 return; 70 72 } 71 73 72 74 $this->injectToolbar($response); 73 74 return $response;75 75 } 76 76 branches/2.0/src/Symfony/Component/EventDispatcher/Event.php
r32184 r32299 2 2 3 3 /* 4 * This file is part of the Symfony package. 4 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 5 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 6 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 7 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 8 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 9 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 10 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 11 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 12 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 13 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 14 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5 15 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 16 * This software consists of voluntary contributions made by many individuals 17 * and is licensed under the LGPL. For more information, see 18 * <http://www.doctrine-project.org>. 10 19 */ 11 20 … … 13 22 14 23 /** 15 * Event .24 * Event is the base class for classes containing event data. 16 25 * 17 * @author Fabien Potencier <fabien@symfony.com> 26 * This class contains no event data. It is used by events that do not pass 27 * state information to an event handler when an event is raised. 28 * 29 * You can call the method stopPropagation() to abort the execution of 30 * further listeners in your event listener. 31 * 32 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL 33 * @link www.doctrine-project.org 34 * @since 2.0 35 * @version $Revision: 3938 $ 36 * @author Guilherme Blanco <guilhermeblanco@hotmail.com> 37 * @author Jonathan Wage <jonwage@gmail.com> 38 * @author Roman Borschel <roman@code-factory.org> 39 * @author Bernhard Schussek <bschussek@gmail.com> 18 40 */ 19 class Event implements EventInterface41 class Event 20 42 { 21 protected $processed = false;22 protected $subject;23 protected $name;24 pr otected $parameters;43 /** 44 * @var Boolean Whether no further event listeners should be triggered 45 */ 46 private $propagationStopped = false; 25 47 26 48 /** 27 * Constructs a new Event.49 * Returns whether further event listeners should be triggered. 28 50 * 29 * @param mixed $subject The subject 30 * @param string $name The event name 31 * @param array $parameters An array of parameters 51 * @see Event::stopPropagation 52 * @return Boolean Whether propagation was already stopped for this event. 32 53 */ 33 public function __construct($subject, $name, $parameters = array())54 public function isPropagationStopped() 34 55 { 35 $this->subject = $subject; 36 $this->name = $name; 37 $this->parameters = $parameters; 56 return $this->propagationStopped; 38 57 } 39 58 40 59 /** 41 * Returns the subject.60 * Stops the propagation of the event to further event listeners. 42 61 * 43 * @return mixed The subject 62 * If multiple event listeners are connected to the same event, no 63 * further event listener will be triggered once any trigger calls 64 * stopPropagation(). 44 65 */ 45 public function getSubject()66 public function stopPropagation() 46 67 { 47 return $this->subject; 48 } 49 50 /** 51 * Returns the event name. 52 * 53 * @return string The event name 54 */ 55 public function getName() 56 { 57 return $this->name; 58 } 59 60 /** 61 * Sets the processed flag to true. 62 * 63 * This method must be called by listeners when 64 * it has processed the event (it is only meaningful 65 * when the event has been notified with the notifyUntil() 66 * dispatcher method. 67 */ 68 public function setProcessed() 69 { 70 $this->processed = true; 71 } 72 73 /** 74 * Returns whether the event has been processed by a listener or not. 75 * 76 * This method is only meaningful for events notified 77 * with notifyUntil(). 78 * 79 * @return Boolean true if the event has been processed, false otherwise 80 */ 81 public function isProcessed() 82 { 83 return $this->processed; 84 } 85 86 /** 87 * Returns the event parameters. 88 * 89 * @return array The event parameters 90 */ 91 public function all() 92 { 93 return $this->parameters; 94 } 95 96 /** 97 * Returns true if the parameter exists. 98 * 99 * @param string $name The parameter name 100 * 101 * @return Boolean true if the parameter exists, false otherwise 102 */ 103 public function has($name) 104 { 105 return array_key_exists($name, $this->parameters); 106 } 107 108 /** 109 * Returns a parameter value. 110 * 111 * @param string $name The parameter name 112 * 113 * @return mixed The parameter value 114 * 115 * @throws \InvalidArgumentException When parameter doesn't exists for this event 116 */ 117 public function get($name) 118 { 119 if (!array_key_exists($name, $this->parameters)) { 120 throw new \InvalidArgumentException(sprintf('The event "%s" has no "%s" parameter.', $this->name, $name)); 121 } 122 123 return $this->parameters[$name]; 124 } 125 126 /** 127 * Sets a parameter. 128 * 129 * @param string $name The parameter name 130 * @param mixed $value The parameter value 131 */ 132 public function set($name, $value) 133 { 134 $this->parameters[$name] = $value; 68 $this->propagationStopped = true; 135 69 } 136 70 } branches/2.0/src/Symfony/Component/EventDispatcher/EventDispatcher.php
r32184 r32299 2 2 3 3 /* 4 * This file is part of the Symfony package. 4 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 5 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 6 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 7 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 8 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 9 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 10 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 11 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 12 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 13 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 14 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5 15 * 6 * (c) Fabien Potencier <fabien@symfony.com> 16 * This software consists of voluntary contributions made by many individuals 17 * and is licensed under the LGPL. For more information, see 18 * <http://www.doctrine-project.org>. 19 */ 20 21 namespace Symfony\Component\EventDispatcher; 22 23 /** 24 * The EventDispatcherInterface is the central point of Symfony's event listener system. 7 25 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\EventDispatcher; 13 14 /** 15 * EventDispatcher implements a dispatcher object. 26 * Listeners are registered on the manager and events are dispatched through the 27 * manager. 16 28 * 17 * @author Fabien Potencier <fabien@symfony.com> 29 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL 30 * @link www.doctrine-project.org 31 * @since 2.0 32 * @version $Revision: 3938 $ 33 * @author Guilherme Blanco <guilhermeblanco@hotmail.com> 34 * @author Jonathan Wage <jonwage@gmail.com> 35 * @author Roman Borschel <roman@code-factory.org> 36 * @author Bernhard Schussek <bschussek@gmail.com> 18 37 */ 19 38 class EventDispatcher implements EventDispatcherInterface 20 39 { 21 protected $listeners = array(); 22 23 /** 24 * Connects a listener to a given event name. 25 * 26 * Listeners with a higher priority are executed first. 27 * 28 * @param string $name An event name 29 * @param mixed $listener A PHP callable 30 * @param integer $priority The priority (between -10 and 10 -- defaults to 0) 31 */ 32 public function connect($name, $listener, $priority = 0) 33 { 34 if (!isset($this->listeners[$name][$priority])) { 35 if (!isset($this->listeners[$name])) { 36 $this->listeners[$name] = array(); 37 } 38 $this->listeners[$name][$priority] = array(); 39 } 40 41 $this->listeners[$name][$priority][] = $listener; 42 } 43 44 /** 45 * Disconnects one, or all listeners for the given event name. 46 * 47 * @param string $name An event name 48 * @param mixed|null $listener The listener to remove, or null to remove all 49 * 50 * @return void 51 */ 52 public function disconnect($name, $listener = null) 53 { 54 if (!isset($this->listeners[$name])) { 55 return; 56 } 57 58 if (null === $listener) { 59 unset($this->listeners[$name]); 60 return; 61 } 62 63 foreach ($this->listeners[$name] as $priority => $callables) { 64 foreach ($callables as $i => $callable) { 65 if ($listener === $callable) { 66 unset($this->listeners[$name][$priority][$i]); 40 /** 41 * Map of registered listeners. 42 * <event> => (<objecthash> => <listener>) 43 * 44 * @var array 45 */ 46 private $listeners = array(); 47 48 /** 49 * Map of priorities by the object hashes of their listeners. 50 * <event> => (<objecthash> => <priority>) 51 * 52 * This property is used for listener sorting. 53 * 54 * @var array 55 */ 56 private $priorities = array(); 57 58 /** 59 * Stores which event listener lists are currently sorted. 60 * <event> => <sorted> 61 * 62 * @var array 63 */ 64 private $sorted = array(); 65 66 /** 67 * @see EventDispatcherInterface::dispatch 68 */ 69 public function dispatch($eventName, Event $event = null) 70 { 71 if (isset($this->listeners[$eventName])) { 72 if (null === $event) { 73 $event = new Event(); 74 } 75 76 $this->sortListeners($eventName); 77 78 foreach ($this->listeners[$eventName] as $listener) { 79 $this->triggerListener($listener, $eventName, $event); 80 81 if ($event->isPropagationStopped()) { 82 break; 67 83 } 68 84 } … … 71 87 72 88 /** 73 * Notifies all listeners of a given event. 74 * 75 * @param EventInterface $event An EventInterface instance 76 */ 77 public function notify(EventInterface $event) 78 { 79 foreach ($this->getListeners($event->getName()) as $listener) { 80 call_user_func($listener, $event); 81 } 82 } 83 84 /** 85 * Notifies all listeners of a given event until one processes the event. 86 * 87 * @param EventInterface $event An EventInterface instance 88 * 89 * @return mixed The returned value of the listener that processed the event 90 */ 91 public function notifyUntil(EventInterface $event) 92 { 93 foreach ($this->getListeners($event->getName()) as $listener) { 94 $ret = call_user_func($listener, $event); 95 if ($event->isProcessed()) { 96 return $ret; 97 } 98 } 99 } 100 101 /** 102 * Filters a value by calling all listeners of a given event. 103 * 104 * @param EventInterface $event An EventInterface instance 105 * @param mixed $value The value to be filtered 106 * 107 * @return mixed The filtered value 108 */ 109 public function filter(EventInterface $event, $value) 110 { 111 foreach ($this->getListeners($event->getName()) as $listener) { 112 $value = call_user_func($listener, $event, $value); 113 } 114 115 return $value; 116 } 117 118 /** 119 * Returns true if the given event name has some listeners. 120 * 121 * @param string $name The event name 122 * 123 * @return Boolean true if some listeners are connected, false otherwise 124 */ 125 public function hasListeners($name) 126 { 127 return (Boolean) count($this->getListeners($name)); 128 } 129 130 /** 131 * Returns all listeners associated with a given event name. 132 * 133 * @param string $name The event name 134 * 135 * @return array An array of listeners 136 */ 137 public function getListeners($name) 138 { 139 if (!isset($this->listeners[$name])) { 140 return array(); 141 } 142 143 krsort($this->listeners[$name]); 144 145 return call_user_func_array('array_merge', $this->listeners[$name]); 89 * @see EventDispatcherInterface::getListeners 90 */ 91 public function getListeners($eventName = null) 92 { 93 if ($eventName) { 94 $this->sortListeners($eventName); 95 96 return $this->listeners[$eventName]; 97 } 98 99 foreach ($this->listeners as $eventName => $listeners) { 100 $this->sortListeners($eventName); 101 } 102 103 return $this->listeners; 104 } 105 106 /** 107 * @see EventDispatcherInterface::hasListeners 108 */ 109 public function hasListeners($eventName) 110 { 111 return isset($this->listeners[$eventName]) && $this->listeners[$eventName]; 112 } 113 114 /** 115 * @see EventDispatcherInterface::addListener 116 */ 117 public function addListener($eventNames, $listener, $priority = 0) 118 { 119 // Picks the hash code related to that listener 120 $hash = spl_object_hash($listener); 121 122 foreach ((array) $eventNames as $eventName) { 123 if (!isset($this->listeners[$eventName])) { 124 $this->listeners[$eventName] = array(); 125 $this->priorities[$eventName] = array(); 126 } 127 128 // Prevents duplicate listeners on same event (same instance only) 129 $this->listeners[$eventName][$hash] = $listener; 130 $this->priorities[$eventName][$hash] = $priority; 131 $this->sorted[$eventName] = false; 132 } 133 } 134 135 /** 136 * @see EventDispatcherInterface::removeListener 137 */ 138 public function removeListener($eventNames, $listener) 139 { 140 // Picks the hash code related to that listener 141 $hash = spl_object_hash($listener); 142 143 foreach ((array) $eventNames as $eventName) { 144 // Check if actually have this listener associated 145 if (isset($this->listeners[$eventName][$hash])) { 146 unset($this->listeners[$eventName][$hash]); 147 unset($this->priorities[$eventName][$hash]); 148 } 149 } 150 } 151 152 /** 153 * @see EventDispatcherInterface::addSubscriber 154 */ 155 public function addSubscriber(EventSubscriberInterface $subscriber, $priority = 0) 156 { 157 $this->addListener($subscriber->getSubscribedEvents(), $subscriber, $priority); 158 } 159 160 /** 161 * Triggers the listener method for an event. 162 * 163 * This method can be overridden to add functionality that is executed 164 * for each listener. 165 * 166 * @param object $listener The event listener on which to invoke the listener method. 167 * @param string $eventName The name of the event to dispatch. The name of the event is 168 * the name of the method that is invoked on listeners. 169 * @param Event $event The event arguments to pass to the event handlers/listeners. 170 */ 171 protected function triggerListener($listener, $eventName, Event $event) 172 { 173 if ($listener instanceof \Closure) { 174 $listener->__invoke($event); 175 } else { 176 $listener->$eventName($event); 177 } 178 } 179 180 /** 181 * Sorts the internal list of listeners for the given event by priority. 182 * 183 * Calling this method multiple times will not cause overhead unless you 184 * add new listeners. As long as no listener is added, the list for an 185 * event name won't be sorted twice. 186 * 187 * @param string $event The name of the event. 188 */ 189 private function sortListeners($eventName) 190 { 191 if (!$this->sorted[$eventName]) { 192 $p = $this->priorities[$eventName]; 193 194 uasort($this->listeners[$eventName], function ($a, $b) use ($p) { 195 $order = $p[spl_object_hash($b)] - $p[spl_object_hash($a)]; 196 197 // for the same priority, force the first registered one to stay first 198 return 0 === $order ? 1 : $order; 199 }); 200 201 $this->sorted[$eventName] = true; 202 } 146 203 } 147 204 } branches/2.0/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php
r32184 r32299 13 13 14 14 /** 15 * EventDispatcherInterface describes an event dispatcher class. 15 * The EventDispatcherInterface is the central point of Symfony's event listener system. 16 * Listeners are registered on the manager and events are dispatched through the 17 * manager. 16 18 * 17 * @see http://developer.apple.com/documentation/Cocoa/Conceptual/Notifications/index.html Apple's Cocoa framework 18 * 19 * @author Fabien Potencier <fabien@symfony.com> 19 * @author Bernhard Schussek <bschussek@gmail.com> 20 20 */ 21 21 interface EventDispatcherInterface 22 22 { 23 23 /** 24 * Connects a listener to a given event name.24 * Dispatches an event to all registered listeners. 25 25 * 26 * Listeners with a higher priority are executed first.27 * 28 * @param string $name An event name29 * @param mixed $listener A PHP callable30 * @param integer $priority The priority (between -10 and 10 -- defaults to 0)26 * @param string $eventName The name of the event to dispatch. The name of 27 * the event is the name of the method that is 28 * invoked on listeners. 29 * @param Event $event The event to pass to the event handlers/listeners. 30 * If not supplied, an empty Event instance is created. 31 31 */ 32 function connect($name, $listener, $priority = 0);32 function dispatch($eventName, Event $event = null); 33 33 34 34 /** 35 * Disconnects one, or all listeners for the given event name.35 * Adds an event listener that listens on the specified events. 36 36 * 37 * @param string $name An event name 38 * @param mixed|null $listener The listener to remove, or null to remove all 39 * 40 * @return void 37 * @param string|array $eventNames The event(s) to listen on. 38 * @param object $listener The listener object. 39 * @param integer $priority The higher this value, the earlier an event 40 * listener will be triggered in the chain. 41 * Defaults to 0. 41 42 */ 42 function disconnect($name, $listener = null);43 function addListener($eventNames, $listener, $priority = 0); 43 44 44 45 /** 45 * Notifies all listeners of a given event. 46 * Adds an event subscriber. The subscriber is asked for all the events he is 47 * interested in and added as a listener for these events. 46 48 * 47 * @param EventInterface $event An EventInterface instance 49 * @param EventSubscriberInterface $subscriber The subscriber. 50 * @param integer $priority The higher this value, the earlier an event 51 * listener will be triggered in the chain. 52 * Defaults to 0. 48 53 */ 49 function notify(EventInterface $event);54 function addSubscriber(EventSubscriberInterface $subscriber, $priority = 0); 50 55 51 56 /** 52 * Notifies all listeners of a given event until one processes the event.57 * Removes an event listener from the specified events. 53 58 * 54 * A listener tells the dispatcher that it has processed the event 55 * by calling the setProcessed() method on it. 56 * 57 * It can then return a value that will be forwarded to the caller. 58 * 59 * @param EventInterface $event An EventInterface instance 60 * 61 * @return mixed The returned value of the listener that processed the event 59 * @param string|array $eventNames The event(s) to remove a listener from. 60 * @param object $listener The listener object to remove. 62 61 */ 63 function notifyUntil(EventInterface $event);62 function removeListener($eventNames, $listener); 64 63 65 64 /** 66 * Filters a value by calling all listeners of a given event.65 * Gets the listeners of a specific event or all listeners. 67 66 * 68 * @param EventInterface $event An EventInterface instance 69 * @param mixed $value The value to be filtered 67 * @param string $eventName The name of the event. 70 68 * 71 * @return mixed The filtered value 69 * @return array The event listeners for the specified event, or all event 70 * listeners by event name. 72 71 */ 73 function filter(EventInterface $event, $value);72 function getListeners($eventName = null); 74 73 75 74 /** 76 * Returns true if the given event name has somelisteners.75 * Checks whether an event has any registered listeners. 77 76 * 78 * @param string $name The event name77 * @param string $eventName The name of the event. 79 78 * 80 * @return Boolean true if some listeners are connected, false otherwise 79 * @return Boolean TRUE if the specified event has any listeners, FALSE 80 * otherwise. 81 81 */ 82 function hasListeners($name); 83 84 /** 85 * Returns all listeners associated with a given event name. 86 * 87 * @param string $name The event name 88 * 89 * @return array An array of listeners 90 */ 91 function getListeners($name); 82 function hasListeners($eventName); 92 83 } branches/2.0/src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php
r32184 r32299 12 12 namespace Symfony\Component\HttpKernel\DataCollector; 13 13 14 use Symfony\Component\EventDispatcher\EventDispatcherInterface;15 14 use Symfony\Component\HttpFoundation\Request; 16 15 use Symfony\Component\HttpFoundation\Response; 17 use Symfony\Component\HttpKernel\Debug\EventDispatcherTraceableInterface; 16 use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcherInterface; 17 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 18 18 19 19 /** … … 28 28 public function setEventDispatcher(EventDispatcherInterface $dispatcher) 29 29 { 30 if ($dispatcher instanceof EventDispatcherTraceableInterface) {30 if ($dispatcher instanceof TraceableEventDispatcherInterface) { 31 31 $this->dispatcher = $dispatcher; 32 32 } … … 49 49 * @return array An array of called listeners 50 50 * 51 * @see EventDispatcherTraceableInterface51 * @see TraceableEventDispatcherInterface 52 52 */ 53 53 public function getCalledListeners() … … 61 61 * @return array An array of not called listeners 62 62 * 63 * @see EventDispatcherTraceableInterface63 * @see TraceableEventDispatcherInterface 64 64 */ 65 65 public function getNotCalledListeners() branches/2.0/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php
r32184 r32299 49 49 * @return array An array of called events 50 50 * 51 * @see EventDispatcherTraceableInterface51 * @see TraceableEventDispatcherInterface 52 52 */ 53 53 public function countErrors() branches/2.0/src/Symfony/Component/HttpKernel/Debug/ExceptionListener.php
r32184 r32299 12 12 namespace Symfony\Component\HttpKernel\Debug; 13 13 14 use Symfony\Component\EventDispatcher\EventInterface;15 14 use Symfony\Component\HttpKernel\Log\LoggerInterface; 16 15 use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; 16 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 17 17 use Symfony\Component\HttpKernel\HttpKernelInterface; 18 18 use Symfony\Component\HttpKernel\Exception\FlattenException; … … 21 21 /** 22 22 * ExceptionListener. 23 *24 * The handle method must be connected to the core.exception event.25 23 * 26 24 * @author Fabien Potencier <fabien@symfony.com> … … 37 35 } 38 36 39 public function handle(EventInterface$event)37 public function onCoreException(GetResponseForExceptionEvent $event) 40 38 { 41 39 static $handling; … … 47 45 $handling = true; 48 46 49 $exception = $event->get ('exception');50 $request = $event->get ('request');47 $exception = $event->getException(); 48 $request = $event->getRequest(); 51 49 52 50 if (null !== $this->logger) { … … 69 67 70 68 try { 71 $response = $event->get Subject()->handle($request, HttpKernelInterface::SUB_REQUEST, true);69 $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true); 72 70 } catch (\Exception $e) { 73 71 $message = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()); … … 80 78 // set handling to false otherwise it wont be able to handle further more 81 79 $handling = false; 82 80 83 81 // re-throw the exception as this is a catch-all 84 82 throw $exception; 85 83 } 86 84 87 $event->set Processed();85 $event->setResponse($response); 88 86 89 87 $handling = false; 90 91 return $response;92 88 } 93 89 } branches/2.0/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcherInterface.php
r32184 r32299 15 15 * @author Fabien Potencier <fabien@symfony.com> 16 16 */ 17 interface EventDispatcherTraceableInterface17 interface TraceableEventDispatcherInterface 18 18 { 19 19 /** branches/2.0/src/Symfony/Component/HttpKernel/HttpCache/EsiListener.php
r32184 r32299 14 14 use Symfony\Component\HttpFoundation\Response; 15 15 use Symfony\Component\HttpKernel\HttpKernelInterface; 16 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 17 use Symfony\Component\EventDispatcher\EventInterface; 16 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 18 17 19 18 /** 20 19 * EsiListener adds a Surrogate-Control HTTP header when the Response needs to be parsed for ESI. 21 *22 * The filter method must be connected to the core.response event.23 20 * 24 21 * @author Fabien Potencier <fabien@symfony.com> … … 26 23 class EsiListener 27 24 { 28 protected $ dispatcher;25 protected $i; 29 26 protected $esi; 30 27 … … 42 39 * Filters the Response. 43 40 * 44 * @param EventInterface $event An EventInterface instance 45 * @param Response $response A Response instance 41 * @param FilterResponseEvent $event A FilterResponseEvent instance 46 42 */ 47 public function filter(EventInterface $event, Response $response)43 public function onCoreResponse(FilterResponseEvent $event) 48 44 { 49 if (HttpKernelInterface::MASTER_REQUEST !== $event->get ('request_type') || null === $this->esi) {50 return $response;45 if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType() || null === $this->esi) { 46 return; 51 47 } 52 48 53 $this->esi->addSurrogateControl($response); 54 55 return $response; 49 $this->esi->addSurrogateControl($event->getResponse()); 56 50 } 57 51 } branches/2.0/src/Symfony/Component/HttpKernel/HttpKernel.php
r32292 r32299 12 12 namespace Symfony\Component\HttpKernel; 13 13 14 use Symfony\Component\EventDispatcher\Event;15 use Symfony\Component\EventDispatcher\EventDispatcherInterface;16 14 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; 17 15 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; 16 use Symfony\Component\HttpKernel\Event\FilterControllerEvent; 17 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 18 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 19 use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; 20 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 18 21 use Symfony\Component\HttpFoundation\Request; 19 22 use Symfony\Component\HttpFoundation\Response; 23 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 20 24 21 25 /** … … 26 30 class HttpKernel implements HttpKernelInterface 27 31 { 28 pr otected$dispatcher;29 pr otected$resolver;32 private $dispatcher; 33 private $resolver; 30 34 31 35 /** 32 36 * Constructor 33 37 * 34 * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance38 * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance 35 39 * @param ControllerResolverInterface $resolver A ControllerResolverInterface instance 36 40 */ … … 85 89 { 86 90 // request 87 $event = new Event($this, 'core.request', array('request_type' => $type, 'request' => $request)); 88 $response = $this->dispatcher->notifyUntil($event); 89 if ($event->isProcessed()) { 90 return $this->filterResponse($response, $request, 'A "core.request" listener returned a non response object.', $type); 91 $event = new GetResponseEvent($this, $request, $type); 92 $this->dispatcher->dispatch(Events::onCoreRequest, $event); 93 94 if ($event->hasResponse()) { 95 return $this->filterResponse($event->getResponse(), $request, $type); 91 96 } 92 97 … … 96 101 } 97 102 98 $event = new Event($this, 'core.controller', array('request_type' => $type, 'request' => $request)); 99 $controller = $this->dispatcher->filter($event, $controller); 100 101 // controller must be a callable 102 if (!is_callable($controller)) { 103 throw new \LogicException(sprintf('The controller must be a callable (%s given).', $this->varToString($controller))); 104 } 103 $event = new FilterControllerEvent($this, $controller, $request, $type); 104 $this->dispatcher->dispatch(Events::onCoreController, $event); 105 $controller = $event->getController(); 105 106 106 107 // controller arguments … … 112 113 // view 113 114 if (!$response instanceof Response) { 114 $event = new Event($this, 'core.view', array('request_type' => $type, 'request' => $request, 'controller_value' => $response)); 115 $retval = $this->dispatcher->notifyUntil($event); 116 if ($event->isProcessed()) { 117 $response = $retval; 115 $event = new GetResponseForControllerResultEvent($this, $request, $type, $response); 116 $this->dispatcher->dispatch(Events::onCoreView, $event); 117 118 if ($event->hasResponse()) { 119 $response = $event->getResponse(); 120 } 121 122 if (!$response instanceof Response) { 123 throw new \LogicException(sprintf('The controller must return a response (%s given).', $this->varToString($response))); 118 124 } 119 125 } 120 126 121 return $this->filterResponse($response, $request, sprintf('The controller must return a response (%s given).', $this->varToString($response)),$type);127 return $this->filterResponse($response, $request, $type); 122 128 } 123 129 … … 133 139 * @throws \RuntimeException if the passed object is not a Response instance 134 140 */ 135 protected function filterResponse( $response, $request, $message, $type)141 protected function filterResponse(Response $response, Request $request, $type) 136 142 { 137 if (!$response instanceof Response) { 138 throw new \RuntimeException($message); 139 } 143 $event = new FilterResponseEvent($this, $request, $type, $response); 140 144 141 $ response = $this->dispatcher->filter(new Event($this, 'core.response', array('request_type' => $type, 'request' => $request)), $response);145 $this->dispatcher->dispatch(Events::onCoreResponse, $event); 142 146 143 if (!$response instanceof Response) { 144 throw new \RuntimeException('A "core.response" listener returned a non response object.'); 145 } 146 147 return $response; 147 return $event->getResponse(); 148 148 } 149 149 … … 159 159 protected function handleException(\Exception $e, $request, $type) 160 160 { 161 $event = new Event($this, 'core.exception', array('request_type' => $type, 'request' => $request, 'exception' => $e)); 162 $response = $this->dispatcher->notifyUntil($event); 163 if (!$event->isProcessed()) { 161 $event = new GetResponseForExceptionEvent($this, $request, $type, $e); 162 $this->dispatcher->dispatch(Events::onCoreException, $event); 163 164 if (!$event->hasResponse()) { 164 165 throw $e; 165 166 } 166 167 167 return $this->filterResponse($ response, $request, 'A "core.exception" listener returned a non response object.', $type);168 return $this->filterResponse($event->getResponse(), $request, $type); 168 169 } 169 170 branches/2.0/src/Symfony/Component/HttpKernel/ResponseListener.php
r32184 r32299 12 12 namespace Symfony\Component\HttpKernel; 13 13 14 use Symfony\Component\ EventDispatcher\EventInterface;14 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 15 15 use Symfony\Component\HttpFoundation\Response; 16 16 17 17 /** 18 18 * ResponseListener fixes the Response Content-Type. 19 *20 * The filter method must be connected to the core.response event.21 19 * 22 20 * @author Fabien Potencier <fabien@symfony.com> … … 34 32 * Filters the Response. 35 33 * 36 * @param EventInterface $event An EventInterface instance 37 * @param Response $response A Response instance 34 * @param FilterResponseEvent $event A FilterResponseEvent instance 38 35 */ 39 public function filter(EventInterface $event, Response $response)36 public function onCoreResponse(FilterResponseEvent $event) 40 37 { 41 if (HttpKernelInterface::MASTER_REQUEST !== $event->get ('request_type')) {42 return $response;38 if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { 39 return; 43 40 } 41 42 $response = $event->getResponse(); 44 43 45 44 if (null === $response->getCharset()) { … … 48 47 49 48 if ($response->headers->has('Content-Type')) { 50 return $response;49 return; 51 50 } 52 51 53 $request = $event->get ('request');52 $request = $event->getRequest(); 54 53 $format = $request->getRequestFormat(); 55 54 if ((null !== $format) && $mimeType = $request->getMimeType($format)) { 56 55 $response->headers->set('Content-Type', $mimeType); 57 56 } 58 59 return $response;60 57 } 61 58 } branches/2.0/src/Symfony/Component/Security/Http/Authentication/AuthenticationFailureHandlerInterface.php
r32076 r32299 3 3 namespace Symfony\Component\Security\Http\Authentication; 4 4 5 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 5 6 use Symfony\Component\Security\Core\Exception\AuthenticationException; 6 use Symfony\Component\EventDispatcher\EventInterface;7 7 use Symfony\Component\HttpFoundation\Request; 8 8 … … 23 23 * AbstractAuthenticationListener. 24 24 * 25 * @param EventInterface $event the "core.security" event, this event always25 * @param GetResponseEvent $event the "onCoreRequest" event, this event always 26 26 * has the kernel as target 27 27 * @param Request $request … … 30 30 * @return Response the response to return 31 31 */ 32 function onAuthenticationFailure( EventInterface$event, Request $request, AuthenticationException $exception);32 function onAuthenticationFailure(GetResponseEvent $event, Request $request, AuthenticationException $exception); 33 33 } branches/2.0/src/Symfony/Component/Security/Http/Authentication/AuthenticationSuccessHandlerInterface.php
r31979 r32299 3 3 namespace Symfony\Component\Security\Http\Authentication; 4 4 5 use Symfony\Component\ EventDispatcher\EventInterface;5 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 6 6 use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 7 7 use Symfony\Component\HttpFoundation\Request; … … 23 23 * AbstractAuthenticationListener. 24 24 * 25 * @param EventInterface $event the "core.security" event, this event always25 * @param GetResponseEvent $event the "onCoreRequest" event, this event always 26 26 * has the kernel as target 27 27 * @param Request $request … … 30 30 * @return Response the response to return 31 31 */ 32 function onAuthenticationSuccess( EventInterface$event, Request $request, TokenInterface $token);32 function onAuthenticationSuccess(GetResponseEvent $event, Request $request, TokenInterface $token); 33 33 } branches/2.0/src/Symfony/Component/Security/Http/Authorization/AccessDeniedHandlerInterface.php
r31979 r32299 4 4 5 5 use Symfony\Component\HttpFoundation\Request; 6 use Symfony\Component\ EventDispatcher\EventInterface;6 use Symfony\Component\HttpKernel\Event\ExceptionEvent; 7 7 use Symfony\Component\Security\Core\Exception\AccessDeniedException; 8 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 8 9 9 10 /** … … 18 19 * Handles an access denied failure. 19 20 * 20 * @param EventInterface$event21 * @param Request $request22 * @param AccessDeniedException $accessDeniedException21 * @param GetResponseForExceptionEvent $event 22 * @param Request $request 23 * @param AccessDeniedException $accessDeniedException 23 24 * 24 25 * @return Response may return null 25 26 */ 26 function handle( EventInterface$event, Request $request, AccessDeniedException $accessDeniedException);27 function handle(GetResponseForExceptionEvent $event, Request $request, AccessDeniedException $accessDeniedException); 27 28 } branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/AuthenticationEntryPointInterface.php
r32184 r32299 12 12 namespace Symfony\Component\Security\Http\EntryPoint; 13 13 14 use Symfony\Component\ EventDispatcher\EventInterface;14 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 15 15 use Symfony\Component\Security\Core\Exception\AuthenticationException; 16 16 use Symfony\Component\HttpFoundation\Request; … … 27 27 * Starts the authentication scheme. 28 28 * 29 * @param EventInterface $event The "core.security" event29 * @param GetResponseEvent $event The "onCoreRequest" event 30 30 * @param object $request The request that resulted in an AuthenticationException 31 31 * @param AuthenticationException $authException The exception that started the authentication process 32 32 */ 33 function start( EventInterface$event, Request $request, AuthenticationException $authException = null);33 function start(GetResponseEvent $event, Request $request, AuthenticationException $authException = null); 34 34 } branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/BasicAuthenticationEntryPoint.php
r32220 r32299 12 12 namespace Symfony\Component\Security\Http\EntryPoint; 13 13 14 use Symfony\Component\EventDispatcher\EventInterface;15 14 use Symfony\Component\Security\Core\Exception\AuthenticationException; 16 15 use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; 17 16 use Symfony\Component\HttpFoundation\Response; 18 17 use Symfony\Component\HttpFoundation\Request; 18 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 19 19 20 20 /** … … 32 32 } 33 33 34 public function start( EventInterface$event, Request $request, AuthenticationException $authException = null)34 public function start(GetResponseEvent $event, Request $request, AuthenticationException $authException = null) 35 35 { 36 36 $response = new Response(); branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/DigestAuthenticationEntryPoint.php
r32220 r32299 12 12 namespace Symfony\Component\Security\Http\EntryPoint; 13 13 14 use Symfony\Component\EventDispatcher\EventInterface;15 14 use Symfony\Component\Security\Core\Exception\AuthenticationException; 16 15 use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; … … 19 18 use Symfony\Component\HttpFoundation\Request; 20 19 use Symfony\Component\HttpKernel\Log\LoggerInterface; 20 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 21 21 22 22 /** … … 40 40 } 41 41 42 public function start( EventInterface$event, Request $request, AuthenticationException $authException = null)42 public function start(GetResponseEvent $event, Request $request, AuthenticationException $authException = null) 43 43 { 44 44 $expiryTime = microtime(true) + $this->nonceValiditySeconds * 1000; branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/FormAuthenticationEntryPoint.php
r32220 r32299 12 12 namespace Symfony\Component\Security\Http\EntryPoint; 13 13 14 use Symfony\Component\EventDispatcher\EventInterface;15 14 use Symfony\Component\HttpFoundation\Request; 16 15 use Symfony\Component\HttpFoundation\Response; … … 19 18 use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; 20 19 use Symfony\Component\HttpKernel\HttpKernelInterface; 20 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 21 21 22 22 /** … … 45 45 * {@inheritdoc} 46 46 */ 47 public function start( EventInterface$event, Request $request, AuthenticationException $authException = null)47 public function start(GetResponseEvent $event, Request $request, AuthenticationException $authException = null) 48 48 { 49 49 if ($this->useForward) { 50 return $event->get Subject()->handle(Request::create($this->loginPath), HttpKernelInterface::SUB_REQUEST);50 return $event->getKernel()->handle(Request::create($this->loginPath), HttpKernelInterface::SUB_REQUEST); 51 51 } 52 52 branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/RetryAuthenticationEntryPoint.php
r32220 r32299 12 12 namespace Symfony\Component\Security\Http\EntryPoint; 13 13 14 use Symfony\Component\EventDispatcher\EventInterface;15 14 use Symfony\Component\Security\Core\Exception\AuthenticationException; 16 15 use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; … … 18 17 use Symfony\Component\HttpFoundation\RedirectResponse; 19 18 use Symfony\Component\HttpFoundation\Request; 19 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 20 20 21 21 /** … … 37 37 } 38 38 39 public function start( EventInterface$event, Request $request, AuthenticationException $authException = null)39 public function start(GetResponseEvent $event, Request $request, AuthenticationException $authException = null) 40 40 { 41 41 $scheme = $request->isSecure() ? 'http' : 'https'; branches/2.0/src/Symfony/Component/Security/Http/Firewall.php
r32227 r32299 12 12 namespace Symfony\Component\Security\Http; 13 13 14 use Symfony\Component\HttpKernel\HttpKernelInterface; 15 use Symfony\Component\HttpKernel\Events; 16 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 17 use Symfony\Component\HttpFoundation\Request; 14 18 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 15 use Symfony\Component\EventDispatcher\EventInterface;16 use Symfony\Component\EventDispatcher\Event;17 use Symfony\Component\HttpKernel\HttpKernelInterface;18 use Symfony\Component\HttpFoundation\Request;19 19 20 20 /** … … 26 26 * everything else for instance). 27 27 * 28 * The handle method must be connected to the core.request event.29 *30 28 * @author Fabien Potencier <fabien@symfony.com> 31 29 */ … … 33 31 { 34 32 private $map; 33 private $dispatcher; 34 private $currentListeners; 35 35 36 36 /** … … 43 43 $this->map = $map; 44 44 $this->dispatcher = $dispatcher; 45 $this->currentListeners = array(); 45 46 } 46 47 … … 48 49 * Handles security. 49 50 * 50 * @param EventInterface $event An EventInterfaceinstance51 * @param GetResponseEvent $event An GetResponseEvent instance 51 52 */ 52 public function handle(EventInterface$event)53 public function onCoreRequest(GetResponseEvent $event) 53 54 { 54 if (HttpKernelInterface::MASTER_REQUEST !== $event->get ('request_type')) {55 if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { 55 56 return; 56 57 } 57 58 58 59 // register listeners for this firewall 59 list($listeners, $exception) = $this->map->getListeners($event->get ('request'));60 list($listeners, $exception) = $this->map->getListeners($event->getRequest()); 60 61 if (null !== $exception) { 61 62 $exception->register($this->dispatcher); … … 66 67 $response = $listener->handle($event); 67 68 68 if ($event-> isProcessed()) {69 return $response;69 if ($event->hasResponse()) { 70 break; 70 71 } 71 72 } branches/2.0/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php
r32253 r32299 12 12 namespace Symfony\Component\Security\Http\Firewall; 13 13 14 use Symfony\Component\EventDispatcher\Event;15 14 use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface; 16 15 use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface; … … 19 18 use Symfony\Component\Security\Core\SecurityContextInterface; 20 19 use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; 20 use Symfony\Component\Security\Core\Exception\AuthenticationException; 21 21 use Symfony\Component\HttpKernel\Log\LoggerInterface; 22 use Symfony\Component\ EventDispatcher\EventDispatcherInterface;23 use Symfony\Component\ EventDispatcher\EventInterface;24 use Symfony\Component\ Security\Core\Exception\AuthenticationException;22 use Symfony\Component\HttpKernel\HttpKernelInterface; 23 use Symfony\Component\HttpKernel\Events as KernelEvents; 24 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 25 25 use Symfony\Component\HttpFoundation\Request; 26 use Symfony\Component\HttpKernel\HttpKernelInterface;27 26 use Symfony\Component\HttpFoundation\Response; 28 27 use Symfony\Component\HttpFoundation\RedirectResponse; 29 28 use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 29 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 30 use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; 31 use Symfony\Component\Security\Http\Events; 30 32 31 33 /** … … 54 56 private $securityContext; 55 57 private $sessionStrategy; 56 private $ eventDispatcher;58 private $dispatcher; 57 59 private $successHandler; 58 60 private $failureHandler; … … 67 69 * @param LoggerInterface $logger A LoggerInterface instance 68 70 */ 69 public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, $providerKey, array $options = array(), AuthenticationSuccessHandlerInterface $successHandler = null, AuthenticationFailureHandlerInterface $failureHandler = null, LoggerInterface $logger = null, EventDispatcherInterface $ eventDispatcher = null)71 public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, $providerKey, array $options = array(), AuthenticationSuccessHandlerInterface $successHandler = null, AuthenticationFailureHandlerInterface $failureHandler = null, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null) 70 72 { 71 73 if (empty($providerKey)) { … … 90 92 ), $options); 91 93 $this->logger = $logger; 92 $this-> eventDispatcher = $eventDispatcher;94 $this->dispatcher = $dispatcher; 93 95 } 94 96 … … 106 108 * Handles form based authentication. 107 109 * 108 * @param Event $event AnEvent instance109 */ 110 public final function handle( EventInterface$event)111 { 112 $request = $event->get ('request');110 * @param GetResponseEvent $event A GetResponseEvent instance 111 */ 112 public final function handle(GetResponseEvent $event) 113 { 114 $request = $event->getRequest(); 113 115 114 116 if (!$this->requiresAuthentication($request)) { … … 130 132 throw new \RuntimeException('attemptAuthentication() must either return a Response, an implementation of TokenInterface, or null.'); 131 133 } 132 } catch (AuthenticationException $failed) { 133 $response = $this->onFailure($event, $request, $failed); 134 } 135 136 $event->setProcessed(); 137 138 return $response; 134 } catch (AuthenticationException $e) { 135 $response = $this->onFailure($event, $request, $e); 136 } 137 138 $event->setResponse($response); 139 139 } 140 140 … … 166 166 abstract protected function attemptAuthentication(Request $request); 167 167 168 private function onFailure( $event, Request $request, AuthenticationException $failed)168 private function onFailure(GetResponseEvent $event, Request $request, AuthenticationException $failed) 169 169 { 170 170 if (null !== $this->logger) { … … 202 202 } 203 203 204 private function onSuccess( EventInterface$event, Request $request, TokenInterface $token)204 private function onSuccess(GetResponseEvent $event, Request $request, TokenInterface $token) 205 205 { 206 206 if (null !== $this->logger) { … … 214 214 $session->remove(SecurityContextInterface::LAST_USERNAME); 215 215 216 if (null !== $this->eventDispatcher) { 217 $this->eventDispatcher->notify(new Event($this, 'security.interactive_login', array('request' => $request, 'token' => $token))); 216 if (null !== $this->dispatcher) { 217 $loginEvent = new InteractiveLoginEvent($request, $token); 218 $this->dispatcher->dispatch(Events::onSecurityInteractiveLogin, $loginEvent); 218 219 } 219 220 branches/2.0/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php
r32253 r32299 12 12 namespace Symfony\Component\Security\Http\Firewall; 13 13 14 use Symfony\Component\EventDispatcher\Event;15 14 use Symfony\Component\Security\Core\SecurityContextInterface; 16 15 use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; 17 use Symfony\Component\HttpKernel\Log\LoggerInterface;18 use Symfony\Component\EventDispatcher\EventDispatcherInterface;19 use Symfony\Component\EventDispatcher\EventInterface;20 16 use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken; 21 17 use Symfony\Component\Security\Core\Exception\AuthenticationException; 18 use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; 19 use Symfony\Component\Security\Http\Events; 20 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 21 use Symfony\Component\HttpKernel\Events as KernelEvents; 22 use Symfony\Component\HttpKernel\Log\LoggerInterface; 22 23 use Symfony\Component\HttpFoundation\Request; 24 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 23 25 24 26 /** … … 35 37 private $authenticationManager; 36 38 private $providerKey; 37 private $ eventDispatcher;39 private $dispatcher; 38 40 39 public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, LoggerInterface $logger = null, EventDispatcherInterface $ eventDispatcher = null)41 public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null) 40 42 { 41 43 $this->securityContext = $securityContext; … … 43 45 $this->providerKey = $providerKey; 44 46 $this->logger = $logger; 45 $this-> eventDispatcher = $eventDispatcher;47 $this->dispatcher = $dispatcher; 46 48 } 47 49 … … 49 51 * Handles X509 authentication. 50 52 * 51 * @param EventInterface $event An EventInterfaceinstance53 * @param GetResponseEvent $event A GetResponseEvent instance 52 54 */ 53 public final function handle( EventInterface$event)55 public final function handle(GetResponseEvent $event) 54 56 { 55 $request = $event->get ('request');57 $request = $event->getRequest(); 56 58 57 59 if (null !== $this->logger) { … … 79 81 $this->securityContext->setToken($token); 80 82 81 if (null !== $this->eventDispatcher) { 82 $this->eventDispatcher->notify(new Event($this, 'security.interactive_login', array('request' => $request, 'token' => $token))); 83 if (null !== $this->dispatcher) { 84 $loginEvent = new InteractiveLoginEvent($request, $token); 85 $this->dispatcher->dispatch(Events::onSecurityInteractiveLogin, $loginEvent); 83 86 } 84 87 } catch (AuthenticationException $failed) { branches/2.0/src/Symfony/Component/Security/Http/Firewall/AccessListener.php
r32227 r32299 17 17 use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; 18 18 use Symfony\Component\HttpKernel\Log\LoggerInterface; 19 use Symfony\Component\ EventDispatcher\EventDispatcherInterface;20 use Symfony\Component\ EventDispatcher\EventInterface;19 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 20 use Symfony\Component\HttpKernel\Events; 21 21 use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException; 22 22 use Symfony\Component\Security\Core\Exception\AccessDeniedException; … … 47 47 * Handles access authorization. 48 48 * 49 * @param EventInterface $event An EventInterfaceinstance49 * @param GetResponseEvent $event A GetResponseEvent instance 50 50 */ 51 public function handle( EventInterface$event)51 public function handle(GetResponseEvent $event) 52 52 { 53 53 if (null === $token = $this->context->getToken()) { … … 55 55 } 56 56 57 $request = $event->get ('request');57 $request = $event->getRequest(); 58 58 59 59 list($attributes, $channel) = $this->map->getPatterns($request); branches/2.0/src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php
r32227 r32299 14 14 use Symfony\Component\Security\Core\SecurityContextInterface; 15 15 use Symfony\Component\HttpKernel\Log\LoggerInterface; 16 use Symfony\Component\ EventDispatcher\EventDispatcherInterface;17 use Symfony\Component\ EventDispatcher\EventInterface;16 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 17 use Symfony\Component\HttpKernel\Events; 18 18 use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; 19 19 … … 40 40 * Handles anonymous authentication. 41 41 * 42 * @param EventInterface $event An EventInterfaceinstance42 * @param GetResponseEvent $event A GetResponseEvent instance 43 43 */ 44 public function handle( EventInterface$event)44 public function handle(GetResponseEvent $event) 45 45 { 46 46 if (null !== $this->context->getToken()) { branches/2.0/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php
r32227 r32299 16 16 use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; 17 17 use Symfony\Component\HttpKernel\Log\LoggerInterface; 18 use Symfony\Component\ EventDispatcher\EventDispatcherInterface;19 use Symfony\Component\ EventDispatcher\EventInterface;18 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 19 use Symfony\Component\HttpKernel\Events; 20 20 use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; 21 21 use Symfony\Component\Security\Core\Exception\AuthenticationException; … … 52 52 * Handles basic authentication. 53 53 * 54 * @param EventInterface $event An EventInterfaceinstance54 * @param GetResponseEvent $event A GetResponseEvent instance 55 55 */ 56 public function handle( EventInterface$event)56 public function handle(GetResponseEvent $event) 57 57 { 58 $request = $event->get ('request');58 $request = $event->getRequest(); 59 59 60 60 if (false === $username = $request->server->get('PHP_AUTH_USER', false)) { branches/2.0/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php
r32227 r32299 15 15 use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; 16 16 use Symfony\Component\HttpKernel\Log\LoggerInterface; 17 use Symfony\Component\ EventDispatcher\EventDispatcherInterface;18 use Symfony\Component\ EventDispatcher\EventInterface;17 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 18 use Symfony\Component\HttpKernel\Events; 19 19 20 20 /** … … 40 40 * Handles channel management. 41 41 * 42 * @param EventInterface $event An EventInterfaceinstance42 * @param GetResponseEvent $event A GetResponseEvent instance 43 43 */ 44 public function handle( EventInterface$event)44 public function handle(GetResponseEvent $event) 45 45 { 46 $request = $event->get ('request');46 $request = $event->getRequest(); 47 47 48 48 list($attributes, $channel) = $this->map->getPatterns($request); … … 53 53 } 54 54 55 $ event->setProcessed();55 $response = $this->authenticationEntryPoint->start($event, $request); 56 56 57 return $this->authenticationEntryPoint->start($event, $request); 57 $event->setResponse($response); 58 59 return; 58 60 } 59 61 … … 63 65 } 64 66 65 $ event->setProcessed();67 $response = $this->authenticationEntryPoint->start($event, $request); 66 68 67 return $this->authenticationEntryPoint->start($event, $request);69 $event->setResponse($response); 68 70 } 69 71 } branches/2.0/src/Symfony/Component/Security/Http/Firewall/ContextListener.php
r32227 r32299 12 12 namespace Symfony\Component\Security\Http\Firewall; 13 13 14 use Symfony\Component\EventDispatcher\EventInterface;15 use Symfony\Component\EventDispatcher\EventDispatcherInterface;16 14 use Symfony\Component\HttpFoundation\Response; 17 15 use Symfony\Component\HttpKernel\HttpKernelInterface; 18 16 use Symfony\Component\HttpKernel\Log\LoggerInterface; 17 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 18 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 19 use Symfony\Component\HttpKernel\Events; 19 20 use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; 20 21 use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; … … 23 24 use Symfony\Component\Security\Core\SecurityContext; 24 25 use Symfony\Component\Security\Core\User\UserInterface; 26 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 25 27 26 28 /** … … 37 39 private $userProviders; 38 40 39 public function __construct(SecurityContext $context, array $userProviders, $contextKey, LoggerInterface $logger = null, EventDispatcherInterface $ eventDispatcher = null)41 public function __construct(SecurityContext $context, array $userProviders, $contextKey, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null) 40 42 { 41 43 if (empty($contextKey)) { … … 47 49 $this->contextKey = $contextKey; 48 50 49 if (null !== $ eventDispatcher) {50 $ eventDispatcher->connect('core.response', array($this, 'write'), 0);51 if (null !== $dispatcher) { 52 $dispatcher->addListener(Events::onCoreResponse, $this); 51 53 } 52 54 } … … 55 57 * Reads the SecurityContext from the session. 56 58 * 57 * @param EventInterface $event An EventInterfaceinstance59 * @param GetResponseEvent $event A GetResponseEvent instance 58 60 */ 59 public function handle( EventInterface$event)61 public function handle(GetResponseEvent $event) 60 62 { 61 $request = $event->get ('request');63 $request = $event->getRequest(); 62 64 63 65 $session = $request->hasSession() ? $request->getSession() : null; … … 83 85 * Writes the SecurityContext to the session. 84 86 * 85 * @param EventInterface $event An EventInterfaceinstance87 * @param FilterResponseEvent $event A FilterResponseEvent instance 86 88 */ 87 public function write(EventInterface $event, Response $response)89 public function onCoreResponse(FilterResponseEvent $event) 88 90 { 89 if (HttpKernelInterface::MASTER_REQUEST !== $event->get ('request_type')) {90 return $response;91 if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { 92 return; 91 93 } 92 94 93 95 if (null === $token = $this->context->getToken()) { 94 return $response;96 return; 95 97 } 96 98 97 99 if (null === $token || $token instanceof AnonymousToken) { 98 return $response;100 return; 99 101 } 100 102 … … 103 105 } 104 106 105 $event->get('request')->getSession()->set('_security_'.$this->contextKey, serialize($token)); 106 107 return $response; 107 $event->getRequest()->getSession()->set('_security_'.$this->contextKey, serialize($token)); 108 108 } 109 109 branches/2.0/src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php
r32227 r32299 16 16 use Symfony\Component\Security\Http\EntryPoint\DigestAuthenticationEntryPoint; 17 17 use Symfony\Component\HttpKernel\Log\LoggerInterface; 18 use Symfony\Component\ EventDispatcher\EventDispatcherInterface;19 use Symfony\Component\ EventDispatcher\EventInterface;18 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 19 use Symfony\Component\HttpKernel\Events; 20 20 use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; 21 21 use Symfony\Component\Security\Core\Exception\BadCredentialsException; … … 55 55 * Handles digest authentication. 56 56 * 57 * @param EventInterface $event An EventInterfaceinstance57 * @param GetResponseEvent $event A GetResponseEvent instance 58 58 */ 59 public function handle( EventInterface$event)60 { 61 $request = $event->get ('request');59 public function handle(GetResponseEvent $event) 60 { 61 $request = $event->getRequest(); 62 62 63 63 if (!$header = $request->server->get('PHP_AUTH_DIGEST')) { … … 122 122 } 123 123 124 private function fail( EventInterface$event, Request $request, AuthenticationException $authException)124 private function fail(GetResponseEvent $event, Request $request, AuthenticationException $authException) 125 125 { 126 126 $this->securityContext->setToken(null); branches/2.0/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php
r32227 r32299 18 18 use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; 19 19 use Symfony\Component\HttpKernel\Log\LoggerInterface; 20 use Symfony\Component\EventDispatcher\EventDispatcherInterface;21 use Symfony\Component\EventDispatcher\EventInterface;22 20 use Symfony\Component\Security\Core\Exception\AuthenticationException; 23 21 use Symfony\Component\Security\Core\Exception\AccessDeniedException; … … 26 24 use Symfony\Component\HttpFoundation\Request; 27 25 use Symfony\Component\HttpKernel\HttpKernelInterface; 26 use Symfony\Component\HttpKernel\Events; 27 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 28 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 28 29 29 30 /** … … 53 54 54 55 /** 55 * Registers a core.exception listener to take care of security exceptions.56 * Registers a onCoreException listener to take care of security exceptions. 56 57 * 57 58 * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance 58 * @param integer $priority The priority59 59 */ 60 60 public function register(EventDispatcherInterface $dispatcher) 61 61 { 62 $dispatcher-> connect('core.exception', array($this, 'handleException'), 0);62 $dispatcher->addListener(Events::onCoreException, $this); 63 63 } 64 64 … … 66 66 * Handles security related exceptions. 67 67 * 68 * @param EventInterface $event An EventInterfaceinstance68 * @param GetResponseForExceptionEvent $event An GetResponseForExceptionEvent instance 69 69 */ 70 public function handleException(EventInterface$event)70 public function onCoreException(GetResponseForExceptionEvent $event) 71 71 { 72 $exception = $event->get ('exception');73 $request = $event->get ('request');72 $exception = $event->getException(); 73 $request = $event->getRequest(); 74 74 75 75 if ($exception instanceof AuthenticationException) { … … 119 119 $subRequest->attributes->set(SecurityContextInterface::ACCESS_DENIED_ERROR, $exception); 120 120 121 $response = $event->get Subject()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);121 $response = $event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true); 122 122 $response->setStatusCode(403); 123 123 } … … 127 127 } 128 128 129 $event->set ('exception',new \RuntimeException('Exception thrown when handling an exception.', 0, $e));129 $event->setException(new \RuntimeException('Exception thrown when handling an exception.', 0, $e)); 130 130 131 131 return; … … 136 136 } 137 137 138 $event->setProcessed(); 139 140 return $response; 138 $event->setResponse($response); 141 139 } 142 140 143 private function startAuthentication( EventInterface$event, Request $request, AuthenticationException $authException)141 private function startAuthentication(GetResponseForExceptionEvent $event, Request $request, AuthenticationException $authException) 144 142 { 145 143 $this->context->setToken(null); branches/2.0/src/Symfony/Component/Security/Http/Firewall/ListenerInterface.php
r32227 r32299 12 12 namespace Symfony\Component\Security\Http\Firewall; 13 13 14 use Symfony\Component\EventDispatcher\EventInterface; 15 14 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 16 15 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 17 16 … … 26 25 * This interface must be implemented by firewall listeners. 27 26 * 28 * @param EventInterface $dispatcher27 * @param GetResponseEvent $event 29 28 */ 30 function handle( EventInterface$event);29 function handle(GetResponseEvent $event); 31 30 } branches/2.0/src/Symfony/Component/Security/Http/Firewall/LogoutListener.php
r32227 r32299 16 16 use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface; 17 17 use Symfony\Component\Security\Core\SecurityContextInterface; 18 use Symfony\Component\EventDispatcher\EventDispatcherInterface;19 use Symfony\Component\EventDispatcher\EventInterface;20 18 use Symfony\Component\HttpFoundation\Response; 21 19 use Symfony\Component\HttpFoundation\RedirectResponse; 20 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 21 use Symfony\Component\HttpKernel\Events; 22 22 23 23 /** … … 64 64 * Performs the logout if requested 65 65 * 66 * @param EventInterface $event An EventInterfaceinstance66 * @param GetResponseEvent $event A GetResponseEvent instance 67 67 */ 68 public function handle( EventInterface$event)68 public function handle(GetResponseEvent $event) 69 69 { 70 $request = $event->get ('request');70 $request = $event->getRequest(); 71 71 72 72 if ($this->logoutPath !== $request->getPathInfo()) { … … 93 93 $this->securityContext->setToken(null); 94 94 95 $event->setProcessed(); 96 97 return $response; 95 $event->setResponse($response); 98 96 } 99 97 } branches/2.0/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php
r32227 r32299 3 3 namespace Symfony\Component\Security\Http\Firewall; 4 4 5 use Symfony\Component\EventDispatcher\Event; 5 use Symfony\Component\HttpKernel\HttpKernelInterface; 6 use Symfony\Component\HttpKernel\Log\LoggerInterface; 7 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 8 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 9 use Symfony\Component\HttpKernel\Events as KernelEvents; 10 use Symfony\Component\HttpFoundation\Response; 6 11 use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 12 use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; 7 13 use Symfony\Component\Security\Core\Exception\AuthenticationException; 8 14 use Symfony\Component\Security\Core\Exception\CookieTheftException; 9 use Symfony\Component\HttpKernel\HttpKernelInterface;10 use Symfony\Component\HttpKernel\Log\LoggerInterface;11 use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;12 use Symfony\Component\EventDispatcher\EventDispatcherInterface;13 use Symfony\Component\EventDispatcher\EventInterface;14 use Symfony\Component\HttpFoundation\Response;15 15 use Symfony\Component\Security\Core\SecurityContext; 16 16 use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; 17 use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; 18 use Symfony\Component\Security\Http\Events; 19 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 17 20 18 21 /* … … 36 39 private $authenticationManager; 37 40 private $logger; 38 private $ eventDispatcher;41 private $dispatcher; 39 42 40 43 /** … … 46 49 * @param LoggerInterface $logger 47 50 */ 48 public function __construct(SecurityContext $securityContext, RememberMeServicesInterface $rememberMeServices, AuthenticationManagerInterface $authenticationManager, LoggerInterface $logger = null, EventDispatcherInterface $ eventDispatcher = null)51 public function __construct(SecurityContext $securityContext, RememberMeServicesInterface $rememberMeServices, AuthenticationManagerInterface $authenticationManager, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null) 49 52 { 50 53 $this->securityContext = $securityContext; … … 52 55 $this->authenticationManager = $authenticationManager; 53 56 $this->logger = $logger; 54 $this-> eventDispatcher = $eventDispatcher;57 $this->dispatcher = $dispatcher; 55 58 } 56 59 … … 58 61 * Handles remember-me cookie based authentication. 59 62 * 60 * @param Event $event AnEvent instance63 * @param GetResponseEvent $event A GetResponseEvent instance 61 64 */ 62 public function handle( EventInterface$event)65 public function handle(GetResponseEvent $event) 63 66 { 64 67 if (null !== $this->securityContext->getToken()) { … … 66 69 } 67 70 68 $request = $event->get ('request');71 $request = $event->getRequest(); 69 72 if (null === $token = $this->rememberMeServices->autoLogin($request)) { 70 73 return; … … 75 78 $this->securityContext->setToken($token); 76 79 77 if (null !== $this->eventDispatcher) { 78 $this->eventDispatcher->notify(new Event($this, 'security.interactive_login', array('request' => $request, 'token' => $token))); 80 if (null !== $this->dispatcher) { 81 $loginEvent = new InteractiveLoginEvent($request, $token); 82 $this->dispatcher->dispatch(Events::onSecurityInteractiveLogin, $loginEvent); 79 83 } 80 84 branches/2.0/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php
r32227 r32299 12 12 namespace Symfony\Component\Security\Http\Firewall; 13 13 14 use Symfony\Component\EventDispatcher\Event;15 14 use Symfony\Component\Security\Core\SecurityContextInterface; 16 15 use Symfony\Component\Security\Core\User\UserProviderInterface; … … 18 17 use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface; 19 18 use Symfony\Component\HttpKernel\Log\LoggerInterface; 20 use Symfony\Component\ EventDispatcher\EventDispatcherInterface;21 use Symfony\Component\ EventDispatcher\EventInterface;19 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 20 use Symfony\Component\HttpKernel\Events; 22 21 use Symfony\Component\Security\Core\Exception\AuthenticationException; 23 22 use Symfony\Component\HttpFoundation\Response; … … 28 27 use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException; 29 28 use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 29 use Symfony\Component\Security\Http\Event\SwitchUserEvent; 30 use Symfony\Component\Security\Http\Events; 31 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 30 32 31 33 /** … … 45 47 private $role; 46 48 private $logger; 47 private $ eventDispatcher;49 private $dispatcher; 48 50 49 51 /** 50 52 * Constructor. 51 53 */ 52 public function __construct(SecurityContextInterface $securityContext, UserProviderInterface $provider, UserCheckerInterface $userChecker, $providerKey, AccessDecisionManagerInterface $accessDecisionManager, LoggerInterface $logger = null, $usernameParameter = '_switch_user', $role = 'ROLE_ALLOWED_TO_SWITCH', EventDispatcherInterface $ eventDispatcher = null)54 public function __construct(SecurityContextInterface $securityContext, UserProviderInterface $provider, UserCheckerInterface $userChecker, $providerKey, AccessDecisionManagerInterface $accessDecisionManager, LoggerInterface $logger = null, $usernameParameter = '_switch_user', $role = 'ROLE_ALLOWED_TO_SWITCH', EventDispatcherInterface $dispatcher = null) 53 55 { 54 56 if (empty($providerKey)) { … … 64 66 $this->role = $role; 65 67 $this->logger = $logger; 66 $this-> eventDispatcher = $eventDispatcher;68 $this->dispatcher = $dispatcher; 67 69 } 68 70 … … 70 72 * Handles digest authentication. 71 73 * 72 * @param EventInterface $event An EventInterfaceinstance74 * @param GetResponseEvent $event A GetResponseEvent instance 73 75 */ 74 public function handle( EventInterface$event)76 public function handle(GetResponseEvent $event) 75 77 { 76 $request = $event->get ('request');78 $request = $event->getRequest(); 77 79 78 80 if (!$request->get($this->usernameParameter)) { … … 95 97 $response = new RedirectResponse($request->getUri(), 302); 96 98 97 $event->setProcessed(); 98 99 return $response; 99 $event->setResponse($response); 100 100 } 101 101 … … 130 130 $token = new UsernamePasswordToken($user, $user->getPassword(), $this->providerKey, $roles); 131 131 132 if (null !== $this->eventDispatcher) { 133 $this->eventDispatcher->notify(new Event($this, 'security.switch_user', array('request' => $request, 'target_user' => $token->getUser()))); 132 if (null !== $this->dispatcher) { 133 $switchEvent = new SwitchUserEvent($request, $token->getUser()); 134 $this->dispatcher->dispatch(Events::onSecuritySwitchUser, $switchEvent); 134 135 } 135 136 … … 150 151 } 151 152 152 if (null !== $this->eventDispatcher) { 153 $this->eventDispatcher->notify(new Event($this, 'security.switch_user', array('request' => $request, 'target_user' => $original->getUser()))); 153 if (null !== $this->dispatcher) { 154 $switchEvent = new SwitchUserEvent($request, $original->getUser()); 155 $this->dispatcher->dispatch(Events::onSecuritySwitchUser, $switchEvent); 154 156 } 155 157 branches/2.0/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordFormAuthenticationListener.php
r32227 r32299 12 12 namespace Symfony\Component\Security\Http\Firewall; 13 13 14 use Symfony\Component\EventDispatcher\EventDispatcherInterface;15 16 14 use Symfony\Component\Form\CsrfProvider\CsrfProviderInterface; 17 15 use Symfony\Component\HttpFoundation\Request; … … 24 22 use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException; 25 23 use Symfony\Component\Security\Core\SecurityContextInterface; 24 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 26 25 27 26 /** … … 38 37 * {@inheritdoc} 39 38 */ 40 public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, $providerKey, array $options = array(), AuthenticationSuccessHandlerInterface $successHandler = null, AuthenticationFailureHandlerInterface $failureHandler = null, LoggerInterface $logger = null, EventDispatcherInterface $ eventDispatcher = null, CsrfProviderInterface $csrfProvider = null)39 public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, $providerKey, array $options = array(), AuthenticationSuccessHandlerInterface $successHandler = null, AuthenticationFailureHandlerInterface $failureHandler = null, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, CsrfProviderInterface $csrfProvider = null) 41 40 { 42 41 parent::__construct($securityContext, $authenticationManager, $sessionStrategy, $providerKey, array_merge(array( … … 46 45 'csrf_page_id' => 'form_login', 47 46 'post_only' => true, 48 ), $options), $successHandler, $failureHandler, $logger, $ eventDispatcher);47 ), $options), $successHandler, $failureHandler, $logger, $dispatcher); 49 48 50 49 $this->csrfProvider = $csrfProvider; branches/2.0/src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php
r32253 r32299 12 12 namespace Symfony\Component\Security\Http\Firewall; 13 13 14 use Symfony\Component\EventDispatcher\EventDispatcherInterface;15 14 use Symfony\Component\Security\Core\SecurityContextInterface; 16 15 use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; … … 18 17 use Symfony\Component\HttpFoundation\Request; 19 18 use Symfony\Component\Security\Core\Exception\BadCredentialsException; 19 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 20 20 21 21 /** … … 29 29 private $credentialKey; 30 30 31 public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, $userKey = 'SSL_CLIENT_S_DN_Email', $credentialKey = 'SSL_CLIENT_S_DN', LoggerInterface $logger = null, EventDispatcherInterface $ eventDispatcher = null)31 public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, $userKey = 'SSL_CLIENT_S_DN_Email', $credentialKey = 'SSL_CLIENT_S_DN', LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null) 32 32 { 33 parent::__construct($securityContext, $authenticationManager, $providerKey, $logger, $ eventDispatcher);33 parent::__construct($securityContext, $authenticationManager, $providerKey, $logger, $dispatcher); 34 34 35 35 $this->userKey = $userKey; branches/2.0/src/Symfony/Component/Security/Http/Logout/LogoutSuccessHandlerInterface.php
r32076 r32299 4 4 5 5 use Symfony\Component\HttpFoundation\Request; 6 use Symfony\Component\ EventDispatcher\EventInterface;6 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 7 7 8 8 /** … … 22 22 * Creates a Response object to send upon a successful logout. 23 23 * 24 * @param EventInterface$event24 * @param GetResponseEvent $event 25 25 * @param Request $request 26 26 * @return Response never null 27 27 */ 28 function onLogoutSuccess( EventInterface$event, Request $request);28 function onLogoutSuccess(GetResponseEvent $event, Request $request); 29 29 } branches/2.0/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php
r32184 r32299 14 14 use Symfony\Component\EventDispatcher\Event; 15 15 use Symfony\Component\EventDispatcher\EventDispatcher; 16 use Symfony\Component\EventDispatcher\EventSubscriberInterface; 16 17 17 18 class EventDispatcherTest extends \PHPUnit_Framework_TestCase 18 19 { 19 public function testConnectAndDisconnect() 20 /* Some pseudo events */ 21 const preFoo = 'preFoo'; 22 const postFoo = 'postFoo'; 23 const preBar = 'preBar'; 24 const postBar = 'postBar'; 25 26 private $dispatcher; 27 28 private $listener; 29 30 protected function setUp() 20 31 { 21 $dispatcher = new EventDispatcher(); 22 23 $dispatcher->connect('bar', 'listenToBar'); 24 $this->assertEquals(array('listenToBar'), $dispatcher->getListeners('bar'), '->connect() connects a listener to an event name'); 25 $dispatcher->connect('bar', 'listenToBarBar'); 26 $this->assertEquals(array('listenToBar', 'listenToBarBar'), $dispatcher->getListeners('bar'), '->connect() can connect several listeners for the same event name'); 27 28 $dispatcher->connect('barbar', 'listenToBarBar'); 29 30 $dispatcher->disconnect('bar'); 31 $this->assertEquals(array(), $dispatcher->getListeners('bar'), '->disconnect() without a listener disconnects all listeners of for an event name'); 32 $this->assertEquals(array('listenToBarBar'), $dispatcher->getListeners('barbar'), '->disconnect() without a listener disconnects all listeners of for an event name'); 32 $this->dispatcher = new EventDispatcher(); 33 $this->listener = new TestEventListener(); 33 34 } 34 35 35 public function test GetHasListeners()36 public function testInitialState() 36 37 { 37 $dispatcher = new EventDispatcher(); 38 39 $this->assertFalse($dispatcher->hasListeners('foo'), '->hasListeners() returns false if the event has no listener'); 40 $dispatcher->connect('foo', 'listenToFoo'); 41 $this->assertEquals(true, $dispatcher->hasListeners('foo'), '->hasListeners() returns true if the event has some listeners'); 42 $dispatcher->disconnect('foo', 'listenToFoo'); 43 $this->assertFalse($dispatcher->hasListeners('foo'), '->hasListeners() returns false if the event has no listener'); 44 45 $dispatcher->connect('bar', 'listenToBar'); 46 $this->assertEquals(array('listenToBar'), $dispatcher->getListeners('bar'), '->getListeners() returns an array of listeners connected to the given event name'); 47 $this->assertEquals(array(), $dispatcher->getListeners('foobar'), '->getListeners() returns an empty array if no listener are connected to the given event name'); 38 $this->assertEquals(array(), $this->dispatcher->getListeners()); 39 $this->assertFalse($this->dispatcher->hasListeners(self::preFoo)); 40 $this->assertFalse($this->dispatcher->hasListeners(self::postFoo)); 48 41 } 49 42 50 public function test Notify()43 public function testAddListener() 51 44 { 52 $listener = new Listener(); 53 $dispatcher = new EventDispatcher(); 54 $dispatcher->connect('foo', array($listener, 'listenToFoo')); 55 $dispatcher->connect('foo', array($listener, 'listenToFooBis')); 56 $e = $dispatcher->notify($event = new Event(new \stdClass(), 'foo')); 57 $this->assertEquals('listenToFoolistenToFooBis', $listener->getValue(), '->notify() notifies all registered listeners in order'); 58 59 $listener->reset(); 60 $dispatcher = new EventDispatcher(); 61 $dispatcher->connect('foo', array($listener, 'listenToFooBis')); 62 $dispatcher->connect('foo', array($listener, 'listenToFoo')); 63 $dispatcher->notify(new Event(new \stdClass(), 'foo')); 64 $this->assertEquals('listenToFooBislistenToFoo', $listener->getValue(), '->notify() notifies all registered listeners in order'); 45 $this->dispatcher->addListener(array('preFoo', 'postFoo'), $this->listener); 46 $this->assertTrue($this->dispatcher->hasListeners(self::preFoo)); 47 $this->assertTrue($this->dispatcher->hasListeners(self::postFoo)); 48 $this->assertEquals(1, count($this->dispatcher->getListeners(self::preFoo))); 49 $this->assertEquals(1, count($this->dispatcher->getListeners(self::postFoo))); 50 $this->assertEquals(2, count($this->dispatcher->getListeners())); 65 51 } 66 52 67 public function test NotifyUntil()53 public function testGetListenersSortsByPriority() 68 54 { 69 $listener = new Listener(); 70 $dispatcher = new EventDispatcher(); 71 $dispatcher->connect('foo', array($listener, 'listenToFoo')); 72 $dispatcher->connect('foo', array($listener, 'listenToFooBis')); 73 $dispatcher->notifyUntil($event = new Event(new \stdClass(), 'foo')); 74 $this->assertEquals('listenToFoolistenToFooBis', $listener->getValue(), '->notifyUntil() notifies all registered listeners in order and stops when the event is processed'); 55 $listener1 = new TestEventListener(); 56 $listener2 = new TestEventListener(); 57 $listener3 = new TestEventListener(); 75 58 76 $listener->reset(); 77 $dispatcher = new EventDispatcher(); 78 $dispatcher->connect('foo', array($listener, 'listenToFooBis')); 79 $dispatcher->connect('foo', array($listener, 'listenToFoo')); 80 $dispatcher->notifyUntil($event = new Event(new \stdClass(), 'foo')); 81 $this->assertEquals('listenToFooBis', $listener->getValue(), '->notifyUntil() notifies all registered listeners in order and stops when the event is processed'); 59 $this->dispatcher->addListener('preFoo', $listener1, -10); 60 $this->dispatcher->addListener('preFoo', $listener2); 61 $this->dispatcher->addListener('preFoo', $listener3, 10); 62 63 $expected = array( 64 spl_object_hash($listener3) => $listener3, 65 spl_object_hash($listener2) => $listener2, 66 spl_object_hash($listener1) => $listener1, 67 ); 68 69 $this->assertSame($expected, $this->dispatcher->getListeners('preFoo')); 82 70 } 83 71 84 public function test Filter()72 public function testGetAllListenersSortsByPriority() 85 73 { 86 $listener = newListener();87 $ dispatcher = new EventDispatcher();88 $ dispatcher->connect('foo', array($listener, 'filterFoo'));89 $ dispatcher->connect('foo', array($listener, 'filterFooBis'));90 $ ret = $dispatcher->filter($event = new Event(new \stdClass(), 'foo'), 'foo');91 $ this->assertEquals('-*foo*-', $ret, '->filter() returns the filtered value');74 $listener1 = new TestEventListener(); 75 $listener2 = new TestEventListener(); 76 $listener3 = new TestEventListener(); 77 $listener4 = new TestEventListener(); 78 $listener5 = new TestEventListener(); 79 $listener6 = new TestEventListener(); 92 80 93 $listener->reset(); 94 $dispatcher = new EventDispatcher(); 95 $dispatcher->connect('foo', array($listener, 'filterFooBis')); 96 $dispatcher->connect('foo', array($listener, 'filterFoo')); 97 $ret = $dispatcher->filter($event = new Event(new \stdClass(), 'foo'), 'foo'); 98 $this->assertEquals('*-foo-*', $ret, '->filter() returns the filtered value'); 81 $this->dispatcher->addListener('preFoo', $listener1, -10); 82 $this->dispatcher->addListener('preFoo', $listener2); 83 $this->dispatcher->addListener('preFoo', $listener3, 10); 84 $this->dispatcher->addListener('postFoo', $listener4, -10); 85 $this->dispatcher->addListener('postFoo', $listener5); 86 $this->dispatcher->addListener('postFoo', $listener6, 10); 87 88 $expected = array( 89 'preFoo' => array( 90 spl_object_hash($listener3) => $listener3, 91 spl_object_hash($listener2) => $listener2, 92 spl_object_hash($listener1) => $listener1, 93 ), 94 'postFoo' => array( 95 spl_object_hash($listener6) => $listener6, 96 spl_object_hash($listener5) => $listener5, 97 spl_object_hash($listener4) => $listener4, 98 ), 99 ); 100 101 $this->assertSame($expected, $this->dispatcher->getListeners()); 102 } 103 104 public function testDispatch() 105 { 106 $this->dispatcher->addListener(array('preFoo', 'postFoo'), $this->listener); 107 $this->dispatcher->dispatch(self::preFoo); 108 $this->assertTrue($this->listener->preFooInvoked); 109 $this->assertFalse($this->listener->postFooInvoked); 110 } 111 112 public function testDispatchForClosure() 113 { 114 $invoked = 0; 115 $listener = function () use (&$invoked) { 116 $invoked++; 117 }; 118 $this->dispatcher->addListener(array('preFoo', 'postFoo'), $listener); 119 $this->dispatcher->dispatch(self::preFoo); 120 $this->assertEquals(1, $invoked); 121 } 122 123 public function testStopEventPropagation() 124 { 125 $otherListener = new TestEventListener; 126 127 // postFoo() stops the propagation, so only one listener should 128 // be executed 129 // Manually set priority to enforce $this->listener to be called first 130 $this->dispatcher->addListener('postFoo', $this->listener, 10); 131 $this->dispatcher->addListener('postFoo', $otherListener); 132 $this->dispatcher->dispatch(self::postFoo); 133 $this->assertTrue($this->listener->postFooInvoked); 134 $this->assertFalse($otherListener->postFooInvoked); 135 } 136 137 public function testDispatchByPriority() 138 { 139 $invoked = array(); 140 $listener1 = function () use (&$invoked) { 141 $invoked[] = '1'; 142 }; 143 $listener2 = function () use (&$invoked) { 144 $invoked[] = '2'; 145 }; 146 $listener3 = function () use (&$invoked) { 147 $invoked[] = '3'; 148 }; 149 $this->dispatcher->addListener('preFoo', $listener1, -10); 150 $this->dispatcher->addListener('preFoo', $listener2); 151 $this->dispatcher->addListener('preFoo', $listener3, 10); 152 $this->dispatcher->dispatch(self::preFoo); 153 $this->assertEquals(array('3', '2', '1'), $invoked); 154 } 155 156 public function testRemoveListener() 157 { 158 $this->dispatcher->addListener(array('preBar'), $this->listener); 159 $this->assertTrue($this->dispatcher->hasListeners(self::preBar)); 160 $this->dispatcher->removeListener(array('preBar'), $this->listener); 161 $this->assertFalse($this->dispatcher->hasListeners(self::preBar)); 162 } 163 164 public function testAddSubscriber() 165 { 166 $eventSubscriber = new TestEventSubscriber(); 167 $this->dispatcher->addSubscriber($eventSubscriber); 168 $this->assertTrue($this->dispatcher->hasListeners(self::preFoo)); 169 $this->assertTrue($this->dispatcher->hasListeners(self::postFoo)); 99 170 } 100 171 } 101 172 102 class Listener173 class TestEventListener 103 174 { 104 p rotected105 $value = '';175 public $preFooInvoked = false; 176 public $postFooInvoked = false; 106 177 107 function filterFoo(Event $event, $foo) 178 /* Listener methods */ 179 180 public function preFoo(Event $e) 108 181 { 109 return "*$foo*";182 $this->preFooInvoked = true; 110 183 } 111 184 112 function filterFooBis(Event $event, $foo)185 public function postFoo(Event $e) 113 186 { 114 return "-$foo-"; 115 } 187 $this->postFooInvoked = true; 116 188 117 function listenToFoo(Event $event) 118 { 119 $this->value .= 'listenToFoo'; 120 } 121 122 function listenToFooBis(Event $event) 123 { 124 $this->value .= 'listenToFooBis'; 125 126 $event->setProcessed(); 127 } 128 129 function getValue() 130 { 131 return $this->value; 132 } 133 134 function reset() 135 { 136 $this->value = ''; 189 $e->stopPropagation(); 137 190 } 138 191 } 192 193 class TestEventSubscriber implements EventSubscriberInterface 194 { 195 public static function getSubscribedEvents() 196 { 197 return array('preFoo', 'postFoo'); 198 } 199 } branches/2.0/tests/Symfony/Tests/Component/HttpKernel/ClientTest.php
r32210 r32299 16 16 use Symfony\Component\HttpFoundation\Request; 17 17 use Symfony\Component\HttpFoundation\Response; 18 use Symfony\Component\EventDispatcher\EventDispatcher;19 use Symfony\Component\EventDispatcher\Event;20 18 21 19 require_once __DIR__.'/TestHttpKernel.php'; branches/2.0/tests/Symfony/Tests/Component/HttpKernel/DataCollector/EventDataCollectorTest.php
r32184 r32299 15 15 use Symfony\Component\HttpFoundation\Request; 16 16 use Symfony\Component\HttpFoundation\Response; 17 use Symfony\Component\HttpKernel\Debug\ EventDispatcherTraceableInterface;17 use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcherInterface; 18 18 use Symfony\Component\EventDispatcher\EventDispatcher; 19 20 19 21 20 class EventDataCollectorTest extends \PHPUnit_Framework_TestCase … … 25 24 $c = new EventDataCollector(); 26 25 $c->setEventDispatcher(new TestEventDispatcher()); 27 26 28 27 $c->collect(new Request(), new Response()); 29 28 30 29 $this->assertSame('events',$c->getName()); 31 30 $this->assertSame(array('foo'),$c->getCalledListeners()); 32 31 $this->assertSame(array('bar'),$c->getNotCalledListeners()); 33 32 } 34 33 35 34 } 36 35 37 class TestEventDispatcher extends EventDispatcher implements EventDispatcherTraceableInterface36 class TestEventDispatcher extends EventDispatcher implements TraceableEventDispatcherInterface 38 37 { 39 38 function getCalledListeners() branches/2.0/tests/Symfony/Tests/Component/HttpKernel/Debug/ExceptionListenerTest.php
r32184 r32299 12 12 namespace Symfony\Tests\Component\HttpKernel\Debug; 13 13 14 use Symfony\Component\HttpKernel\HttpKernelInterface; 14 15 use Symfony\Component\HttpKernel\Debug\ExceptionListener; 16 use Symfony\Component\HttpKernel\Debug\ErrorException; 15 17 use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; 16 use Symfony\Component\ EventDispatcher\Event;18 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 17 19 use Symfony\Component\HttpFoundation\Request; 18 use Symfony\Component\Http Kernel\Debug\ErrorException;20 use Symfony\Component\HttpFoundation\Response; 19 21 use Symfony\Tests\Component\HttpKernel\Logger; 20 22 … … 30 32 $logger = new TestLogger(); 31 33 $l = new ExceptionListener('foo', $logger); 32 33 $_logger = new \ReflectionProperty(get_class($l), 'logger');34 35 $_logger = new \ReflectionProperty(get_class($l), 'logger'); 34 36 $_logger->setAccessible(true); 35 $_controller = new \ReflectionProperty(get_class($l), 'controller');37 $_controller = new \ReflectionProperty(get_class($l), 'controller'); 36 38 $_controller->setAccessible(true); 37 38 $this->assertSame($logger, $_logger->getValue($l));39 $this->assertSame('foo', $_controller->getValue($l));39 40 $this->assertSame($logger, $_logger->getValue($l)); 41 $this->assertSame('foo', $_controller->getValue($l)); 40 42 } 41 43 42 44 /** 43 45 * @dataProvider provider 44 46 */ 45 public function testHandleWithoutLogger($event, $event2)47 public function testHandleWithoutLogger($event, $event2) 46 48 { 47 49 //store the current error_log, and set the new one to dev/null 48 50 $error_log = ini_get('error_log'); 49 ini_set('error_log', '/dev/null');50 51 ini_set('error_log', '/dev/null'); 52 51 53 $l = new ExceptionListener('foo'); 54 $l->onCoreException($event); 52 55 53 $this->assertEquals( 'foo', $l->handle($event));54 55 try {56 $ response = $l->handle($event2);57 } catch(\Exception $e){58 $this->assertSame('foo', $e->getMessage());56 $this->assertEquals(new Response('foo'), $event->getResponse()); 57 58 try { 59 $l->onCoreException($event2); 60 } catch(\Exception $e) { 61 $this->assertSame('foo', $e->getMessage()); 59 62 } 60 63 61 64 //restore the old error_log 62 ini_set('error_log', $error_log);65 ini_set('error_log', $error_log); 63 66 } 64 67 65 68 /** 66 69 * @dataProvider provider … … 69 72 { 70 73 $logger = new TestLogger(); 71 72 $l = new ExceptionListener('foo',$logger); 73 74 $this->assertSame('foo', $l->handle($event)); 75 76 try{ 77 $response = $l->handle($event2); 78 }catch(\Exception $e){ 79 $this->assertSame('foo',$e->getMessage()); 74 75 $l = new ExceptionListener('foo', $logger); 76 $l->onCoreException($event); 77 78 $this->assertEquals(new Response('foo'), $event->getResponse()); 79 80 try { 81 $l->onCoreException($event2); 82 } catch(\Exception $e) { 83 $this->assertSame('foo', $e->getMessage()); 80 84 } 81 82 $this->assertEquals(3, $logger->countErrors());83 $this->assertEquals(3, count($logger->getLogs('err')));85 86 $this->assertEquals(3, $logger->countErrors()); 87 $this->assertEquals(3, count($logger->getLogs('err'))); 84 88 } 85 89 86 90 public function provider() 87 91 { 88 $ args = array('exception'=>new ErrorException('foo'),'request'=>new Request());89 90 $event = new Event(new Subject(),'bar',$args);91 $event2 = new Event(new SubjectException(),'bar',$args);92 $request = new Request(); 93 $exception = new ErrorException('foo'); 94 $event = new GetResponseForExceptionEvent(new TestKernel(), $request, 'foo', $exception); 95 $event2 = new GetResponseForExceptionEvent(new TestKernelThatThrowsException(), $request, 'foo', $exception); 92 96 93 97 return array( 94 array($event, $event2)98 array($event, $event2) 95 99 ); 96 100 } 97 101 98 102 } 99 103 … … 104 108 return count($this->logs['err']); 105 109 } 106 110 107 111 public function getDebugLogger() 108 112 { … … 111 115 } 112 116 113 class Subject117 class TestKernel implements HttpKernelInterface 114 118 { 115 public function handle( )119 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) 116 120 { 117 return 'foo';121 return new Response('foo'); 118 122 } 119 123 120 124 } 121 125 122 class SubjectException126 class TestKernelThatThrowsException implements HttpKernelInterface 123 127 { 124 public function handle( )128 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) 125 129 { 126 130 throw new \Exception('bar'); branches/2.0/tests/Symfony/Tests/Component/HttpKernel/HttpCache/EsiListenerTest.php
r32184 r32299 14 14 use Symfony\Component\HttpKernel\HttpCache\Esi; 15 15 use Symfony\Component\HttpKernel\HttpCache\EsiListener; 16 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 17 use Symfony\Component\HttpKernel\Events; 18 use Symfony\Component\HttpKernel\HttpKernelInterface; 19 use Symfony\Component\HttpFoundation\Response; 20 use Symfony\Component\HttpFoundation\Request; 16 21 use Symfony\Component\EventDispatcher\EventDispatcher; 17 use Symfony\Component\EventDispatcher\Event;18 use Symfony\Component\HttpFoundation\Response;19 use Symfony\Component\HttpKernel\HttpKernelInterface;20 22 21 23 class EsiListenerTest extends \PHPUnit_Framework_TestCase … … 24 26 { 25 27 $dispatcher = new EventDispatcher(); 28 $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); 29 $response = new Response('foo <esi:include src="" />'); 26 30 $listener = new EsiListener(new Esi()); 27 $dispatcher->connect('core.response', array($listener, 'filter'));28 31 29 $event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::SUB_REQUEST)); 30 $dispatcher->filter($event, $response = new Response('foo <esi:include src="" />')); 32 $dispatcher->addListener(Events::onCoreResponse, $listener); 33 $event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response); 34 $dispatcher->dispatch(Events::onCoreResponse, $event); 31 35 32 $this->assertEquals('', $ response->headers->get('Surrogate-Control'));36 $this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control')); 33 37 } 34 38 … … 36 40 { 37 41 $dispatcher = new EventDispatcher(); 42 $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); 43 $response = new Response('foo <esi:include src="" />'); 38 44 $listener = new EsiListener(new Esi()); 39 $dispatcher->connect('core.response', array($listener, 'filter'));40 45 41 $event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST)); 42 $dispatcher->filter($event, $response = new Response('foo <esi:include src="" />')); 46 $dispatcher->addListener(Events::onCoreResponse, $listener); 47 $event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response); 48 $dispatcher->dispatch(Events::onCoreResponse, $event); 43 49 44 $this->assertEquals('content="ESI/1.0"', $ response->headers->get('Surrogate-Control'));50 $this->assertEquals('content="ESI/1.0"', $event->getResponse()->headers->get('Surrogate-Control')); 45 51 } 46 52 … … 48 54 { 49 55 $dispatcher = new EventDispatcher(); 56 $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); 57 $response = new Response('foo'); 50 58 $listener = new EsiListener(new Esi()); 51 $dispatcher->connect('core.response', array($listener, 'filter'));52 59 53 $event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST)); 54 $dispatcher->filter($event, $response = new Response('foo')); 60 $dispatcher->addListener(Events::onCoreResponse, $listener); 61 $event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response); 62 $dispatcher->dispatch(Events::onCoreResponse, $event); 55 63 56 $this->assertEquals('', $ response->headers->get('Surrogate-Control'));64 $this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control')); 57 65 } 58 66 } branches/2.0/tests/Symfony/Tests/Component/HttpKernel/HttpCache/TestHttpKernel.php
r32184 r32299 16 16 use Symfony\Component\HttpFoundation\Request; 17 17 use Symfony\Component\HttpFoundation\Response; 18 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; 18 19 use Symfony\Component\EventDispatcher\EventDispatcher; 19 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;20 20 21 21 class TestHttpKernel extends HttpKernel implements ControllerResolverInterface branches/2.0/tests/Symfony/Tests/Component/HttpKernel/HttpCache/TestMultipleHttpKernel.php
r32184 r32299 16 16 use Symfony\Component\HttpFoundation\Request; 17 17 use Symfony\Component\HttpFoundation\Response; 18 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; 18 19 use Symfony\Component\EventDispatcher\EventDispatcher; 19 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;20 20 21 21 class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInterface branches/2.0/tests/Symfony/Tests/Component/HttpKernel/HttpKernelTest.php
r32184 r32299 14 14 use Symfony\Component\HttpKernel\HttpKernel; 15 15 use Symfony\Component\HttpKernel\HttpKernelInterface; 16 use Symfony\Component\HttpKernel\Events; 16 17 use Symfony\Component\HttpFoundation\Request; 17 18 use Symfony\Component\HttpFoundation\Response; … … 43 44 { 44 45 $dispatcher = new EventDispatcher(); 45 $dispatcher-> connect('core.exception', function ($event)46 $dispatcher->addListener(Events::onCoreException, function ($event) 46 47 { 47 $event->setProcessed(); 48 49 return new Response($event->get('exception')->getMessage()); 48 $event->setResponse(new Response($event->getException()->getMessage())); 50 49 }); 51 50 … … 58 57 { 59 58 $dispatcher = new EventDispatcher(); 60 $dispatcher-> connect('core.request', function ($event)59 $dispatcher->addListener(Events::onCoreRequest, function ($event) 61 60 { 62 $event->setProcessed(); 63 64 return new Response('hello'); 61 $event->setResponse(new Response('hello')); 65 62 }); 66 63 … … 93 90 94 91 /** 95 * @expectedException RuntimeException92 * @expectedException LogicException 96 93 */ 97 94 public function testHandleWhenControllerDoesNotReturnAResponse() … … 106 103 { 107 104 $dispatcher = new EventDispatcher(); 108 $dispatcher-> connect('core.view', function ($event)105 $dispatcher->addListener(Events::onCoreView, function ($event) 109 106 { 110 $event->setProcessed(); 111 112 return new Response($event->get('controller_value')); 107 $event->setResponse(new Response($event->getControllerResult())); 113 108 }); 114 109 $kernel = new HttpKernel($dispatcher, $this->getResolver(function () { return 'foo'; })); … … 117 112 } 118 113 119 /**120 * @expectedException RuntimeException121 */122 public function testHandleWhenAViewDoesNotReturnAResponse()123 {124 $dispatcher = new EventDispatcher();125 $dispatcher->connect('core.view', function ($event)126 {127 $event->setProcessed();128 129 return $event->get('controller_value');130 });131 $kernel = new HttpKernel($dispatcher, $this->getResolver(function () { return 'foo'; }));132 133 $kernel->handle(new Request());134 }135 136 /**137 * @expectedException RuntimeException138 */139 public function testHandleWhenAResponseListenerDoesNotReturnAResponse()140 {141 $dispatcher = new EventDispatcher();142 $dispatcher->connect('core.response', function ($event, $response)143 {144 return 'foo';145 });146 $kernel = new HttpKernel($dispatcher, $this->getResolver());147 148 $kernel->handle(new Request());149 }150 151 114 public function testHandleWithAResponseListener() 152 115 { 153 116 $dispatcher = new EventDispatcher(); 154 $dispatcher-> connect('core.response', function ($event, $response)117 $dispatcher->addListener(Events::onCoreResponse, function ($event) 155 118 { 156 return new Response('foo');119 $event->setResponse(new Response('foo')); 157 120 }); 158 121 $kernel = new HttpKernel($dispatcher, $this->getResolver()); branches/2.0/tests/Symfony/Tests/Component/HttpKernel/ResponseListenerTest.php
r32184 r32299 13 13 14 14 use Symfony\Component\HttpKernel\ResponseListener; 15 use Symfony\Component\EventDispatcher\EventDispatcher;16 use Symfony\Component\EventDispatcher\Event;17 15 use Symfony\Component\HttpFoundation\Request; 18 16 use Symfony\Component\HttpFoundation\Response; 19 17 use Symfony\Component\HttpKernel\HttpKernelInterface; 18 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 19 use Symfony\Component\HttpKernel\Events; 20 use Symfony\Component\EventDispatcher\EventDispatcher; 20 21 21 22 class ResponseListenerTest extends \PHPUnit_Framework_TestCase 22 23 { 24 private $dispatcher; 25 26 private $kernel; 27 28 protected function setUp() 29 { 30 $this->dispatcher = new EventDispatcher(); 31 $listener = new ResponseListener('UTF-8'); 32 $this->dispatcher->addListener(Events::onCoreResponse, $listener); 33 34 $this->kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); 35 36 } 23 37 public function testFilterDoesNothingForSubRequests() 24 38 { 25 $event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::SUB_REQUEST)); 26 $this->getDispatcher()->filter($event, $response = new Response('foo')); 39 $response = new Response('foo'); 27 40 28 $this->assertEquals('', $response->headers->get('content-type')); 41 $event = new FilterResponseEvent($this->kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response); 42 $this->dispatcher->dispatch(Events::onCoreResponse, $event); 43 44 $this->assertEquals('', $event->getResponse()->headers->get('content-type')); 29 45 } 30 46 31 47 public function testFilterDoesNothingIfContentTypeIsSet() 32 48 { 33 $event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST));34 49 $response = new Response('foo'); 35 50 $response->headers->set('Content-Type', 'text/plain'); 36 $this->getDispatcher()->filter($event, $response);37 51 38 $this->assertEquals('text/plain', $response->headers->get('content-type')); 52 $event = new FilterResponseEvent($this->kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response); 53 $this->dispatcher->dispatch(Events::onCoreResponse, $event); 54 55 $this->assertEquals('text/plain', $event->getResponse()->headers->get('content-type')); 39 56 } 40 57 41 58 public function testFilterDoesNothingIfRequestFormatIsNotDefined() 42 59 { 43 $event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST, 'request' => Request::create('/'))); 44 $this->getDispatcher()->filter($event, $response = new Response('foo')); 60 $response = new Response('foo'); 45 61 46 $this->assertEquals('', $response->headers->get('content-type')); 62 $event = new FilterResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response); 63 $this->dispatcher->dispatch(Events::onCoreResponse, $event); 64 65 $this->assertEquals('', $event->getResponse()->headers->get('content-type')); 47 66 } 48 67 49 68 public function testFilterSetContentType() 50 69 { 70 $response = new Response('foo'); 51 71 $request = Request::create('/'); 52 72 $request->setRequestFormat('json'); 53 $event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST, 'request' => $request));54 $this->getDispatcher()->filter($event, $response = new Response('foo'));55 73 56 $ this->assertEquals('application/json', $response->headers->get('content-type'));57 }74 $event = new FilterResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response); 75 $this->dispatcher->dispatch(Events::onCoreResponse, $event); 58 76 59 protected function getDispatcher() 60 { 61 $dispatcher = new EventDispatcher(); 62 $listener = new ResponseListener('UTF-8'); 63 $dispatcher->connect('core.response', array($listener, 'filter')); 64 65 return $dispatcher; 77 $this->assertEquals('application/json', $event->getResponse()->headers->get('content-type')); 66 78 } 67 79 } branches/2.0/tests/Symfony/Tests/Component/HttpKernel/TestHttpKernel.php
r32184 r32299 15 15 use Symfony\Component\HttpFoundation\Request; 16 16 use Symfony\Component\HttpFoundation\Response; 17 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; 17 18 use Symfony\Component\EventDispatcher\EventDispatcher; 18 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;19 19 20 20 class TestHttpKernel extends HttpKernel implements ControllerResolverInterface branches/2.0/tests/Symfony/Tests/Component/Security/Http/Firewall/RememberMeListenerTest.php
r32227 r32299 4 4 5 5 use Symfony\Component\HttpKernel\HttpKernelInterface; 6 use Symfony\Component\HttpKernel\Events; 6 7 use Symfony\Component\HttpFoundation\Response; 7 8 use Symfony\Component\Security\Core\Exception\CookieTheftException; … … 12 13 class RememberMeListenerTest extends \PHPUnit_Framework_TestCase 13 14 { 14 public function test CheckCookiesDoesNotTryToPopulateNonEmptySecurityContext()15 public function testOnCoreSecurityDoesNotTryToPopulateNonEmptySecurityContext() 15 16 { 16 17 list($listener, $context, $service,,) = $this->getListener(); … … 27 28 ; 28 29 29 $this->assertNull($listener->handle($this->get Event()));30 $this->assertNull($listener->handle($this->getGetResponseEvent())); 30 31 } 31 32 32 public function test CheckCookiesDoesNothingWhenNoCookieIsSet()33 public function testOnCoreSecurityDoesNothingWhenNoCookieIsSet() 33 34 { 34 35 list($listener, $context, $service,,) = $this->getListener(); … … 46 47 ; 47 48 48 $event = $this->get Event();49 $event = $this->getGetResponseEvent(); 49 50 $event 50 51 ->expects($this->once()) 51 ->method('get') 52 ->with('request') 52 ->method('getRequest') 53 53 ->will($this->returnValue(new Request())) 54 54 ; … … 57 57 } 58 58 59 public function test CheckCookiesIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation()59 public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation() 60 60 { 61 61 list($listener, $context, $service, $manager,) = $this->getListener(); … … 85 85 ; 86 86 87 $event = $this->get Event();87 $event = $this->getGetResponseEvent(); 88 88 $event 89 89 ->expects($this->once()) 90 ->method('get') 91 ->with('request') 90 ->method('getRequest') 92 91 ->will($this->returnValue(new Request())) 93 92 ; … … 96 95 } 97 96 98 public function test CheckCookies()97 public function testOnCoreSecurity() 99 98 { 100 99 list($listener, $context, $service, $manager,) = $this->getListener(); … … 125 124 ; 126 125 127 $event = $this->get Event();126 $event = $this->getGetResponseEvent(); 128 127 $event 129 128 ->expects($this->once()) 130 ->method('get') 131 ->with('request') 129 ->method('getRequest') 132 130 ->will($this->returnValue(new Request())) 133 131 ; … … 136 134 } 137 135 138 protected function get Event()136 protected function getGetResponseEvent() 139 137 { 140 return $this->getMock('Symfony\Component\EventDispatcher\Event', array(), array(), '', false); 138 return $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false); 139 } 140 141 protected function getFilterResponseEvent() 142 { 143 return $this->getMock('Symfony\Component\HttpKernel\Event\FilterResponseEvent', array(), array(), '', false); 141 144 } 142 145