Changeset 272

Show
Ignore:
Timestamp:
02/16/07 12:59:42 (1 year ago)
Author:
mikey
Message:

removed singleton from session

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docroot/index.php

    r263 r272  
    1111    { 
    1212        $request   = stubBaseRequest::getInstance('Web'); 
    13         $session   = stubBaseSession::getInstance('PHP', 'stubSID'); 
     13        $session   = new stubPHPSession('stubSID'); 
    1414        $processor = new stubMemphisPageProcessor($request, $session); 
    1515        $processor->process()->getResponse()->send(); 
  • trunk/docroot/xml.php

    r270 r272  
    2020        } 
    2121        $request   = stubBaseRequest::getInstance('Web'); 
    22         $session   = stubBaseSession::getInstance('PHP', 'stubSID'); 
     22        $session   = new stubPHPSession('stubSID'); 
    2323        $processor = new stubXMLProcessor($request, $session); 
    2424        $postInterceptor = new stubXMLPagePostInterceptor(); 
  • trunk/src/main/php/net/stubbles/ipo/session/stubBaseSession.php

    r153 r272  
    4646     * @param  string  $sessionName  name of the session 
    4747     */ 
    48     protected final function __construct($sessionName) 
     48    public final function __construct($sessionName) 
    4949    { 
    5050        $this->doConstruct($sessionName); 
     
    8383     */ 
    8484    protected abstract function getFingerprint(); 
    85      
    86     /** 
    87      * returns the required instance 
    88      * 
    89      * @param   string           $type 
    90      * @param  string            $sessionName  name of the session 
    91      * @return  stubBaseSession 
    92      * @throws  stubSessionException 
    93      */ 
    94     public static function getInstance($type, $sessionName) 
    95     { 
    96         if (null !== self::$instance) { 
    97             return self::$instance; 
    98         } 
    99          
    100         $className = 'stub' . $type . 'Session'; 
    101         if (class_exists($className) == false) { 
    102             throw new stubSessionException('Unknown session type ' . $type); 
    103         } 
    104          
    105         self::$instance = new $className($sessionName); 
    106         return self::$instance; 
    107     } 
    108      
     85 
    10986    /** 
    11087     * cloning is forbidden 
     
    11491    protected final function __clone() 
    11592    { 
    116         throw new stubSessionException('Session is in an invalid state.'); 
     93        throw new stubSessionException('Cloning the session is somewhat... useless.'); 
    11794    } 
    11895     
  • trunk/src/test/php/net/stubbles/ipo/session/stubBaseSessionTestCase.php

    r153 r272  
    1212    protected $id   = 'test'; 
    1313    protected $data = array(); 
    14      
    15     public function destroy() { parent::$instance = null; } 
    1614     
    1715    protected function doConstruct($sessionName) 
     
    7169    public function setUp() 
    7270    { 
    73         // bugfix for simpletest: tearDown() not called if an expected session  
    74         // was thrown within a test method 
    75         if (is_object($this->session) == true) { 
    76             $this->session->destroy(); 
    77         } 
    78         $this->session = stubBaseSession::getInstance('Test', ''); 
     71        $this->session = new stubTestSession(''); 
    7972    } 
    80      
    81     /** 
    82      * clear test environment 
    83      */ 
    84     public function tearDown() 
    85     { 
    86         $this->session->destroy(); 
    87     } 
    88      
     73 
    8974    /** 
    9075     * test with default values 
     
    10085        $nextToken = $this->session->getNextToken(); 
    10186         
    102         $session = stubBaseSession::getInstance('Test', ''); 
    103         $this->assertReference($this->session, $session); 
    104         $this->assertTrue($session->isNew()); 
    105         $session->destroy(); 
    106          
    107         $this->session->destroy(); 
    108         $this->session = stubBaseSession::getInstance('Test', $startTime . '|foobarbaz|' . $nextToken); 
     87        $this->session = new stubTestSession($startTime . '|foobarbaz|' . $nextToken); 
    10988        $this->assertEqual($this->session->getStartTime(), $startTime); 
    11089        $this->assertFalse($this->session->isNew()); 
     
    196175    public function testSessionHijacking() 
    197176    { 
    198         $this->session->destroy(); 
    199177        // original session started at 50 with fingerprint blub 
    200         $this->session = stubBaseSession::getInstance('Test', '50|blub|dummy'); 
     178        $this->session = new stubTestSession('50|blub|dummy'); 
    201179        $this->assertTrue($this->session->isNew()); 
    202180        $this->assertNotEqual($this->session->getStartTime(), 50); 
  • trunk/src/test/php/net/stubbles/ipo/session/stubPHPSessionTestCase.php

    r157 r272  
    88 */ 
    99stubClassLoader::load('net.stubbles.ipo.session.stubPHPSession'); 
    10 class stubTestPHPSession extends stubPHPSession 
    11 { 
    12     public function destroy() { $this->invalidate(); parent::$instance = null; } 
    13 } 
    1410/** 
    1511 * Tests for net.stubbles.ipo.session.stubPHPSession 
     
    3834    public function setUp() 
    3935    { 
    40         // bugfix for simpletest: tearDown() not called if an expected session  
    41         // was thrown within a test method 
    42         if (is_object($this->session) == true) { 
    43             $this->session->destroy(); 
    44         } 
    45          
    4636        if (isset($_SERVER['HTTP_USER_AGENT']) == false) { 
    4737            $_SERVER['HTTP_USER_AGENT'] = 'dummy for preventing E_NOTICE in cli mode.'; 
     
    4939        } 
    5040         
    51         $this->session = stubBaseSession::getInstance('TestPHP', 'test'); 
     41        $_SESSION      = array(); 
     42        $this->session = new stubPHPSession('test'); 
    5243    } 
    5344     
     
    5748    public function tearDown() 
    5849    { 
    59         $this->session->destroy(); 
    6050        if (true == $this->userAgentSet) { 
    6151            unset($_SERVER['HTTP_USER_AGENT']);