Show
Ignore:
Timestamp:
04/24/08 17:09:12 (6 months ago)
Author:
mikey
Message:

enhanced net::stubbles::ipo::session::stubNoneDurableSession to be more session-like

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ipo/session/stubNoneDurableSession.php

    r1549 r1563  
    77 * @subpackage  ipo_session 
    88 */ 
    9 stubClassLoader::load('net::stubbles::ipo::session::stubAbstractSession'); 
     9stubClassLoader::load('net::stubbles::ipo::request::validator::stubRegexValidator', 
     10                      'net::stubbles::ipo::session::stubAbstractSession' 
     11); 
    1012/** 
    1113 * Session class that is not durable for more than one request. 
     
    2123     * @var  int 
    2224     */ 
    23     protected $id   = 312
     25    protected $id
    2426    /** 
    2527     * the data 
     
    2729     * @var  array 
    2830     */ 
    29     protected $data = array(); 
     31    protected $data        = array(); 
     32    /** 
     33     * the response instance 
     34     * 
     35     * @var  stubResponse 
     36     */ 
     37    protected $response; 
     38    /** 
     39     * regular expression to validate the session id 
     40     */ 
     41    const REGEX_SESSION_ID = '/^([a-zA-Z0-9]{32})$/D'; 
    3042 
    3143    /** 
     
    3951    protected function doConstruct(stubRequest $request, stubResponse $response, $sessionName) 
    4052    { 
     53        $this->response = $response; 
     54        if ($request->hasValue($sessionName) === true) { 
     55            $this->id = $request->getValidatedValue(new stubRegexValidator(self::REGEX_SESSION_ID), $sessionName); 
     56            $this->data = array(stubSession::START_TIME  => time(), 
     57                                stubSession::FINGERPRINT => '', 
     58                                stubSession::NEXT_TOKEN  => '' 
     59                          ); 
     60        } elseif ($request->hasValue($sessionName, stubRequest::SOURCE_COOKIE) === true) { 
     61            $this->id = $request->getValidatedValue(new stubRegexValidator(self::REGEX_SESSION_ID), $sessionName, stubRequest::SOURCE_COOKIE); 
     62            $this->data = array(stubSession::START_TIME  => time(), 
     63                                stubSession::FINGERPRINT => '', 
     64                                stubSession::NEXT_TOKEN  => '' 
     65                          ); 
     66        } else { 
     67            $this->id = md5(uniqid(rand(), true)); 
     68        } 
     69         
     70        $this->response->setCookie(stubCookie::create($sessionName, $this->id)->forPath('/')); 
    4171        return true; 
    4272    } 
     
    5787     * @return  string  the session id 
    5888     */ 
    59     public function getID() 
     89    public function getId() 
    6090    { 
    6191        return $this->id; 
     
    6595     * regenerates the session id but leaves session data 
    6696     */ 
    67     public function regenerateID() 
     97    public function regenerateId() 
    6898    { 
    69         $this->id++; 
     99        $this->id = md5(uniqid(rand(), true)); 
     100        $this->response->setCookie(stubCookie::create($this->sessionName, $this->id)->forPath('/')); 
    70101    } 
    71102