Development

Changeset 32299

You must first sign up to be able to contribute.

Changeset 32299

Show
Ignore:
Timestamp:
03/18/11 08:00:09 (2 years ago)
Author:
fabien
Message:

Merge branch 'master' of git://github.com/symfony/symfony

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.0/src/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php

    r32202 r32299  
    1515use Assetic\Factory\LazyAssetManager; 
    1616use Symfony\Bundle\FrameworkBundle\Command\Command; 
     17use Symfony\Bundle\AsseticBundle\Event\WriteEvent; 
     18use Symfony\Bundle\AsseticBundle\Events; 
    1719use Symfony\Component\Console\Input\InputArgument; 
    1820use Symfony\Component\Console\Input\InputInterface; 
    1921use Symfony\Component\Console\Input\InputOption; 
    2022use Symfony\Component\Console\Output\OutputInterface; 
    21 use Symfony\Component\EventDispatcher\Event; 
    2223 
    2324/** 
     
    4748 
    4849        // 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); 
    5052 
    5153        if ($input->getOption('watch')) { 
  • branches/2.0/src/Symfony/Bundle/DoctrineBundle/ConnectionFactory.php

    r32184 r32299  
    3737    /** 
    3838     * Create a connection by name. 
    39      *  
     39     * 
    4040     * @param  string $connectionName 
    4141     * @return Doctrine\DBAL\Connection 
  • branches/2.0/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php

    r31836 r32299  
    3333 
    3434        foreach ($subscribers as $id => $instances) { 
    35             $definition->addMethodCall('addEventSubscriber', array(new Reference($id))); 
     35            $definition->addMethodCall('addSubscriber', array(new Reference($id))); 
    3636        } 
    3737    } 
     
    5353 
    5454            if (0 < count($events)) { 
    55                 $definition->addMethodCall('addEventListener', array( 
     55                $definition->addMethodCall('addListener', array( 
    5656                    $events, 
    5757                    new Reference($listenerId), 
  • branches/2.0/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/InfoDoctrineODMCommand.php

    r32254 r32299  
    44 * This file is part of the Symfony package. 
    55 * 
    6  * (c) Fabien Potencier <fabien.potencier@symfony-project.com> 
     6 * (c) Fabien Potencier <fabien@symfony.com> 
    77 * 
    88 * For the full copyright and license information, please view the LICENSE 
  • branches/2.0/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php

    r31841 r32299  
    3030 
    3131        foreach ($subscribers as $id => $instances) { 
    32             $definition->addMethodCall('addEventSubscriber', array(new Reference($id))); 
     32            $definition->addMethodCall('addSubscriber', array(new Reference($id))); 
    3333        } 
    3434    } 
     
    5050 
    5151            if (0 < count($events)) { 
    52                 $definition->addMethodCall('addEventListener', array( 
     52                $definition->addMethodCall('addListener', array( 
    5353                    $events, 
    5454                    new Reference($listenerId), 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterKernelListenersPass.php

    r32184 r32299  
    2525 
    2626        $listeners = array(); 
     27        $definition = $container->getDefinition('event_dispatcher'); 
     28 
    2729        foreach ($container->findTaggedServiceIds('kernel.listener') as $id => $events) { 
    2830            foreach ($events as $event) { 
    2931                $priority = isset($event['priority']) ? $event['priority'] : 0; 
     32 
    3033                if (!isset($event['event'])) { 
    3134                    throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "kernel.listener" tags.', $id)); 
    3235                } 
    33                 if (!isset($event['method'])) { 
    34                     throw new \InvalidArgumentException(sprintf('Service "%s" must define the "method" attribute on "kernel.listener" tags.', $id)); 
    35                 } 
    3636 
    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)); 
    4538            } 
    4639        } 
    47  
    48         $container 
    49             ->getDefinition('event_dispatcher') 
    50             ->addMethodCall('registerKernelListeners', array($listeners)) 
    51         ; 
    5240    } 
    5341} 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

    r32287 r32299  
    141141            'Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver', 
    142142            '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', 
    143155 
    144156            'Symfony\\Bundle\\FrameworkBundle\\RequestListener', 
     
    146158            'Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerResolver', 
    147159            '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', 
    154161        )); 
    155162    } 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/HttpFoundation/SessionListener.php

    r32184 r32299  
    1212namespace Symfony\Bundle\FrameworkBundle\HttpFoundation; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventInterface; 
    1514use Symfony\Component\HttpFoundation\Request; 
    1615use Symfony\Component\HttpFoundation\Response; 
    1716use Symfony\Component\HttpKernel\HttpKernelInterface; 
     17use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 
    1818 
    1919/** 
     
    2828    /** 
    2929     * Checks if session was initialized and saves if current request is master 
    30      * Runs on 'core.response' in test environment 
     30     * Runs on 'onCoreResponse' in test environment 
    3131     * 
    32      * @param EventInterface $event 
    33      * @param Response $response 
    34      * 
    35      * @return Response 
     32     * @param FilterResponseEvent $event 
    3633     */ 
    37     public function filter(EventInterface $event, Response $response
     34    public function onCoreResponse(FilterResponseEvent $event
    3835    { 
    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()) { 
    4138                if ($session = $request->getSession()) { 
    4239                    $session->save(); 
     
    4441            } 
    4542        } 
    46  
    47         return $response; 
    4843    } 
    4944} 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php

    r32076 r32299  
    1717class HttpKernel extends BaseHttpKernel 
    1818{ 
    19     protected $container; 
    20     protected $esiSupport; 
     19    private $container; 
     20    private $esiSupport; 
    2121 
    22     public function __construct(ContainerInterface $container, ControllerResolverInterface $controllerResolver) 
     22    public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver) 
    2323    { 
     24        parent::__construct($dispatcher, $controllerResolver); 
     25 
    2426        $this->container = $container; 
    25         $this->resolver = $controllerResolver; 
    26     } 
    27  
    28     public function setEventDispatcher(EventDispatcherInterface $dispatcher) 
    29     { 
    30         $this->dispatcher = $dispatcher; 
    3127    } 
    3228 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php

    r32288 r32299  
    1212namespace Symfony\Bundle\FrameworkBundle\Profiler; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventInterface; 
    1514use Symfony\Component\HttpFoundation\Response; 
    1615use Symfony\Component\HttpKernel\HttpKernelInterface; 
     16use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
     17use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 
     18use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 
    1719use Symfony\Component\HttpFoundation\RequestMatcherInterface; 
    1820use Symfony\Component\DependencyInjection\ContainerInterface; 
    1921 
    2022/** 
    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. 
    2524 * 
    2625 * @author Fabien Potencier <fabien@symfony.com> 
     
    4847 
    4948    /** 
    50      * Handles the core.request event 
     49     * Handles the onCoreRequest event 
    5150     * 
    5251     * This method initialize the profiler to be able to get it as a scoped 
    53      * service when handleResponse() will collect the sub request 
     52     * service when onCoreResponse() will collect the sub request 
    5453     * 
    55      * @param EventInterface $event An EventInterface instance 
     54     * @param GetResponseEvent $event A GetResponseEvent instance 
    5655     */ 
    57     public function handleRequest(EventInterface $event) 
     56    public function onCoreRequest(GetResponseEvent $event) 
    5857    { 
    5958        $this->container->get('profiler'); 
     
    6160 
    6261    /** 
    63      * Handles the core.exception event. 
     62     * Handles the onCoreException event. 
    6463     * 
    65      * @param EventInterface $event An EventInterface instance 
     64     * @param GetResponseForExceptionEvent $event A GetResponseForExceptionEvent instance 
    6665     */ 
    67     public function handleException(EventInterface $event) 
     66    public function onCoreException(GetResponseForExceptionEvent $event) 
    6867    { 
    69         if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) { 
    70             return false
     68        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { 
     69            return
    7170        } 
    7271 
    73         $this->exception = $event->get('exception'); 
    74  
    75         return false; 
     72        $this->exception = $event->getException(); 
    7673    } 
    7774 
    7875    /** 
    79      * Handles the core.response event. 
     76     * Handles the onCoreResponse event. 
    8077     * 
    81      * @param EventInterface $event An EventInterface instance 
    82      * 
    83      * @return Response $response A Response instance 
     78     * @param FilterResponseEvent $event A FilterResponseEvent instance 
    8479     */ 
    85     public function handleResponse(EventInterface $event, Response $response
     80    public function onCoreResponse(FilterResponseEvent $event
    8681    { 
    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())) { 
    8885            return $response; 
    8986        } 
    9087 
    9188        if ($this->onlyException && null === $this->exception) { 
    92             return $response
     89            return
    9390        } 
    9491 
     
    9996        } 
    10097 
    101         $profiler->collect($event->get('request'), $response, $this->exception); 
     98        $profiler->collect($event->getRequest(), $event->getResponse(), $this->exception); 
    10299        $this->exception = null; 
    103  
    104         return $response; 
    105100    } 
    106101} 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/RequestListener.php

    r32184 r32299  
    1414use Symfony\Component\HttpKernel\Log\LoggerInterface; 
    1515use Symfony\Component\HttpKernel\HttpKernelInterface; 
     16use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
    1617use Symfony\Component\HttpFoundation\Request; 
    17 use Symfony\Component\EventDispatcher\EventInterface; 
    1818use Symfony\Component\Routing\RouterInterface; 
    1919use Symfony\Component\DependencyInjection\ContainerInterface; 
     
    2121/** 
    2222 * RequestListener. 
    23  * 
    24  * The handle method must be connected to the core.request event. 
    2523 * 
    2624 * @author Fabien Potencier <fabien@symfony.com> 
     
    3937    } 
    4038 
    41     public function handle(EventInterface $event) 
     39    public function onCoreRequest(GetResponseEvent $event) 
    4240    { 
    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(); 
    4543 
    4644        $this->initializeSession($request, $master); 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml

    r32184 r32299  
    66 
    77    <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> 
    99    </parameters> 
    1010 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/esi.xml

    r32184 r32299  
    1414 
    1515        <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" /> 
    1717          <argument type="service" id="esi" on-invalid="ignore" /> 
    1818        </service> 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml

    r32288 r32299  
    2424 
    2525        <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" /> 
    2929            <argument type="service" id="service_container" /> 
    3030            <argument type="service" id="profiler.request_matcher" on-invalid="null" /> 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

    r32184 r32299  
    66 
    77    <parameters> 
    8         <parameter key="event_dispatcher.class">Symfony\Bundle\FrameworkBundle\EventDispatcher</parameter> 
     8        <parameter key="event_dispatcher.class">Symfony\Bundle\FrameworkBundle\ContainerAwareEventDispatcher</parameter> 
    99        <parameter key="http_kernel.class">Symfony\Bundle\FrameworkBundle\HttpKernel</parameter> 
    1010        <parameter key="error_handler.class">Symfony\Component\HttpKernel\Debug\ErrorHandler</parameter> 
     
    2626 
    2727        <service id="http_kernel" class="%http_kernel.class%"> 
     28            <argument type="service" id="event_dispatcher" /> 
    2829            <argument type="service" id="service_container" /> 
    2930            <argument type="service" id="controller_resolver" /> 
    30             <call method="setEventDispatcher"><argument type="service" id="event_dispatcher" /></call> 
    3131        </service> 
    3232 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml

    r32184 r32299  
    2626 
    2727        <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" /> 
    2929        </service> 
    3030    </services> 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml

    r32184 r32299  
    2727 
    2828        <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" /> 
    3030            <argument type="service" id="service_container" /> 
    3131            <argument type="service" id="router" /> 
     
    3434 
    3535        <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" /> 
    3737            <argument>%kernel.charset%</argument> 
    3838        </service> 
    3939 
    4040        <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" /> 
    4242            <argument>%exception_listener.controller%</argument> 
    4343            <argument type="service" id="logger" on-invalid="null" /> 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Tests/HttpFoundation/SessionListenerTest.php

    r32184 r32299  
    1313 
    1414use Symfony\Bundle\FrameworkBundle\HttpFoundation\SessionListener; 
    15 use Symfony\Component\EventDispatcher\Event; 
    1615use Symfony\Component\HttpFoundation\Response; 
    1716use Symfony\Component\HttpFoundation\Request; 
    1817use Symfony\Component\HttpKernel\HttpKernelInterface; 
     18use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 
    1919 
    2020/** 
     
    5454        $request->setSession($this->session); 
    5555        $response = new Response(); 
     56        $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); 
     57        $event = new FilterResponseEvent($kernel, $request, $type, $response); 
    5658 
    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()); 
    6062    } 
    6163 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Tests/HttpKernelTest.php

    r31885 r32299  
    66use Symfony\Component\HttpFoundation\Response; 
    77use Symfony\Component\HttpFoundation\Request; 
    8 use Symfony\Component\EventDispatcher\EventDispatcher; 
    98use Symfony\Component\DependencyInjection\ContainerBuilder; 
    109use Symfony\Bundle\FrameworkBundle\HttpKernel; 
     10use Symfony\Component\EventDispatcher\EventDispatcher; 
    1111 
    1212class HttpKernelTest extends \PHPUnit_Framework_TestCase 
     
    3939        $dispatcher = new EventDispatcher(); 
    4040        $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); 
    4342 
    4443        $controller = function() use($expected) 
     
    8887        $dispatcher = new EventDispatcher(); 
    8988        $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); 
    9290 
    9391        $controller = function() use ($expected) 
  • branches/2.0/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml

    r32259 r32299  
    107107        <!-- Firewall related services --> 
    108108        <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" /> 
    110110            <argument type="service" id="security.firewall.map" /> 
    111111            <argument type="service" id="event_dispatcher" /> 
  • branches/2.0/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml

    r32264 r32299  
    5252         
    5353        <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"/> 
    5555        </service> 
    5656    </services> 
  • branches/2.0/src/Symfony/Bundle/SecurityBundle/ResponseListener.php

    r32227 r32299  
    44 
    55use Symfony\Component\HttpFoundation\Response; 
    6 use Symfony\Component\EventDispatcher\EventInterface
     6use Symfony\Component\HttpKernel\Event\FilterResponseEvent
    77use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; 
    88 
     
    1414class ResponseListener 
    1515{ 
    16     public function handle(EventInterface $event, Response $response
     16    public function onCoreResponse(FilterResponseEvent $event
    1717    { 
    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)); 
    2123        } 
    22  
    23         $response->headers->setCookie($request->attributes->get(RememberMeServicesInterface::COOKIE_ATTR_NAME)); 
    24  
    25         return $response; 
    2624    } 
    2725} 
  • branches/2.0/src/Symfony/Bundle/WebProfilerBundle/Resources/config/toolbar.xml

    r32184 r32299  
    1212    <services> 
    1313        <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" /> 
    1515            <argument type="service" id="http_kernel" /> 
    1616            <argument type="service" id="templating.engine.twig" /> 
  • branches/2.0/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig

    r32268 r32299  
    1313    <table> 
    1414        <tr> 
     15            <th>Class</th> 
    1516            <th>Event</th> 
    16             <th>Caller</th> 
    17             <th>Listener</th> 
    1817        </tr> 
    1918        {% for elements in collector.calledlisteners %} 
    2019            <tr> 
     20                <td><code>{{ elements.class|abbr_class }}</code></td> 
    2121                <td><code>{{ elements.event }}</code></td> 
    22                 <td><code>{{ elements.caller|abbr_class }}</code></td> 
    23                 <td><code>{{ elements.listener|abbr_method }}</code></td> 
    2422            </tr> 
    2523        {% endfor %} 
     
    3634            {% for elements in collector.notcalledlisteners %} 
    3735                <tr> 
     36                    <td><code>{{ elements.class|abbr_class }}</code></td> 
    3837                    <td><code>{{ elements.event }}</code></td> 
    39                     <td><code>{{ elements.listener|abbr_method }}</code></td> 
    4038                </tr> 
    4139            {% endfor %} 
  • branches/2.0/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php

    r32236 r32299  
    1212namespace Symfony\Bundle\WebProfilerBundle; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventInterface; 
    1514use Symfony\Component\HttpFoundation\Request; 
    1615use Symfony\Component\HttpFoundation\Response; 
    1716use Symfony\Bundle\FrameworkBundle\HttpKernel; 
    1817use Symfony\Component\HttpKernel\HttpKernelInterface; 
     18use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 
    1919use Symfony\Bundle\TwigBundle\TwigEngine; 
    2020 
     
    2222 * WebDebugToolbarListener injects the Web Debug Toolbar. 
    2323 * 
    24  * The handle method must be connected to the core.response event. 
     24 * The handle method must be connected to the onCoreResponse event. 
    2525 * 
    2626 * The WDT is only injected on well-formed HTML (with a proper </body> tag). 
     
    4242    } 
    4343 
    44     public function handle(EventInterface $event, Response $response
     44    public function onCoreResponse(FilterResponseEvent $event
    4545    { 
    46         if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) { 
    47             return $response
     46        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { 
     47            return
    4848        } 
    4949 
    50         $request = $event->get('request'); 
     50        $response = $event->getResponse(); 
     51  $request = $event->getRequest(); 
     52 
    5153        if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) { 
    5254            // keep current flashes for one more request 
     
    6769            || $request->isXmlHttpRequest() 
    6870        ) { 
    69             return $response
     71            return
    7072        } 
    7173 
    7274        $this->injectToolbar($response); 
    73  
    74         return $response; 
    7575    } 
    7676 
  • branches/2.0/src/Symfony/Component/EventDispatcher/Event.php

    r32184 r32299  
    22 
    33/* 
    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. 
    515 * 
    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>. 
    1019 */ 
    1120 
     
    1322 
    1423/** 
    15  * Event
     24 * Event is the base class for classes containing event data
    1625 * 
    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> 
    1840 */ 
    19 class Event implements EventInterface 
     41class Event 
    2042{ 
    21     protected $processed = false; 
    22     protected $subject; 
    23     protected $name; 
    24     protected $parameters
     43    /** 
     44    * @var Boolean Whether no further event listeners should be triggered 
     45    */ 
     46    private $propagationStopped = false
    2547 
    2648    /** 
    27      * Constructs a new Event
     49     * Returns whether further event listeners should be triggered
    2850     * 
    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. 
    3253     */ 
    33     public function __construct($subject, $name, $parameters = array()
     54    public function isPropagationStopped(
    3455    { 
    35         $this->subject = $subject; 
    36         $this->name = $name; 
    37         $this->parameters = $parameters; 
     56        return $this->propagationStopped; 
    3857    } 
    3958 
    4059    /** 
    41      * Returns the subject
     60     * Stops the propagation of the event to further event listeners
    4261     * 
    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(). 
    4465     */ 
    45     public function getSubject() 
     66    public function stopPropagation() 
    4667    { 
    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; 
    13569    } 
    13670} 
  • branches/2.0/src/Symfony/Component/EventDispatcher/EventDispatcher.php

    r32184 r32299  
    22 
    33/* 
    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. 
    515 * 
    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 
     21namespace Symfony\Component\EventDispatcher; 
     22 
     23/** 
     24 * The EventDispatcherInterface is the central point of Symfony's event listener system. 
    725 * 
    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. 
    1628 * 
    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> 
    1837 */ 
    1938class EventDispatcher implements EventDispatcherInterface 
    2039{ 
    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; 
    6783                } 
    6884            } 
     
    7187 
    7288    /** 
    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        } 
    146203    } 
    147204} 
  • branches/2.0/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php

    r32184 r32299  
    1313 
    1414/** 
    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. 
    1618 * 
    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> 
    2020 */ 
    2121interface EventDispatcherInterface 
    2222{ 
    2323    /** 
    24      * Connects a listener to a given event name
     24     * Dispatches an event to all registered listeners
    2525     * 
    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) 
     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. 
    3131     */ 
    32     function connect($name, $listener, $priority = 0); 
     32    function dispatch($eventName, Event $event = null); 
    3333 
    3434    /** 
    35      * Disconnects one, or all listeners for the given event name
     35     * Adds an event listener that listens on the specified events
    3636     * 
    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. 
    4142     */ 
    42     function disconnect($name, $listener = null); 
     43    function addListener($eventNames, $listener, $priority = 0); 
    4344 
    4445    /** 
    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. 
    4648     * 
    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. 
    4853     */ 
    49     function notify(EventInterface $event); 
     54    function addSubscriber(EventSubscriberInterface $subscriber, $priority = 0); 
    5055 
    5156    /** 
    52      * Notifies all listeners of a given event until one processes the event
     57     * Removes an event listener from the specified events
    5358     * 
    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. 
    6261     */ 
    63     function notifyUntil(EventInterface $event); 
     62    function removeListener($eventNames, $listener); 
    6463 
    6564    /** 
    66      * Filters a value by calling all listeners of a given event
     65     * Gets the listeners of a specific event or all listeners
    6766     * 
    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. 
    7068     * 
    71      * @return mixed The filtered value 
     69     * @return array The event listeners for the specified event, or all event 
     70     *               listeners by event name. 
    7271     */ 
    73     function filter(EventInterface $event, $value); 
     72    function getListeners($eventName = null); 
    7473 
    7574    /** 
    76      * Returns true if the given event name has some listeners. 
     75     * Checks whether an event has any registered listeners. 
    7776     * 
    78      * @param string $name The event name 
     77     * @param string $eventName The name of the event. 
    7978     * 
    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. 
    8181     */ 
    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); 
    9283} 
  • branches/2.0/src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php

    r32184 r32299  
    1212namespace Symfony\Component\HttpKernel\DataCollector; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    1514use Symfony\Component\HttpFoundation\Request; 
    1615use Symfony\Component\HttpFoundation\Response; 
    17 use Symfony\Component\HttpKernel\Debug\EventDispatcherTraceableInterface; 
     16use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcherInterface; 
     17use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    1818 
    1919/** 
     
    2828    public function setEventDispatcher(EventDispatcherInterface $dispatcher) 
    2929    { 
    30         if ($dispatcher instanceof EventDispatcherTraceableInterface) { 
     30        if ($dispatcher instanceof TraceableEventDispatcherInterface) { 
    3131            $this->dispatcher = $dispatcher; 
    3232        } 
     
    4949     * @return array An array of called listeners 
    5050     * 
    51      * @see EventDispatcherTraceableInterface 
     51     * @see TraceableEventDispatcherInterface 
    5252     */ 
    5353    public function getCalledListeners() 
     
    6161     * @return array An array of not called listeners 
    6262     * 
    63      * @see EventDispatcherTraceableInterface 
     63     * @see TraceableEventDispatcherInterface 
    6464     */ 
    6565    public function getNotCalledListeners() 
  • branches/2.0/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

    r32184 r32299  
    4949     * @return array An array of called events 
    5050     * 
    51      * @see EventDispatcherTraceableInterface 
     51     * @see TraceableEventDispatcherInterface 
    5252     */ 
    5353    public function countErrors() 
  • branches/2.0/src/Symfony/Component/HttpKernel/Debug/ExceptionListener.php

    r32184 r32299  
    1212namespace Symfony\Component\HttpKernel\Debug; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventInterface; 
    1514use Symfony\Component\HttpKernel\Log\LoggerInterface; 
    1615use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; 
     16use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 
    1717use Symfony\Component\HttpKernel\HttpKernelInterface; 
    1818use Symfony\Component\HttpKernel\Exception\FlattenException; 
     
    2121/** 
    2222 * ExceptionListener. 
    23  * 
    24  * The handle method must be connected to the core.exception event. 
    2523 * 
    2624 * @author Fabien Potencier <fabien@symfony.com> 
     
    3735    } 
    3836 
    39     public function handle(EventInterface $event) 
     37    public function onCoreException(GetResponseForExceptionEvent $event) 
    4038    { 
    4139        static $handling; 
     
    4745        $handling = true; 
    4846 
    49         $exception = $event->get('exception'); 
    50         $request = $event->get('request'); 
     47        $exception = $event->getException(); 
     48        $request = $event->getRequest(); 
    5149 
    5250        if (null !== $this->logger) { 
     
    6967 
    7068        try { 
    71             $response = $event->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true); 
     69            $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true); 
    7270        } catch (\Exception $e) { 
    7371            $message = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()); 
     
    8078            // set handling to false otherwise it wont be able to handle further more 
    8179            $handling = false; 
    82              
     80 
    8381            // re-throw the exception as this is a catch-all 
    8482            throw $exception; 
    8583        } 
    8684 
    87         $event->setProcessed(); 
     85        $event->setResponse($response); 
    8886 
    8987        $handling = false; 
    90  
    91         return $response; 
    9288    } 
    9389} 
  • branches/2.0/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcherInterface.php

    r32184 r32299  
    1515 * @author Fabien Potencier <fabien@symfony.com> 
    1616 */ 
    17 interface EventDispatcherTraceableInterface 
     17interface TraceableEventDispatcherInterface 
    1818{ 
    1919    /** 
  • branches/2.0/src/Symfony/Component/HttpKernel/HttpCache/EsiListener.php

    r32184 r32299  
    1414use Symfony\Component\HttpFoundation\Response; 
    1515use Symfony\Component\HttpKernel\HttpKernelInterface; 
    16 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    17 use Symfony\Component\EventDispatcher\EventInterface; 
     16use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 
    1817 
    1918/** 
    2019 * 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. 
    2320 * 
    2421 * @author Fabien Potencier <fabien@symfony.com> 
     
    2623class EsiListener 
    2724{ 
    28     protected $dispatcher
     25    protected $i
    2926    protected $esi; 
    3027 
     
    4239     * Filters the Response. 
    4340     * 
    44      * @param EventInterface $event    An EventInterface instance 
    45      * @param Response       $response A Response instance 
     41     * @param FilterResponseEvent $event  A FilterResponseEvent instance 
    4642     */ 
    47     public function filter(EventInterface $event, Response $response
     43    public function onCoreResponse(FilterResponseEvent $event
    4844    { 
    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
    5147        } 
    5248 
    53         $this->esi->addSurrogateControl($response); 
    54  
    55         return $response; 
     49        $this->esi->addSurrogateControl($event->getResponse()); 
    5650    } 
    5751} 
  • branches/2.0/src/Symfony/Component/HttpKernel/HttpKernel.php

    r32292 r32299  
    1212namespace Symfony\Component\HttpKernel; 
    1313 
    14 use Symfony\Component\EventDispatcher\Event; 
    15 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    1614use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; 
    1715use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; 
     16use Symfony\Component\HttpKernel\Event\FilterControllerEvent; 
     17use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 
     18use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
     19use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; 
     20use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 
    1821use Symfony\Component\HttpFoundation\Request; 
    1922use Symfony\Component\HttpFoundation\Response; 
     23use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    2024 
    2125/** 
     
    2630class HttpKernel implements HttpKernelInterface 
    2731{ 
    28     protected $dispatcher; 
    29     protected $resolver; 
     32    private $dispatcher; 
     33    private $resolver; 
    3034 
    3135    /** 
    3236     * Constructor 
    3337     * 
    34      * @param EventDispatcherInterface    $dispatcher An EventDispatcherInterface instance 
     38     * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance 
    3539     * @param ControllerResolverInterface $resolver A ControllerResolverInterface instance 
    3640     */ 
     
    8589    { 
    8690        // 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); 
    9196        } 
    9297 
     
    96101        } 
    97102 
    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(); 
    105106 
    106107        // controller arguments 
     
    112113        // view 
    113114        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))); 
    118124            } 
    119125        } 
    120126 
    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); 
    122128    } 
    123129 
     
    133139     * @throws \RuntimeException if the passed object is not a Response instance 
    134140     */ 
    135     protected function filterResponse($response, $request, $message, $type) 
     141    protected function filterResponse(Response $response, Request $request, $type) 
    136142    { 
    137         if (!$response instanceof Response) { 
    138             throw new \RuntimeException($message); 
    139         } 
     143        $event = new FilterResponseEvent($this, $request, $type, $response); 
    140144 
    141         $response = $this->dispatcher->filter(new Event($this, 'core.response', array('request_type' => $type, 'request' => $request)), $response); 
     145        $this->dispatcher->dispatch(Events::onCoreResponse, $event); 
    142146 
    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(); 
    148148    } 
    149149 
     
    159159    protected function handleException(\Exception $e, $request, $type) 
    160160    { 
    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()) { 
    164165            throw $e; 
    165166        } 
    166167 
    167         return $this->filterResponse($response, $request, 'A "core.exception" listener returned a non response object.', $type); 
     168        return $this->filterResponse($event->getResponse(), $request, $type); 
    168169    } 
    169170 
  • branches/2.0/src/Symfony/Component/HttpKernel/ResponseListener.php

    r32184 r32299  
    1212namespace Symfony\Component\HttpKernel; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventInterface
     14use Symfony\Component\HttpKernel\Event\FilterResponseEvent
    1515use Symfony\Component\HttpFoundation\Response; 
    1616 
    1717/** 
    1818 * ResponseListener fixes the Response Content-Type. 
    19  * 
    20  * The filter method must be connected to the core.response event. 
    2119 * 
    2220 * @author Fabien Potencier <fabien@symfony.com> 
     
    3432     * Filters the Response. 
    3533     * 
    36      * @param EventInterface $event    An EventInterface instance 
    37      * @param Response       $response A Response instance 
     34     * @param FilterResponseEvent $event    A FilterResponseEvent instance 
    3835     */ 
    39     public function filter(EventInterface $event, Response $response
     36    public function onCoreResponse(FilterResponseEvent $event
    4037    { 
    41         if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) { 
    42             return $response
     38        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { 
     39            return
    4340        } 
     41 
     42        $response = $event->getResponse(); 
    4443 
    4544        if (null === $response->getCharset()) { 
     
    4847 
    4948        if ($response->headers->has('Content-Type')) { 
    50             return $response
     49            return
    5150        } 
    5251 
    53         $request = $event->get('request'); 
     52        $request = $event->getRequest(); 
    5453        $format = $request->getRequestFormat(); 
    5554        if ((null !== $format) && $mimeType = $request->getMimeType($format)) { 
    5655            $response->headers->set('Content-Type', $mimeType); 
    5756        } 
    58  
    59         return $response; 
    6057    } 
    6158} 
  • branches/2.0/src/Symfony/Component/Security/Http/Authentication/AuthenticationFailureHandlerInterface.php

    r32076 r32299  
    33namespace Symfony\Component\Security\Http\Authentication; 
    44 
     5use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
    56use Symfony\Component\Security\Core\Exception\AuthenticationException; 
    6 use Symfony\Component\EventDispatcher\EventInterface; 
    77use Symfony\Component\HttpFoundation\Request; 
    88 
     
    2323     * AbstractAuthenticationListener. 
    2424     * 
    25      * @param EventInterface          $event the "core.security" event, this event always 
     25     * @param GetResponseEvent    $event the "onCoreRequest" event, this event always 
    2626     *                                       has the kernel as target 
    2727     * @param Request                 $request 
     
    3030     * @return Response the response to return 
    3131     */ 
    32     function onAuthenticationFailure(EventInterface $event, Request $request, AuthenticationException $exception); 
     32    function onAuthenticationFailure(GetResponseEvent $event, Request $request, AuthenticationException $exception); 
    3333} 
  • branches/2.0/src/Symfony/Component/Security/Http/Authentication/AuthenticationSuccessHandlerInterface.php

    r31979 r32299  
    33namespace Symfony\Component\Security\Http\Authentication; 
    44 
    5 use Symfony\Component\EventDispatcher\EventInterface
     5use Symfony\Component\HttpKernel\Event\GetResponseEvent
    66use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 
    77use Symfony\Component\HttpFoundation\Request; 
     
    2323     * AbstractAuthenticationListener. 
    2424     * 
    25      * @param EventInterface $event the "core.security" event, this event always 
     25     * @param GetResponseEvent $event the "onCoreRequest" event, this event always 
    2626     *                              has the kernel as target 
    2727     * @param Request        $request 
     
    3030     * @return Response the response to return 
    3131     */ 
    32     function onAuthenticationSuccess(EventInterface $event, Request $request, TokenInterface $token); 
     32    function onAuthenticationSuccess(GetResponseEvent $event, Request $request, TokenInterface $token); 
    3333} 
  • branches/2.0/src/Symfony/Component/Security/Http/Authorization/AccessDeniedHandlerInterface.php

    r31979 r32299  
    44 
    55use Symfony\Component\HttpFoundation\Request; 
    6 use Symfony\Component\EventDispatcher\EventInterface
     6use Symfony\Component\HttpKernel\Event\ExceptionEvent
    77use Symfony\Component\Security\Core\Exception\AccessDeniedException; 
     8use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 
    89 
    910/** 
     
    1819     * Handles an access denied failure. 
    1920     * 
    20      * @param EventInterface        $event 
    21      * @param Request               $request 
    22      * @param AccessDeniedException $accessDeniedException 
     21     * @param GetResponseForExceptionEvent $event 
     22     * @param Request                      $request 
     23     * @param AccessDeniedException        $accessDeniedException 
    2324     * 
    2425     * @return Response may return null 
    2526     */ 
    26     function handle(EventInterface $event, Request $request, AccessDeniedException $accessDeniedException); 
     27    function handle(GetResponseForExceptionEvent $event, Request $request, AccessDeniedException $accessDeniedException); 
    2728} 
  • branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/AuthenticationEntryPointInterface.php

    r32184 r32299  
    1212namespace Symfony\Component\Security\Http\EntryPoint; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventInterface
     14use Symfony\Component\HttpKernel\Event\GetResponseEvent
    1515use Symfony\Component\Security\Core\Exception\AuthenticationException; 
    1616use Symfony\Component\HttpFoundation\Request; 
     
    2727     * Starts the authentication scheme. 
    2828     * 
    29      * @param EventInterface          $event         The "core.security" event 
     29     * @param GetResponseEvent        $event     The "onCoreRequest" event 
    3030     * @param object                  $request       The request that resulted in an AuthenticationException 
    3131     * @param AuthenticationException $authException The exception that started the authentication process 
    3232     */ 
    33     function start(EventInterface $event, Request $request, AuthenticationException $authException = null); 
     33    function start(GetResponseEvent $event, Request $request, AuthenticationException $authException = null); 
    3434} 
  • branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/BasicAuthenticationEntryPoint.php

    r32220 r32299  
    1212namespace Symfony\Component\Security\Http\EntryPoint; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventInterface; 
    1514use Symfony\Component\Security\Core\Exception\AuthenticationException; 
    1615use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; 
    1716use Symfony\Component\HttpFoundation\Response; 
    1817use Symfony\Component\HttpFoundation\Request; 
     18use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
    1919 
    2020/** 
     
    3232    } 
    3333 
    34     public function start(EventInterface $event, Request $request, AuthenticationException $authException = null) 
     34    public function start(GetResponseEvent $event, Request $request, AuthenticationException $authException = null) 
    3535    { 
    3636        $response = new Response(); 
  • branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/DigestAuthenticationEntryPoint.php

    r32220 r32299  
    1212namespace Symfony\Component\Security\Http\EntryPoint; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventInterface; 
    1514use Symfony\Component\Security\Core\Exception\AuthenticationException; 
    1615use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; 
     
    1918use Symfony\Component\HttpFoundation\Request; 
    2019use Symfony\Component\HttpKernel\Log\LoggerInterface; 
     20use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
    2121 
    2222/** 
     
    4040    } 
    4141 
    42     public function start(EventInterface $event, Request $request, AuthenticationException $authException = null) 
     42    public function start(GetResponseEvent $event, Request $request, AuthenticationException $authException = null) 
    4343    { 
    4444        $expiryTime = microtime(true) + $this->nonceValiditySeconds * 1000; 
  • branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/FormAuthenticationEntryPoint.php

    r32220 r32299  
    1212namespace Symfony\Component\Security\Http\EntryPoint; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventInterface; 
    1514use Symfony\Component\HttpFoundation\Request; 
    1615use Symfony\Component\HttpFoundation\Response; 
     
    1918use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; 
    2019use Symfony\Component\HttpKernel\HttpKernelInterface; 
     20use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
    2121 
    2222/** 
     
    4545     * {@inheritdoc} 
    4646     */ 
    47     public function start(EventInterface $event, Request $request, AuthenticationException $authException = null) 
     47    public function start(GetResponseEvent $event, Request $request, AuthenticationException $authException = null) 
    4848    { 
    4949        if ($this->useForward) { 
    50             return $event->getSubject()->handle(Request::create($this->loginPath), HttpKernelInterface::SUB_REQUEST); 
     50            return $event->getKernel()->handle(Request::create($this->loginPath), HttpKernelInterface::SUB_REQUEST); 
    5151        } 
    5252 
  • branches/2.0/src/Symfony/Component/Security/Http/EntryPoint/RetryAuthenticationEntryPoint.php

    r32220 r32299  
    1212namespace Symfony\Component\Security\Http\EntryPoint; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventInterface; 
    1514use Symfony\Component\Security\Core\Exception\AuthenticationException; 
    1615use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; 
     
    1817use Symfony\Component\HttpFoundation\RedirectResponse; 
    1918use Symfony\Component\HttpFoundation\Request; 
     19use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
    2020 
    2121/** 
     
    3737    } 
    3838 
    39     public function start(EventInterface $event, Request $request, AuthenticationException $authException = null) 
     39    public function start(GetResponseEvent $event, Request $request, AuthenticationException $authException = null) 
    4040    { 
    4141        $scheme = $request->isSecure() ? 'http' : 'https'; 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall.php

    r32227 r32299  
    1212namespace Symfony\Component\Security\Http; 
    1313 
     14use Symfony\Component\HttpKernel\HttpKernelInterface; 
     15use Symfony\Component\HttpKernel\Events; 
     16use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
     17use Symfony\Component\HttpFoundation\Request; 
    1418use 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; 
    1919 
    2020/** 
     
    2626 * everything else for instance). 
    2727 * 
    28  * The handle method must be connected to the core.request event. 
    29  * 
    3028 * @author Fabien Potencier <fabien@symfony.com> 
    3129 */ 
     
    3331{ 
    3432    private $map; 
     33    private $dispatcher; 
     34    private $currentListeners; 
    3535 
    3636    /** 
     
    4343        $this->map = $map; 
    4444        $this->dispatcher = $dispatcher; 
     45        $this->currentListeners = array(); 
    4546    } 
    4647 
     
    4849     * Handles security. 
    4950     * 
    50      * @param EventInterface $event An EventInterface instance 
     51     * @param GetResponseEvent $event An GetResponseEvent instance 
    5152     */ 
    52     public function handle(EventInterface $event) 
     53    public function onCoreRequest(GetResponseEvent $event) 
    5354    { 
    54         if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) { 
     55        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { 
    5556            return; 
    5657        } 
    5758 
    5859        // register listeners for this firewall 
    59         list($listeners, $exception) = $this->map->getListeners($event->get('request')); 
     60        list($listeners, $exception) = $this->map->getListeners($event->getRequest()); 
    6061        if (null !== $exception) { 
    6162            $exception->register($this->dispatcher); 
     
    6667            $response = $listener->handle($event); 
    6768 
    68             if ($event->isProcessed()) { 
    69                 return $response
     69            if ($event->hasResponse()) { 
     70                break
    7071            } 
    7172        } 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php

    r32253 r32299  
    1212namespace Symfony\Component\Security\Http\Firewall; 
    1313 
    14 use Symfony\Component\EventDispatcher\Event; 
    1514use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface; 
    1615use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface; 
     
    1918use Symfony\Component\Security\Core\SecurityContextInterface; 
    2019use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; 
     20use Symfony\Component\Security\Core\Exception\AuthenticationException; 
    2121use 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
     22use Symfony\Component\HttpKernel\HttpKernelInterface; 
     23use Symfony\Component\HttpKernel\Events as KernelEvents
     24use Symfony\Component\HttpKernel\Event\GetResponseEvent
    2525use Symfony\Component\HttpFoundation\Request; 
    26 use Symfony\Component\HttpKernel\HttpKernelInterface; 
    2726use Symfony\Component\HttpFoundation\Response; 
    2827use Symfony\Component\HttpFoundation\RedirectResponse; 
    2928use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 
     29use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
     30use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; 
     31use Symfony\Component\Security\Http\Events; 
    3032 
    3133/** 
     
    5456    private $securityContext; 
    5557    private $sessionStrategy; 
    56     private $eventDispatcher; 
     58    private $dispatcher; 
    5759    private $successHandler; 
    5860    private $failureHandler; 
     
    6769     * @param LoggerInterface                $logger                A LoggerInterface instance 
    6870     */ 
    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) 
    7072    { 
    7173        if (empty($providerKey)) { 
     
    9092        ), $options); 
    9193        $this->logger = $logger; 
    92         $this->eventDispatcher = $eventDispatcher; 
     94        $this->dispatcher = $dispatcher; 
    9395    } 
    9496 
     
    106108     * Handles form based authentication. 
    107109     * 
    108      * @param Event $event An Event instance 
    109      */ 
    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(); 
    113115 
    114116        if (!$this->requiresAuthentication($request)) { 
     
    130132                throw new \RuntimeException('attemptAuthentication() must either return a Response, an implementation of TokenInterface, or null.'); 
    131133            } 
    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); 
    139139    } 
    140140 
     
    166166    abstract protected function attemptAuthentication(Request $request); 
    167167 
    168     private function onFailure($event, Request $request, AuthenticationException $failed) 
     168    private function onFailure(GetResponseEvent $event, Request $request, AuthenticationException $failed) 
    169169    { 
    170170        if (null !== $this->logger) { 
     
    202202    } 
    203203 
    204     private function onSuccess(EventInterface $event, Request $request, TokenInterface $token) 
     204    private function onSuccess(GetResponseEvent $event, Request $request, TokenInterface $token) 
    205205    { 
    206206        if (null !== $this->logger) { 
     
    214214        $session->remove(SecurityContextInterface::LAST_USERNAME); 
    215215 
    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); 
    218219        } 
    219220 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php

    r32253 r32299  
    1212namespace Symfony\Component\Security\Http\Firewall; 
    1313 
    14 use Symfony\Component\EventDispatcher\Event; 
    1514use Symfony\Component\Security\Core\SecurityContextInterface; 
    1615use 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; 
    2016use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken; 
    2117use Symfony\Component\Security\Core\Exception\AuthenticationException; 
     18use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; 
     19use Symfony\Component\Security\Http\Events; 
     20use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
     21use Symfony\Component\HttpKernel\Events as KernelEvents; 
     22use Symfony\Component\HttpKernel\Log\LoggerInterface; 
    2223use Symfony\Component\HttpFoundation\Request; 
     24use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    2325 
    2426/** 
     
    3537    private $authenticationManager; 
    3638    private $providerKey; 
    37     private $eventDispatcher; 
     39    private $dispatcher; 
    3840 
    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) 
    4042    { 
    4143        $this->securityContext = $securityContext; 
     
    4345        $this->providerKey = $providerKey; 
    4446        $this->logger = $logger; 
    45         $this->eventDispatcher = $eventDispatcher; 
     47        $this->dispatcher = $dispatcher; 
    4648    } 
    4749 
     
    4951     * Handles X509 authentication. 
    5052     * 
    51      * @param EventInterface $event An EventInterface instance 
     53     * @param GetResponseEvent $event A GetResponseEvent instance 
    5254     */ 
    53     public final function handle(EventInterface $event) 
     55    public final function handle(GetResponseEvent $event) 
    5456    { 
    55         $request = $event->get('request'); 
     57        $request = $event->getRequest(); 
    5658 
    5759        if (null !== $this->logger) { 
     
    7981            $this->securityContext->setToken($token); 
    8082 
    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); 
    8386            } 
    8487        } catch (AuthenticationException $failed) { 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/AccessListener.php

    r32227 r32299  
    1717use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; 
    1818use Symfony\Component\HttpKernel\Log\LoggerInterface; 
    19 use Symfony\Component\EventDispatcher\EventDispatcherInterface
    20 use Symfony\Component\EventDispatcher\EventInterface
     19use Symfony\Component\HttpKernel\Event\GetResponseEvent
     20use Symfony\Component\HttpKernel\Events
    2121use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException; 
    2222use Symfony\Component\Security\Core\Exception\AccessDeniedException; 
     
    4747     * Handles access authorization. 
    4848     * 
    49      * @param EventInterface $event An EventInterface instance 
     49     * @param GetResponseEvent $event A GetResponseEvent instance 
    5050     */ 
    51     public function handle(EventInterface $event) 
     51    public function handle(GetResponseEvent $event) 
    5252    { 
    5353        if (null === $token = $this->context->getToken()) { 
     
    5555        } 
    5656 
    57         $request = $event->get('request'); 
     57        $request = $event->getRequest(); 
    5858 
    5959        list($attributes, $channel) = $this->map->getPatterns($request); 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php

    r32227 r32299  
    1414use Symfony\Component\Security\Core\SecurityContextInterface; 
    1515use Symfony\Component\HttpKernel\Log\LoggerInterface; 
    16 use Symfony\Component\EventDispatcher\EventDispatcherInterface
    17 use Symfony\Component\EventDispatcher\EventInterface
     16use Symfony\Component\HttpKernel\Event\GetResponseEvent
     17use Symfony\Component\HttpKernel\Events
    1818use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; 
    1919 
     
    4040     * Handles anonymous authentication. 
    4141     * 
    42      * @param EventInterface $event An EventInterface instance 
     42     * @param GetResponseEvent $event A GetResponseEvent instance 
    4343     */ 
    44     public function handle(EventInterface $event) 
     44    public function handle(GetResponseEvent $event) 
    4545    { 
    4646        if (null !== $this->context->getToken()) { 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php

    r32227 r32299  
    1616use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; 
    1717use Symfony\Component\HttpKernel\Log\LoggerInterface; 
    18 use Symfony\Component\EventDispatcher\EventDispatcherInterface
    19 use Symfony\Component\EventDispatcher\EventInterface
     18use Symfony\Component\HttpKernel\Event\GetResponseEvent
     19use Symfony\Component\HttpKernel\Events
    2020use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; 
    2121use Symfony\Component\Security\Core\Exception\AuthenticationException; 
     
    5252     * Handles basic authentication. 
    5353     * 
    54      * @param EventInterface $event An EventInterface instance 
     54     * @param GetResponseEvent $event A GetResponseEvent instance 
    5555     */ 
    56     public function handle(EventInterface $event) 
     56    public function handle(GetResponseEvent $event) 
    5757    { 
    58         $request = $event->get('request'); 
     58        $request = $event->getRequest(); 
    5959 
    6060        if (false === $username = $request->server->get('PHP_AUTH_USER', false)) { 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php

    r32227 r32299  
    1515use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; 
    1616use Symfony\Component\HttpKernel\Log\LoggerInterface; 
    17 use Symfony\Component\EventDispatcher\EventDispatcherInterface
    18 use Symfony\Component\EventDispatcher\EventInterface
     17use Symfony\Component\HttpKernel\Event\GetResponseEvent
     18use Symfony\Component\HttpKernel\Events
    1919 
    2020/** 
     
    4040     * Handles channel management. 
    4141     * 
    42      * @param EventInterface $event An EventInterface instance 
     42     * @param GetResponseEvent $event A GetResponseEvent instance 
    4343     */ 
    44     public function handle(EventInterface $event) 
     44    public function handle(GetResponseEvent $event) 
    4545    { 
    46         $request = $event->get('request'); 
     46        $request = $event->getRequest(); 
    4747 
    4848        list($attributes, $channel) = $this->map->getPatterns($request); 
     
    5353            } 
    5454 
    55             $event->setProcessed(); 
     55            $response = $this->authenticationEntryPoint->start($event, $request); 
    5656 
    57             return $this->authenticationEntryPoint->start($event, $request); 
     57            $event->setResponse($response); 
     58 
     59            return; 
    5860        } 
    5961 
     
    6365            } 
    6466 
    65             $event->setProcessed(); 
     67            $response = $this->authenticationEntryPoint->start($event, $request); 
    6668 
    67             return $this->authenticationEntryPoint->start($event, $request); 
     69            $event->setResponse($response); 
    6870        } 
    6971    } 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/ContextListener.php

    r32227 r32299  
    1212namespace Symfony\Component\Security\Http\Firewall; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventInterface; 
    15 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    1614use Symfony\Component\HttpFoundation\Response; 
    1715use Symfony\Component\HttpKernel\HttpKernelInterface; 
    1816use Symfony\Component\HttpKernel\Log\LoggerInterface; 
     17use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
     18use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 
     19use Symfony\Component\HttpKernel\Events; 
    1920use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; 
    2021use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 
     
    2324use Symfony\Component\Security\Core\SecurityContext; 
    2425use Symfony\Component\Security\Core\User\UserInterface; 
     26use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    2527 
    2628/** 
     
    3739    private $userProviders; 
    3840 
    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) 
    4042    { 
    4143        if (empty($contextKey)) { 
     
    4749        $this->contextKey = $contextKey; 
    4850 
    49         if (null !== $eventDispatcher) { 
    50             $eventDispatcher->connect('core.response', array($this, 'write'), 0); 
     51        if (null !== $dispatcher) { 
     52            $dispatcher->addListener(Events::onCoreResponse, $this); 
    5153        } 
    5254    } 
     
    5557     * Reads the SecurityContext from the session. 
    5658     * 
    57      * @param EventInterface $event An EventInterface instance 
     59     * @param GetResponseEvent $event A GetResponseEvent instance 
    5860     */ 
    59     public function handle(EventInterface $event) 
     61    public function handle(GetResponseEvent $event) 
    6062    { 
    61         $request = $event->get('request'); 
     63        $request = $event->getRequest(); 
    6264 
    6365        $session = $request->hasSession() ? $request->getSession() : null; 
     
    8385     * Writes the SecurityContext to the session. 
    8486     * 
    85      * @param EventInterface $event An EventInterface instance 
     87     * @param FilterResponseEvent $event A FilterResponseEvent instance 
    8688     */ 
    87     public function write(EventInterface $event, Response $response
     89    public function onCoreResponse(FilterResponseEvent $event
    8890    { 
    89         if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) { 
    90             return $response
     91        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { 
     92            return
    9193        } 
    9294 
    9395        if (null === $token = $this->context->getToken()) { 
    94             return $response
     96            return
    9597        } 
    9698 
    9799        if (null === $token || $token instanceof AnonymousToken) { 
    98             return $response
     100            return
    99101        } 
    100102 
     
    103105        } 
    104106 
    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)); 
    108108    } 
    109109 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php

    r32227 r32299  
    1616use Symfony\Component\Security\Http\EntryPoint\DigestAuthenticationEntryPoint; 
    1717use Symfony\Component\HttpKernel\Log\LoggerInterface; 
    18 use Symfony\Component\EventDispatcher\EventDispatcherInterface
    19 use Symfony\Component\EventDispatcher\EventInterface
     18use Symfony\Component\HttpKernel\Event\GetResponseEvent
     19use Symfony\Component\HttpKernel\Events
    2020use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; 
    2121use Symfony\Component\Security\Core\Exception\BadCredentialsException; 
     
    5555     * Handles digest authentication. 
    5656     * 
    57      * @param EventInterface $event An EventInterface instance 
     57     * @param GetResponseEvent $event A GetResponseEvent instance 
    5858     */ 
    59     public function handle(EventInterface $event) 
    60     { 
    61         $request = $event->get('request'); 
     59    public function handle(GetResponseEvent $event) 
     60    { 
     61        $request = $event->getRequest(); 
    6262 
    6363        if (!$header = $request->server->get('PHP_AUTH_DIGEST')) { 
     
    122122    } 
    123123 
    124     private function fail(EventInterface $event, Request $request, AuthenticationException $authException) 
     124    private function fail(GetResponseEvent $event, Request $request, AuthenticationException $authException) 
    125125    { 
    126126        $this->securityContext->setToken(null); 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php

    r32227 r32299  
    1818use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; 
    1919use Symfony\Component\HttpKernel\Log\LoggerInterface; 
    20 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    21 use Symfony\Component\EventDispatcher\EventInterface; 
    2220use Symfony\Component\Security\Core\Exception\AuthenticationException; 
    2321use Symfony\Component\Security\Core\Exception\AccessDeniedException; 
     
    2624use Symfony\Component\HttpFoundation\Request; 
    2725use Symfony\Component\HttpKernel\HttpKernelInterface; 
     26use Symfony\Component\HttpKernel\Events; 
     27use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 
     28use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    2829 
    2930/** 
     
    5354 
    5455    /** 
    55      * Registers a core.exception listener to take care of security exceptions. 
     56     * Registers a onCoreException listener to take care of security exceptions. 
    5657     * 
    5758     * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance 
    58      * @param integer                  $priority   The priority 
    5959     */ 
    6060    public function register(EventDispatcherInterface $dispatcher) 
    6161    { 
    62         $dispatcher->connect('core.exception', array($this, 'handleException'), 0); 
     62        $dispatcher->addListener(Events::onCoreException, $this); 
    6363    } 
    6464 
     
    6666     * Handles security related exceptions. 
    6767     * 
    68      * @param EventInterface $event An EventInterface instance 
     68     * @param GetResponseForExceptionEvent $event An GetResponseForExceptionEvent instance 
    6969     */ 
    70     public function handleException(EventInterface $event) 
     70    public function onCoreException(GetResponseForExceptionEvent $event) 
    7171    { 
    72         $exception = $event->get('exception'); 
    73         $request = $event->get('request'); 
     72        $exception = $event->getException(); 
     73        $request = $event->getRequest(); 
    7474 
    7575        if ($exception instanceof AuthenticationException) { 
     
    119119                        $subRequest->attributes->set(SecurityContextInterface::ACCESS_DENIED_ERROR, $exception); 
    120120 
    121                         $response = $event->getSubject()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true); 
     121                        $response = $event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true); 
    122122                        $response->setStatusCode(403); 
    123123                    } 
     
    127127                    } 
    128128 
    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)); 
    130130 
    131131                    return; 
     
    136136        } 
    137137 
    138         $event->setProcessed(); 
    139  
    140         return $response; 
     138        $event->setResponse($response); 
    141139    } 
    142140 
    143     private function startAuthentication(EventInterface $event, Request $request, AuthenticationException $authException) 
     141    private function startAuthentication(GetResponseForExceptionEvent $event, Request $request, AuthenticationException $authException) 
    144142    { 
    145143        $this->context->setToken(null); 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/ListenerInterface.php

    r32227 r32299  
    1212namespace Symfony\Component\Security\Http\Firewall; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventInterface; 
    15  
     14use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
    1615use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    1716 
     
    2625     * This interface must be implemented by firewall listeners. 
    2726     * 
    28      * @param EventInterface $dispatcher 
     27     * @param GetResponseEvent $event 
    2928     */ 
    30     function handle(EventInterface $event); 
     29    function handle(GetResponseEvent $event); 
    3130} 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/LogoutListener.php

    r32227 r32299  
    1616use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface; 
    1717use Symfony\Component\Security\Core\SecurityContextInterface; 
    18 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    19 use Symfony\Component\EventDispatcher\EventInterface; 
    2018use Symfony\Component\HttpFoundation\Response; 
    2119use Symfony\Component\HttpFoundation\RedirectResponse; 
     20use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
     21use Symfony\Component\HttpKernel\Events; 
    2222 
    2323/** 
     
    6464     * Performs the logout if requested 
    6565     * 
    66      * @param EventInterface $event An EventInterface instance 
     66     * @param GetResponseEvent $event A GetResponseEvent instance 
    6767     */ 
    68     public function handle(EventInterface $event) 
     68    public function handle(GetResponseEvent $event) 
    6969    { 
    70         $request = $event->get('request'); 
     70        $request = $event->getRequest(); 
    7171 
    7272        if ($this->logoutPath !== $request->getPathInfo()) { 
     
    9393        $this->securityContext->setToken(null); 
    9494 
    95         $event->setProcessed(); 
    96  
    97         return $response; 
     95        $event->setResponse($response); 
    9896    } 
    9997} 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php

    r32227 r32299  
    33namespace Symfony\Component\Security\Http\Firewall; 
    44 
    5 use Symfony\Component\EventDispatcher\Event; 
     5use Symfony\Component\HttpKernel\HttpKernelInterface; 
     6use Symfony\Component\HttpKernel\Log\LoggerInterface; 
     7use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
     8use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 
     9use Symfony\Component\HttpKernel\Events as KernelEvents; 
     10use Symfony\Component\HttpFoundation\Response; 
    611use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 
     12use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; 
    713use Symfony\Component\Security\Core\Exception\AuthenticationException; 
    814use 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; 
    1515use Symfony\Component\Security\Core\SecurityContext; 
    1616use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; 
     17use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; 
     18use Symfony\Component\Security\Http\Events; 
     19use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    1720 
    1821/* 
     
    3639    private $authenticationManager; 
    3740    private $logger; 
    38     private $eventDispatcher; 
     41    private $dispatcher; 
    3942 
    4043    /** 
     
    4649     * @param LoggerInterface $logger 
    4750     */ 
    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) 
    4952    { 
    5053        $this->securityContext = $securityContext; 
     
    5255        $this->authenticationManager = $authenticationManager; 
    5356        $this->logger = $logger; 
    54         $this->eventDispatcher = $eventDispatcher; 
     57        $this->dispatcher = $dispatcher; 
    5558    } 
    5659 
     
    5861     * Handles remember-me cookie based authentication. 
    5962     * 
    60      * @param Event $event An Event instance 
     63     * @param GetResponseEvent $event A GetResponseEvent instance 
    6164     */ 
    62     public function handle(EventInterface $event) 
     65    public function handle(GetResponseEvent $event) 
    6366    { 
    6467        if (null !== $this->securityContext->getToken()) { 
     
    6669        } 
    6770 
    68         $request = $event->get('request'); 
     71        $request = $event->getRequest(); 
    6972        if (null === $token = $this->rememberMeServices->autoLogin($request)) { 
    7073            return; 
     
    7578            $this->securityContext->setToken($token); 
    7679 
    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); 
    7983            } 
    8084 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php

    r32227 r32299  
    1212namespace Symfony\Component\Security\Http\Firewall; 
    1313 
    14 use Symfony\Component\EventDispatcher\Event; 
    1514use Symfony\Component\Security\Core\SecurityContextInterface; 
    1615use Symfony\Component\Security\Core\User\UserProviderInterface; 
     
    1817use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface; 
    1918use Symfony\Component\HttpKernel\Log\LoggerInterface; 
    20 use Symfony\Component\EventDispatcher\EventDispatcherInterface
    21 use Symfony\Component\EventDispatcher\EventInterface
     19use Symfony\Component\HttpKernel\Event\GetResponseEvent
     20use Symfony\Component\HttpKernel\Events
    2221use Symfony\Component\Security\Core\Exception\AuthenticationException; 
    2322use Symfony\Component\HttpFoundation\Response; 
     
    2827use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException; 
    2928use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 
     29use Symfony\Component\Security\Http\Event\SwitchUserEvent; 
     30use Symfony\Component\Security\Http\Events; 
     31use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    3032 
    3133/** 
     
    4547    private $role; 
    4648    private $logger; 
    47     private $eventDispatcher; 
     49    private $dispatcher; 
    4850 
    4951    /** 
    5052     * Constructor. 
    5153     */ 
    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) 
    5355    { 
    5456        if (empty($providerKey)) { 
     
    6466        $this->role = $role; 
    6567        $this->logger = $logger; 
    66         $this->eventDispatcher = $eventDispatcher; 
     68        $this->dispatcher = $dispatcher; 
    6769    } 
    6870 
     
    7072     * Handles digest authentication. 
    7173     * 
    72      * @param EventInterface $event An EventInterface instance 
     74     * @param GetResponseEvent $event A GetResponseEvent instance 
    7375     */ 
    74     public function handle(EventInterface $event) 
     76    public function handle(GetResponseEvent $event) 
    7577    { 
    76         $request = $event->get('request'); 
     78        $request = $event->getRequest(); 
    7779 
    7880        if (!$request->get($this->usernameParameter)) { 
     
    9597        $response = new RedirectResponse($request->getUri(), 302); 
    9698 
    97         $event->setProcessed(); 
    98  
    99         return $response; 
     99        $event->setResponse($response); 
    100100    } 
    101101 
     
    130130        $token = new UsernamePasswordToken($user, $user->getPassword(), $this->providerKey, $roles); 
    131131 
    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); 
    134135        } 
    135136 
     
    150151        } 
    151152 
    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); 
    154156        } 
    155157 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordFormAuthenticationListener.php

    r32227 r32299  
    1212namespace Symfony\Component\Security\Http\Firewall; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    15  
    1614use Symfony\Component\Form\CsrfProvider\CsrfProviderInterface; 
    1715use Symfony\Component\HttpFoundation\Request; 
     
    2422use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException; 
    2523use Symfony\Component\Security\Core\SecurityContextInterface; 
     24use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    2625 
    2726/** 
     
    3837     * {@inheritdoc} 
    3938     */ 
    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) 
    4140    { 
    4241        parent::__construct($securityContext, $authenticationManager, $sessionStrategy, $providerKey, array_merge(array( 
     
    4645            'csrf_page_id'       => 'form_login', 
    4746            'post_only'          => true, 
    48         ), $options), $successHandler, $failureHandler, $logger, $eventDispatcher); 
     47        ), $options), $successHandler, $failureHandler, $logger, $dispatcher); 
    4948 
    5049        $this->csrfProvider = $csrfProvider; 
  • branches/2.0/src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php

    r32253 r32299  
    1212namespace Symfony\Component\Security\Http\Firewall; 
    1313 
    14 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    1514use Symfony\Component\Security\Core\SecurityContextInterface; 
    1615use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; 
     
    1817use Symfony\Component\HttpFoundation\Request; 
    1918use Symfony\Component\Security\Core\Exception\BadCredentialsException; 
     19use Symfony\Component\EventDispatcher\EventDispatcherInterface; 
    2020 
    2121/** 
     
    2929    private $credentialKey; 
    3030 
    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) 
    3232    { 
    33         parent::__construct($securityContext, $authenticationManager, $providerKey, $logger, $eventDispatcher); 
     33        parent::__construct($securityContext, $authenticationManager, $providerKey, $logger, $dispatcher); 
    3434 
    3535        $this->userKey = $userKey; 
  • branches/2.0/src/Symfony/Component/Security/Http/Logout/LogoutSuccessHandlerInterface.php

    r32076 r32299  
    44 
    55use Symfony\Component\HttpFoundation\Request; 
    6 use Symfony\Component\EventDispatcher\EventInterface
     6use Symfony\Component\HttpKernel\Event\GetResponseEvent
    77 
    88/** 
     
    2222     * Creates a Response object to send upon a successful logout. 
    2323     * 
    24      * @param EventInterface $event 
     24     * @param GetResponseEvent $event 
    2525     * @param Request $request 
    2626     * @return Response never null 
    2727     */ 
    28     function onLogoutSuccess(EventInterface $event, Request $request); 
     28    function onLogoutSuccess(GetResponseEvent $event, Request $request); 
    2929} 
  • branches/2.0/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php

    r32184 r32299  
    1414use Symfony\Component\EventDispatcher\Event; 
    1515use Symfony\Component\EventDispatcher\EventDispatcher; 
     16use Symfony\Component\EventDispatcher\EventSubscriberInterface; 
    1617 
    1718class EventDispatcherTest extends \PHPUnit_Framework_TestCase 
    1819{ 
    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() 
    2031    { 
    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(); 
    3334    } 
    3435 
    35     public function testGetHasListeners() 
     36    public function testInitialState() 
    3637    { 
    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)); 
    4841    } 
    4942 
    50     public function testNotify() 
     43    public function testAddListener() 
    5144    { 
    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())); 
    6551    } 
    6652 
    67     public function testNotifyUntil() 
     53    public function testGetListenersSortsByPriority() 
    6854    { 
    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(); 
    7558 
    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')); 
    8270    } 
    8371 
    84     public function testFilter() 
     72    public function testGetAllListenersSortsByPriority() 
    8573    { 
    86         $listener = new Listener(); 
    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(); 
    9280 
    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)); 
    99170    } 
    100171} 
    101172 
    102 class Listener 
     173class TestEventListener 
    103174{ 
    104     protected 
    105         $value = ''
     175    public $preFooInvoked = false; 
     176    public $postFooInvoked = false
    106177 
    107     function filterFoo(Event $event, $foo) 
     178    /* Listener methods */ 
     179 
     180    public function preFoo(Event $e) 
    108181    { 
    109         return "*$foo*"
     182        $this->preFooInvoked = true
    110183    } 
    111184 
    112     function filterFooBis(Event $event, $foo
     185    public function postFoo(Event $e
    113186    { 
    114         return "-$foo-"; 
    115     } 
     187        $this->postFooInvoked = true; 
    116188 
    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(); 
    137190    } 
    138191} 
     192 
     193class 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  
    1616use Symfony\Component\HttpFoundation\Request; 
    1717use Symfony\Component\HttpFoundation\Response; 
    18 use Symfony\Component\EventDispatcher\EventDispatcher; 
    19 use Symfony\Component\EventDispatcher\Event; 
    2018 
    2119require_once __DIR__.'/TestHttpKernel.php'; 
  • branches/2.0/tests/Symfony/Tests/Component/HttpKernel/DataCollector/EventDataCollectorTest.php

    r32184 r32299  
    1515use Symfony\Component\HttpFoundation\Request; 
    1616use Symfony\Component\HttpFoundation\Response; 
    17 use Symfony\Component\HttpKernel\Debug\EventDispatcherTraceableInterface; 
     17use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcherInterface; 
    1818use Symfony\Component\EventDispatcher\EventDispatcher; 
    19  
    2019 
    2120class EventDataCollectorTest extends \PHPUnit_Framework_TestCase 
     
    2524        $c = new EventDataCollector(); 
    2625        $c->setEventDispatcher(new TestEventDispatcher()); 
    27          
     26 
    2827        $c->collect(new Request(), new Response()); 
    29          
     28 
    3029        $this->assertSame('events',$c->getName()); 
    3130        $this->assertSame(array('foo'),$c->getCalledListeners()); 
    3231        $this->assertSame(array('bar'),$c->getNotCalledListeners()); 
    3332    } 
    34      
     33 
    3534} 
    3635 
    37 class TestEventDispatcher extends EventDispatcher implements EventDispatcherTraceableInterface 
     36class TestEventDispatcher extends EventDispatcher implements TraceableEventDispatcherInterface 
    3837{ 
    3938    function getCalledListeners() 
  • branches/2.0/tests/Symfony/Tests/Component/HttpKernel/Debug/ExceptionListenerTest.php

    r32184 r32299  
    1212namespace Symfony\Tests\Component\HttpKernel\Debug; 
    1313 
     14use Symfony\Component\HttpKernel\HttpKernelInterface; 
    1415use Symfony\Component\HttpKernel\Debug\ExceptionListener; 
     16use Symfony\Component\HttpKernel\Debug\ErrorException; 
    1517use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; 
    16 use Symfony\Component\EventDispatcher\Event; 
     18use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 
    1719use Symfony\Component\HttpFoundation\Request; 
    18 use Symfony\Component\HttpKernel\Debug\ErrorException
     20use Symfony\Component\HttpFoundation\Response
    1921use Symfony\Tests\Component\HttpKernel\Logger; 
    2022 
     
    3032        $logger = new TestLogger(); 
    3133        $l = new ExceptionListener('foo', $logger); 
    32          
    33         $_logger = new \ReflectionProperty(get_class($l),'logger'); 
     34 
     35        $_logger = new \ReflectionProperty(get_class($l), 'logger'); 
    3436        $_logger->setAccessible(true); 
    35         $_controller = new \ReflectionProperty(get_class($l),'controller'); 
     37        $_controller = new \ReflectionProperty(get_class($l), 'controller'); 
    3638        $_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)); 
    4042    } 
    41      
     43 
    4244    /** 
    4345     * @dataProvider provider 
    4446     */ 
    45     public function testHandleWithoutLogger($event,$event2) 
     47    public function testHandleWithoutLogger($event, $event2) 
    4648    { 
    4749        //store the current error_log, and set the new one to dev/null 
    4850        $error_log = ini_get('error_log'); 
    49         ini_set('error_log','/dev/null'); 
    50          
     51        ini_set('error_log', '/dev/null'); 
     52 
    5153        $l = new ExceptionListener('foo'); 
     54        $l->onCoreException($event); 
    5255 
    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()); 
    5962        } 
    60          
     63 
    6164        //restore the old error_log 
    62         ini_set('error_log',$error_log); 
     65        ini_set('error_log', $error_log); 
    6366    } 
    64      
     67 
    6568    /** 
    6669     * @dataProvider provider 
     
    6972    { 
    7073        $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()); 
    8084        } 
    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'))); 
    8488    } 
    85      
     89 
    8690    public function provider() 
    8791    { 
    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); 
    9296 
    9397        return array( 
    94             array($event,$event2) 
     98            array($event, $event2) 
    9599        ); 
    96100    } 
    97      
     101 
    98102} 
    99103 
     
    104108        return count($this->logs['err']); 
    105109    } 
    106      
     110 
    107111    public function getDebugLogger() 
    108112    { 
     
    111115} 
    112116 
    113 class Subject 
     117class TestKernel implements HttpKernelInterface 
    114118{ 
    115     public function handle(
     119    public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true
    116120    { 
    117         return 'foo'
     121        return new Response('foo')
    118122    } 
    119   
     123 
    120124} 
    121125 
    122 class SubjectException 
     126class TestKernelThatThrowsException implements HttpKernelInterface 
    123127{ 
    124     public function handle(
     128    public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true
    125129    { 
    126130        throw new \Exception('bar'); 
  • branches/2.0/tests/Symfony/Tests/Component/HttpKernel/HttpCache/EsiListenerTest.php

    r32184 r32299  
    1414use Symfony\Component\HttpKernel\HttpCache\Esi; 
    1515use Symfony\Component\HttpKernel\HttpCache\EsiListener; 
     16use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 
     17use Symfony\Component\HttpKernel\Events; 
     18use Symfony\Component\HttpKernel\HttpKernelInterface; 
     19use Symfony\Component\HttpFoundation\Response; 
     20use Symfony\Component\HttpFoundation\Request; 
    1621use Symfony\Component\EventDispatcher\EventDispatcher; 
    17 use Symfony\Component\EventDispatcher\Event; 
    18 use Symfony\Component\HttpFoundation\Response; 
    19 use Symfony\Component\HttpKernel\HttpKernelInterface; 
    2022 
    2123class EsiListenerTest extends \PHPUnit_Framework_TestCase 
     
    2426    { 
    2527        $dispatcher = new EventDispatcher(); 
     28        $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); 
     29        $response = new Response('foo <esi:include src="" />'); 
    2630        $listener = new EsiListener(new Esi()); 
    27         $dispatcher->connect('core.response', array($listener, 'filter')); 
    2831 
    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); 
    3135 
    32         $this->assertEquals('', $response->headers->get('Surrogate-Control')); 
     36        $this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control')); 
    3337    } 
    3438 
     
    3640    { 
    3741        $dispatcher = new EventDispatcher(); 
     42        $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); 
     43        $response = new Response('foo <esi:include src="" />'); 
    3844        $listener = new EsiListener(new Esi()); 
    39         $dispatcher->connect('core.response', array($listener, 'filter')); 
    4045 
    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); 
    4349 
    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')); 
    4551    } 
    4652 
     
    4854    { 
    4955        $dispatcher = new EventDispatcher(); 
     56        $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); 
     57        $response = new Response('foo'); 
    5058        $listener = new EsiListener(new Esi()); 
    51         $dispatcher->connect('core.response', array($listener, 'filter')); 
    5259 
    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); 
    5563 
    56         $this->assertEquals('', $response->headers->get('Surrogate-Control')); 
     64        $this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control')); 
    5765    } 
    5866} 
  • branches/2.0/tests/Symfony/Tests/Component/HttpKernel/HttpCache/TestHttpKernel.php

    r32184 r32299  
    1616use Symfony\Component\HttpFoundation\Request; 
    1717use Symfony\Component\HttpFoundation\Response; 
     18use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; 
    1819use Symfony\Component\EventDispatcher\EventDispatcher; 
    19 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; 
    2020 
    2121class TestHttpKernel extends HttpKernel implements ControllerResolverInterface 
  • branches/2.0/tests/Symfony/Tests/Component/HttpKernel/HttpCache/TestMultipleHttpKernel.php

    r32184 r32299  
    1616use Symfony\Component\HttpFoundation\Request; 
    1717use Symfony\Component\HttpFoundation\Response; 
     18use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; 
    1819use Symfony\Component\EventDispatcher\EventDispatcher; 
    19 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; 
    2020 
    2121class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInterface 
  • branches/2.0/tests/Symfony/Tests/Component/HttpKernel/HttpKernelTest.php

    r32184 r32299  
    1414use Symfony\Component\HttpKernel\HttpKernel; 
    1515use Symfony\Component\HttpKernel\HttpKernelInterface; 
     16use Symfony\Component\HttpKernel\Events; 
    1617use Symfony\Component\HttpFoundation\Request; 
    1718use Symfony\Component\HttpFoundation\Response; 
     
    4344    { 
    4445        $dispatcher = new EventDispatcher(); 
    45         $dispatcher->connect('core.exception', function ($event) 
     46        $dispatcher->addListener(Events::onCoreException, function ($event) 
    4647        { 
    47             $event->setProcessed(); 
    48  
    49             return new Response($event->get('exception')->getMessage()); 
     48            $event->setResponse(new Response($event->getException()->getMessage())); 
    5049        }); 
    5150 
     
    5857    { 
    5958        $dispatcher = new EventDispatcher(); 
    60         $dispatcher->connect('core.request', function ($event) 
     59        $dispatcher->addListener(Events::onCoreRequest, function ($event) 
    6160        { 
    62             $event->setProcessed(); 
    63  
    64             return new Response('hello'); 
     61            $event->setResponse(new Response('hello')); 
    6562        }); 
    6663 
     
    9390 
    9491    /** 
    95      * @expectedException RuntimeException 
     92     * @expectedException LogicException 
    9693     */ 
    9794    public function testHandleWhenControllerDoesNotReturnAResponse() 
     
    106103    { 
    107104        $dispatcher = new EventDispatcher(); 
    108         $dispatcher->connect('core.view', function ($event) 
     105        $dispatcher->addListener(Events::onCoreView, function ($event) 
    109106        { 
    110             $event->setProcessed(); 
    111  
    112             return new Response($event->get('controller_value')); 
     107            $event->setResponse(new Response($event->getControllerResult())); 
    113108        }); 
    114109        $kernel = new HttpKernel($dispatcher, $this->getResolver(function () { return 'foo'; })); 
     
    117112    } 
    118113 
    119     /** 
    120      * @expectedException RuntimeException 
    121      */ 
    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 RuntimeException 
    138      */ 
    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  
    151114    public function testHandleWithAResponseListener() 
    152115    { 
    153116        $dispatcher = new EventDispatcher(); 
    154         $dispatcher->connect('core.response', function ($event, $response
     117        $dispatcher->addListener(Events::onCoreResponse, function ($event
    155118        { 
    156             return new Response('foo'); 
     119            $event->setResponse(new Response('foo')); 
    157120        }); 
    158121        $kernel = new HttpKernel($dispatcher, $this->getResolver()); 
  • branches/2.0/tests/Symfony/Tests/Component/HttpKernel/ResponseListenerTest.php

    r32184 r32299  
    1313 
    1414use Symfony\Component\HttpKernel\ResponseListener; 
    15 use Symfony\Component\EventDispatcher\EventDispatcher; 
    16 use Symfony\Component\EventDispatcher\Event; 
    1715use Symfony\Component\HttpFoundation\Request; 
    1816use Symfony\Component\HttpFoundation\Response; 
    1917use Symfony\Component\HttpKernel\HttpKernelInterface; 
     18use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 
     19use Symfony\Component\HttpKernel\Events; 
     20use Symfony\Component\EventDispatcher\EventDispatcher; 
    2021 
    2122class ResponseListenerTest extends \PHPUnit_Framework_TestCase 
    2223{ 
     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    } 
    2337    public function testFilterDoesNothingForSubRequests() 
    2438    { 
    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'); 
    2740 
    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')); 
    2945    } 
    3046 
    3147    public function testFilterDoesNothingIfContentTypeIsSet() 
    3248    { 
    33         $event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST)); 
    3449        $response = new Response('foo'); 
    3550        $response->headers->set('Content-Type', 'text/plain'); 
    36         $this->getDispatcher()->filter($event, $response); 
    3751 
    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')); 
    3956    } 
    4057 
    4158    public function testFilterDoesNothingIfRequestFormatIsNotDefined() 
    4259    { 
    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'); 
    4561 
    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')); 
    4766    } 
    4867 
    4968    public function testFilterSetContentType() 
    5069    { 
     70        $response = new Response('foo'); 
    5171        $request = Request::create('/'); 
    5272        $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')); 
    5573 
    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); 
    5876 
    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')); 
    6678    } 
    6779} 
  • branches/2.0/tests/Symfony/Tests/Component/HttpKernel/TestHttpKernel.php

    r32184 r32299  
    1515use Symfony\Component\HttpFoundation\Request; 
    1616use Symfony\Component\HttpFoundation\Response; 
     17use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; 
    1718use Symfony\Component\EventDispatcher\EventDispatcher; 
    18 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; 
    1919 
    2020class TestHttpKernel extends HttpKernel implements ControllerResolverInterface 
  • branches/2.0/tests/Symfony/Tests/Component/Security/Http/Firewall/RememberMeListenerTest.php

    r32227 r32299  
    44 
    55use Symfony\Component\HttpKernel\HttpKernelInterface; 
     6use Symfony\Component\HttpKernel\Events; 
    67use Symfony\Component\HttpFoundation\Response; 
    78use Symfony\Component\Security\Core\Exception\CookieTheftException; 
     
    1213class RememberMeListenerTest extends \PHPUnit_Framework_TestCase 
    1314{ 
    14     public function testCheckCookiesDoesNotTryToPopulateNonEmptySecurityContext() 
     15    public function testOnCoreSecurityDoesNotTryToPopulateNonEmptySecurityContext() 
    1516    { 
    1617        list($listener, $context, $service,,) = $this->getListener(); 
     
    2728        ; 
    2829 
    29         $this->assertNull($listener->handle($this->getEvent())); 
     30        $this->assertNull($listener->handle($this->getGetResponseEvent())); 
    3031    } 
    3132 
    32     public function testCheckCookiesDoesNothingWhenNoCookieIsSet() 
     33    public function testOnCoreSecurityDoesNothingWhenNoCookieIsSet() 
    3334    { 
    3435        list($listener, $context, $service,,) = $this->getListener(); 
     
    4647        ; 
    4748 
    48         $event = $this->getEvent(); 
     49        $event = $this->getGetResponseEvent(); 
    4950        $event 
    5051            ->expects($this->once()) 
    51             ->method('get') 
    52             ->with('request') 
     52            ->method('getRequest') 
    5353            ->will($this->returnValue(new Request())) 
    5454        ; 
     
    5757    } 
    5858 
    59     public function testCheckCookiesIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation() 
     59    public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation() 
    6060    { 
    6161        list($listener, $context, $service, $manager,) = $this->getListener(); 
     
    8585        ; 
    8686 
    87         $event = $this->getEvent(); 
     87        $event = $this->getGetResponseEvent(); 
    8888        $event 
    8989            ->expects($this->once()) 
    90             ->method('get') 
    91             ->with('request') 
     90            ->method('getRequest') 
    9291            ->will($this->returnValue(new Request())) 
    9392        ; 
     
    9695    } 
    9796 
    98     public function testCheckCookies() 
     97    public function testOnCoreSecurity() 
    9998    { 
    10099        list($listener, $context, $service, $manager,) = $this->getListener(); 
     
    125124        ; 
    126125 
    127         $event = $this->getEvent(); 
     126        $event = $this->getGetResponseEvent(); 
    128127        $event 
    129128            ->expects($this->once()) 
    130             ->method('get') 
    131             ->with('request') 
     129            ->method('getRequest') 
    132130            ->will($this->returnValue(new Request())) 
    133131        ; 
     
    136134    } 
    137135 
    138     protected function getEvent() 
     136    protected function getGetResponseEvent() 
    139137    { 
    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); 
    141144    } 
    142145