Changeset 914

Show
Ignore:
Timestamp:
09/12/07 14:41:30 (10 months ago)
Author:
mikey
Message:

fixed ticket #82
whitespace fixes

Files:

Legend:

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

    r909 r914  
    104104        if ($this->session->hasValue($sessionKey)) { 
    105105            $this->resources[$implementation] = $this->session->getValue($sessionKey); 
    106             $this->session->putValue($sessionKey, $this->resources[$implementation]); 
    107106            return $this->resources[$implementation]; 
    108107        } 
  • trunk/src/main/php/net/stubbles/ipo/session/stubAbstractSession.php

    r522 r914  
    4242     */ 
    4343    private $sessionName = ''; 
    44      
     44    /** 
     45     * cache for objects 
     46     * 
     47     * @var  array<string,object> 
     48     */ 
     49    private $objectCache = array(); 
     50 
    4551    /** 
    4652     * constructor 
     
    7278        $this->putValue(stubSession::NEXT_TOKEN, md5(uniqid(rand()))); 
    7379    } 
    74      
     80 
    7581    /** 
    7682     * template method for child classes to do the real construction 
     
    8086     */ 
    8187    protected abstract function doConstruct(stubRequest $request, $sessionName); 
    82          
     88 
     89    /** 
     90     * clear up object cache (make sure that changed objects are written into session store) 
     91     */ 
     92    public final function __destruct() 
     93    { 
     94        foreach ($this->objectCache as $key => $value) { 
     95            $this->managePutValue($key, $value); 
     96        } 
     97    } 
     98 
    8399    /** 
    84100     * returns fingerprint for user: has to use same user agent all over the session 
     
    97113        throw new stubSessionException('Cloning the session is somewhat... useless.'); 
    98114    } 
    99      
     115 
    100116    /** 
    101117     * checks whether session has been started 
     
    125141        return $this->getValue(stubSession::START_TIME); 
    126142    } 
    127      
     143 
    128144    /** 
    129145     * returns the name of the session 
     
    145161        return $this->token; 
    146162    } 
    147      
     163 
    148164    /** 
    149165     * returns token for next request 
     
    155171        return $this->getValue(stubSession::NEXT_TOKEN); 
    156172    } 
    157      
     173 
    158174    /** 
    159175     * checks if this session is valid 
     
    165181        return $this->hasValue(stubSession::START_TIME); 
    166182    } 
    167      
    168     /** 
     183 
     184    /** 
    169185     * resets the session and deletes all session data 
    170186     * 
     
    173189    public function reset() 
    174190    { 
    175         $valueKeys = $this->getValueKeys(); 
    176         $count     = 0; 
     191        $this->objectCache = array(); 
     192        $valueKeys         = $this->getValueKeys(); 
     193        $count             = 0; 
    177194        foreach ($valueKeys as $valueKey) { 
    178195            if (stubSession::NEXT_TOKEN == $valueKey || stubSession::FINGERPRINT == $valueKey) { 
     
    190207        return $count; 
    191208    } 
    192      
     209 
    193210    /** 
    194211     * stores a value associated with the key 
     
    198215     */ 
    199216    public function putValue($key, $value) 
     217    { 
     218        $this->managePutValue($key, $value); 
     219        if (is_object($value) === true) { 
     220            $this->objectCache[$key] = $value; 
     221        } 
     222    } 
     223 
     224    /** 
     225     * helper method for storing the value into the session 
     226     * 
     227     * @param  string  $key    key to store value under 
     228     * @param  mixed   $value  data to store 
     229     */ 
     230    protected function managePutValue($key, $value) 
    200231    { 
    201232        // This will enable lazy loading for stubObjects that are stored within 
     
    207238        } 
    208239    } 
    209      
     240 
    210241    /** 
    211242     * returns a value associated with the key or the default value 
     
    215246     */ 
    216247    protected abstract function doPutValue($key, $value); 
    217      
     248 
    218249    /** 
    219250     * returns a value associated with the key or the default value 
     
    230261        } 
    231262         
     263        if (isset($this->objectCache[$key]) === true) { 
     264            return $this->objectCache[$key]; 
     265        } 
     266         
    232267        if ($this->hasValue($key) == true) { 
    233268            $value = $this->doGetValue($key); 
    234269            if ($value instanceof stubSerializedObject) { 
    235                 return $value->getUnserialized(); 
     270                $this->objectCache[$key] = $value->getUnserialized(); 
     271                return $this->objectCache[$key]; 
    236272            } 
    237273             
     274            if (is_object($value) === true) { 
     275                $this->objectCache[$key] = $value; 
     276            } 
     277         
    238278            return $value; 
    239279        } 
     
    241281        return $default; 
    242282    } 
    243      
     283 
    244284    /** 
    245285     * returns a value associated with the key or the default value 
     
    249289     */ 
    250290    protected abstract function doGetValue($key); 
    251      
     291 
    252292    /** 
    253293     * removes a value from the session 
     
    263303        } 
    264304         
     305        if (isset($this->objectCache[$key]) === true) { 
     306            unset($this->objectCache[$key]); 
     307        } 
     308         
    265309        if ($this->hasValue($key) == true) { 
    266310            return $this->doRemoveValue($key); 
     
    269313        return false; 
    270314    } 
    271      
     315 
    272316    /** 
    273317     * removes a value from the session 
     
    277321     */ 
    278322    protected abstract function doRemoveValue($key); 
    279      
     323 
    280324    /** 
    281325     * return an array of all keys registered in this session 
     
    292336        return $this->doGetValueKeys(); 
    293337    } 
    294      
     338 
    295339    /** 
    296340     * return an array of all keys registered in this session