Changeset 419

Show
Ignore:
Timestamp:
03/23/07 17:07:45 (2 years ago)
Author:
mikey
Message:

net.stubbles.websites.stubFrontController now triggers an event with name onSessionCreated after the session instance was created with the session as context of the event

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/websites/stubFrontController.php

    r399 r419  
    77 * @subpackage  websites 
    88 */ 
    9 stubClassLoader::load('net.stubbles.ioc.injection.injection', 
     9stubClassLoader::load('net.stubbles.events.events', 
     10                      'net.stubbles.ioc.injection.injection', 
    1011                      'net.stubbles.ipo.interceptors.stubInterceptorInitializer', 
    1112                      'net.stubbles.ipo.request.stubRequest', 
     
    2526class stubFrontController extends stubBaseObject 
    2627{ 
     28    /** 
     29     * name of event triggered when session is created 
     30     */ 
     31    const SESSION_EVENT_NAME    = 'onSessionCreated'; 
    2732    /** 
    2833     * list of interceptors to call at startup 
     
    6772     */ 
    6873    protected $response; 
     74    /** 
     75     * the event dispatcher to use 
     76     * 
     77     * @var  stubEventDispatcher 
     78     */ 
     79    protected $dispatcher       = null; 
    6980 
    7081    /** 
     
    8596        $this->resolver = $processorResolverFactory->getResolver(); 
    8697        $this->createInjectionMap(); 
     98    } 
     99     
     100    /** 
     101     * sets the event dispatcher to use 
     102     * 
     103     * @param  stubEventDispatcher  $dispatcher 
     104     */ 
     105    public function setEventDispatcher(stubEventDispatcher $dispatcher) 
     106    { 
     107        $this->dispatcher = $dispatcher; 
    87108    } 
    88109     
     
    118139         
    119140        $this->injectionMap->addInjection('stubSession', $this->session); 
     141        if (null == $this->dispatcher) { 
     142            $this->dispatcher = stubEventDispatcher::getInstance(); 
     143        } 
     144        $this->dispatcher->trigger(self::SESSION_EVENT_NAME, $this->session, array(), true); 
    120145         
    121146        $this->response = new stubBaseResponse(); 
  • trunk/src/test/php/net/stubbles/websites/stubFrontControllerInjectionMapTestCase.php

    r399 r419  
    1616Mock::generate('stubRegistryInitializer'); 
    1717Mock::generate('stubXJConfFacade'); 
     18Mock::generate('stubEventListener'); 
    1819require_once dirname(__FILE__) . '/TeststubFrontController.php'; 
    1920class TeststubSessionName extends stubAbstractSession 
     
    7778        stubRegistry::setConfig('net.stubbles.ipo.request.class', null); 
    7879        stubRegistry::setConfig('net.stubbles.ipo.session.class', null); 
     80        $dispatcher        = stubEventDispatcher::getInstance(); 
     81        $mockEventListener = new MockstubEventListener(); 
     82        $mockEventListener->expectOnce('handleEvent'); 
     83        $mockEventListener->expectOnce('autoremove'); 
     84        $mockEventListener->setReturnValue('autoremove', true); 
     85        $dispatcher->clearQueuedEvents(); 
     86        $dispatcher->register($mockEventListener, stubFrontController::SESSION_EVENT_NAME); 
    7987        $injectionMap = $this->frontController->getInjectionMap(); 
    8088        $this->assertTrue($injectionMap->getInjection('stubRequest') instanceof stubWebRequest); 
    8189        $this->assertTrue($injectionMap->getInjection('stubSession') instanceof stubPHPSession); 
    8290        $this->assertTrue($injectionMap->getInjection('stubResponse') instanceof stubBaseResponse); 
     91        $dispatcher->remove($mockEventListener, stubFrontController::SESSION_EVENT_NAME); 
    8392    } 
    8493     
     
    8998    { 
    9099        stubRegistry::setConfig('net.stubbles.ipo.session.class', 'TeststubSessionName'); 
     100        $dispatcher        = stubEventDispatcher::getInstance(__CLASS__); 
     101        $this->frontController->setEventDispatcher($dispatcher); 
     102        $mockEventListener = new MockstubEventListener(); 
     103        $mockEventListener->expectOnce('handleEvent'); 
     104        $mockEventListener->expectOnce('autoremove'); 
     105        $mockEventListener->setReturnValue('autoremove', true); 
     106        $dispatcher->clearQueuedEvents(); 
     107        $dispatcher->register($mockEventListener, stubFrontController::SESSION_EVENT_NAME); 
    91108        $injectionMap = $this->frontController->getInjectionMap(); 
    92109        $this->assertTrue($injectionMap->getInjection('stubRequest') instanceof MockstubRequest); 
    93110        $this->assertTrue($injectionMap->getInjection('stubSession') instanceof TeststubSessionName); 
    94111        $this->assertEqual($injectionMap->getInjection('stubSession')->getSessionName(), 'SID'); 
     112        $dispatcher->remove($mockEventListener, stubFrontController::SESSION_EVENT_NAME); 
     113        stubEventDispatcher::destroyInstance(__CLASS__); 
    95114    } 
    96115