[+FEATURE] introduce signal in MVC/Dispatcher
authorFelix Oertel <f@oer.tel>
Sat, 9 Jul 2011 13:09:47 +0000 (15:09 +0200)
committerFelix Oertel <f@oer.tel>
Sun, 17 Jul 2011 16:00:10 +0000 (18:00 +0200)
Introuce signal dispatched after a request has been dispatched.

Change-Id: Ia274306265d59fa5d5e14e08777025813ea307a7

typo3/sysext/extbase/Classes/MVC/Dispatcher.php
typo3/sysext/extbase/Tests/Unit/MVC/DispatcherTest.php

index 2ad8e9a..5fdb2b4 100644 (file)
@@ -43,6 +43,11 @@ class Tx_Extbase_MVC_Dispatcher implements t3lib_Singleton {
        protected $reflectionService;
 
        /**
+        * @var Tx_Extbase_SignalSlot_Dispatcher
+        */
+       protected $signalSlotDispatcher;
+
+       /**
         * @var array
         */
        protected $settings = array();
@@ -67,6 +72,15 @@ class Tx_Extbase_MVC_Dispatcher implements t3lib_Singleton {
        }
 
        /**
+        * Injects the SignalSlotDispatcher Service
+        *
+        * @param Tx_Extbase_SignalSlot_Dispatcher $signalSlotDispatcher
+        */
+       public function injectSignalSlotDispatcher(Tx_Extbase_SignalSlot_Dispatcher $signalSlotDispatcher) {
+               $this->signalSlotDispatcher = $signalSlotDispatcher;
+       }
+
+       /**
         * Dispatches a request to a controller and initializes the security framework.
         *
         * @param Tx_Extbase_MVC_RequestInterface $request The request to dispatch
@@ -83,6 +97,7 @@ class Tx_Extbase_MVC_Dispatcher implements t3lib_Singleton {
                        } catch (Tx_Extbase_MVC_Exception_StopAction $ignoredException) {
                        }
                }
+               $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterRequestDispatch', array($request, $response));
        }
 
        /**
index fa790d2..46d1582 100644 (file)
@@ -42,8 +42,10 @@ class Tx_Extbase_Tests_Unit_MVC_DispatcherTest extends Tx_Extbase_Tests_Unit_Bas
 
                $mockController = $this->getMock('Tx_Extbase_MVC_Controller_ControllerInterface', array('processRequest', 'canProcessRequest'));
                $mockController->expects($this->exactly(2))->method('processRequest')->with($mockRequest, $mockResponse);
+               $mockSignalSlotDispatcher = $this->getMock('Tx_Extbase_SignalSlot_Dispatcher', array('dispatch'));
 
                $dispatcher = $this->getMock('Tx_Extbase_MVC_Dispatcher', array('resolveController'), array(), '', FALSE);
+               $dispatcher->injectSignalSlotDispatcher($mockSignalSlotDispatcher);
                $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($mockController));
                $dispatcher->dispatch($mockRequest, $mockResponse);
        }
@@ -64,11 +66,30 @@ class Tx_Extbase_Tests_Unit_MVC_DispatcherTest extends Tx_Extbase_Tests_Unit_Bas
 
                $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface');
                $mockController = $this->getMock('Tx_Extbase_MVC_Controller_ControllerInterface', array('processRequest', 'canProcessRequest'));
+               $mockSignalSlotDispatcher = $this->getMock('Tx_Extbase_SignalSlot_Dispatcher', array('dispatch'));
 
                $dispatcher = $this->getMock('Tx_Extbase_MVC_Dispatcher', array('resolveController'), array(), '', FALSE);
+               $dispatcher->injectSignalSlotDispatcher($mockSignalSlotDispatcher);
                $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($mockController));
                $dispatcher->dispatch($mockRequest, $mockResponse);
        }
 
+       /**
+        * @test
+        */
+       public function dispatchDispatchesSignalAfterDispatchOfRequest() {
+
+               $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface');
+               $mockRequest->expects($this->at(0))->method('isDispatched')->will($this->returnValue(TRUE));
+
+               $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface');
+
+               $mockSignalSlotDispatcher = $this->getMock('Tx_Extbase_SignalSlot_Dispatcher', array('dispatch'));
+               $mockSignalSlotDispatcher->expects($this->exactly(1))->method('dispatch')->with('Tx_Extbase_MVC_Dispatcher', 'afterRequestDispatch', array($mockRequest, $mockResponse));
+
+               $dispatcher = $this->getMock('Tx_Extbase_MVC_Dispatcher', array('resolveController'), array(), '', FALSE);
+               $dispatcher->injectSignalSlotDispatcher($mockSignalSlotDispatcher);
+               $dispatcher->dispatch($mockRequest, $mockResponse);
+       }
 }
 ?>
\ No newline at end of file