Development

Changeset 4890

You must first sign up to be able to contribute.

Changeset 4890

Show
Ignore:
Timestamp:
08/23/07 17:48:11 (2 years ago)
Author:
fabien
Message:

refactored storage sub-framework

  • removed sfContext, sfConfig and sfDatabaseManager dependencies
  • added a new sfNoStorage to be able to disable sessions
  • added a new sfDatabaseStorage abstract class for all database based session storage classes
  • added unit tests
  • simplified some calls: ->getParameterHolder()->get() to ->getParameter()
  • fixed a bug in sfPostgreSQLSessionStorage::sessionGC()
  • fixed coding standards
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/data/skeleton/app/app/config/factories.yml

    r4852 r4890  
    1717  storage: 
    1818    class: sfSessionTestStorage 
     19    param: 
     20      session_path: %SF_TEST_CACHE_DIR%/sessions 
    1921 
    2022#all: 
  • trunk/lib/addon/creole/storage/sfCreoleSessionStorage.class.php

    r4887 r4890  
    1616 * Provides support for session storage using a CreoleDb database abstraction layer. 
    1717 * 
    18  * <b>Required parameters:</b> 
    19  * 
    20  * # <b>db_table</b> - [none] - The database table in which session data will be 
    21  *                              stored. 
    22  * 
    23  * <b>Optional parameters:</b> 
    24  * 
    25  * # <b>database</b>     - [default]   - The database connection to use 
    26  *                                       (see databases.ini). 
    27  * # <b>db_id_col</b>    - [sess_id]   - The database column in which the 
    28  *                                       session id will be stored. 
    29  * # <b>db_data_col</b>  - [sess_data] - The database column in which the 
    30  *                                       session data will be stored. 
    31  * # <b>db_time_col</b>  - [sess_time] - The database column in which the 
    32  *                                       session timestamp will be stored. 
    33  * # <b>session_name</b> - [Agavi]    - The name of the session. 
     18 * <b>parameters:</b> see sfDatabaseSessionStorage 
    3419 * 
    3520 * @package    symfony 
     
    4025 * @version    SVN: $Id$ 
    4126 */ 
    42 class sfCreoleSessionStorage extends sfSessionStorage 
     27class sfCreoleSessionStorage extends sfDatabaseSessionStorage 
    4328{ 
    44   /** 
    45    * Creole Database Connection 
    46    * @var Connection 
    47    */ 
    48   protected $db; 
    49  
    50   /** 
    51    * Initialize this Storage. 
    52    * 
    53    * @param Context A Context instance. 
    54    * @param array   An associative array of initialization parameters. 
    55    * 
    56    * @return bool true, if initialization completes successfully, otherwise 
    57    *              false. 
    58    * 
    59    * @throws <b>InitializationException</b> If an error occurs while 
    60    *                                        initializing this Storage. 
    61    */ 
    62   public function initialize($context, $parameters = null) 
    63   { 
    64     // disable auto_start 
    65     $parameters['auto_start'] = false; 
    66  
    67     // initialize the parent 
    68     parent::initialize($context, $parameters); 
    69  
    70     if (!$this->getParameterHolder()->has('db_table')) 
    71     { 
    72       // missing required 'db_table' parameter 
    73       throw new sfInitializationException('Factory configuration file is missing required "db_table" parameter for the Storage category.'); 
    74     } 
    75  
    76     // use this object as the session handler 
    77     session_set_save_handler(array($this, 'sessionOpen'), 
    78                              array($this, 'sessionClose'), 
    79                              array($this, 'sessionRead'), 
    80                              array($this, 'sessionWrite'), 
    81                              array($this, 'sessionDestroy'), 
    82                              array($this, 'sessionGC')); 
    83  
    84     // start our session 
    85     session_start(); 
    86   } 
    87  
    88   /** 
    89   * Close a session. 
    90   * 
    91   * @return bool true, if the session was closed, otherwise false. 
    92   */ 
    93   public function sessionClose() 
    94   { 
    95     // do nothing 
    96     return true; 
    97   } 
    98  
    9929  /** 
    10030   * Destroy a session. 
     
    10939  { 
    11040    // get table/column 
    111     $db_table  = $this->getParameterHolder()->get('db_table'); 
    112     $db_id_col = $this->getParameterHolder()->get('db_id_col', 'sess_id'); 
     41    $db_table  = $this->getParameter('db_table'); 
     42    $db_id_col = $this->getParameter('db_id_col', 'sess_id'); 
    11343 
    11444    // delete the record associated with this id 
    115     $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_id_col.'=?'; 
     45    $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_id_col.'= ?'; 
    11646 
    11747    try 
     
    12555      throw new sfDatabaseException(sprintf('Creole SQLException was thrown when trying to manipulate session data. Message: %s.', $e->getMessage())); 
    12656    } 
     57 
     58    return true; 
    12759  } 
    12860 
     
    13870  public function sessionGC($lifetime) 
    13971  { 
    140     // determine deletable session time 
    141     $time = time() - $lifetime; 
    142  
    14372    // get table/column 
    144     $db_table    = $this->getParameterHolder()->get('db_table'); 
    145     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); 
     73    $db_table    = $this->getParameter('db_table'); 
     74    $db_time_col = $this->getParameter('db_time_col', 'sess_time'); 
    14675 
    14776    // delete the record associated with this id 
    148     $sql = 'DELETE FROM '.$db_table.' '.'WHERE '.$db_time_col.' < '.$time
     77    $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_time_col.' < '.(time() - $lifetime)
    14978 
    15079    try 
    15180    { 
    15281      $this->db->executeQuery($sql); 
    153       return true; 
    15482    } 
    15583    catch (SQLException $e) 
    15684    { 
    15785      throw new sfDatabaseException(sprintf('Creole SQLException was thrown when trying to manipulate session data. Message: %s.', $e->getMessage())); 
    158     } 
    159   } 
    160  
    161   /** 
    162    * Open a session. 
    163    * 
    164    * @param string 
    165    * @param string 
    166    * 
    167    * @return bool true, if the session was opened, otherwise an exception is thrown. 
    168    * 
    169    * @throws <b>DatabaseException</b> If a connection with the database does 
    170    *                                  not exist or cannot be created. 
    171    */ 
    172   public function sessionOpen($path, $name) 
    173   { 
    174     // what database are we using? 
    175     $database = $this->getParameterHolder()->get('database', 'default'); 
    176  
    177     // autoload propel propely if we're reusing the propel connection for session storage 
    178     if ($this->getContext()->getDatabaseManager()->getDatabase($database) instanceof sfPropelDatabase && !Propel::isInit()) 
    179     { 
    180       throw new sfDatabaseException('Creole dabatase connection is the same as the propel database connection, but could not be initialized.'); 
    181     } 
    182  
    183     $this->db = $this->getContext()->getDatabaseConnection($database); 
    184     if ($this->db == null || !$this->db instanceof Connection) 
    185     { 
    186       throw new sfDatabaseException('Creole dabatase connection doesn\'t exist. Unable to open session.'); 
    18786    } 
    18887 
     
    202101  { 
    203102    // get table/columns 
    204     $db_table    = $this->getParameterHolder()->get('db_table'); 
    205     $db_data_col = $this->getParameterHolder()->get('db_data_col', 'sess_data'); 
    206     $db_id_col   = $this->getParameterHolder()->get('db_id_col', 'sess_id'); 
    207     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); 
     103    $db_table    = $this->getParameter('db_table'); 
     104    $db_data_col = $this->getParameter('db_data_col', 'sess_data'); 
     105    $db_id_col   = $this->getParameter('db_id_col', 'sess_id'); 
     106    $db_time_col = $this->getParameter('db_time_col', 'sess_time'); 
    208107 
    209108    try 
     
    256155  { 
    257156    // get table/column 
    258     $db_table    = $this->getParameterHolder()->get('db_table'); 
    259     $db_data_col = $this->getParameterHolder()->get('db_data_col', 'sess_data'); 
    260     $db_id_col   = $this->getParameterHolder()->get('db_id_col', 'sess_id'); 
    261     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); 
     157    $db_table    = $this->getParameter('db_table'); 
     158    $db_data_col = $this->getParameter('db_data_col', 'sess_data'); 
     159    $db_id_col   = $this->getParameter('db_id_col', 'sess_id'); 
     160    $db_time_col = $this->getParameter('db_time_col', 'sess_time'); 
    262161 
    263162    $sql = 'UPDATE '.$db_table.' SET '.$db_data_col.'=?, '.$db_time_col.' = '.time().' WHERE '.$db_id_col.'=?'; 
     
    269168      $stmt->setString(2, $id); 
    270169      $stmt->executeUpdate(); 
    271  
    272       return true; 
    273170    } 
    274  
    275171    catch (SQLException $e) 
    276172    { 
     
    278174    } 
    279175 
    280     return false; 
    281   } 
    282  
    283   /** 
    284    * Execute the shutdown procedure. 
    285    * 
    286    * @return void 
    287    */ 
    288   public function shutdown() 
    289   { 
     176    return true; 
    290177  } 
    291178} 
  • trunk/lib/config/sfFactoryConfigHandler.class.php

    r4845 r4890  
    127127 
    128128          // append instance initialization 
    129           $inits[] = sprintf("  \$this->factories['storage']->initialize(\$this, sfConfig::get('sf_factory_storage_parameters', %s));", var_export($parameters, true)); 
     129          $defaultParameters = array(); 
     130          $defaultParameters[] = sprintf("'session_id' => \$this->getRequest()->getParameter('%s'),", $parameters['session_name']); 
     131          if (is_subclass_of($class, 'sfDatabaseSessionStorage')) 
     132          { 
     133            $defaultParameters[] = sprintf("'database' => \$this->getDatabaseManager()->getDatabase('%s'),", isset($parameters['database']) ? $parameters['database'] : 'default'); 
     134          } 
     135          $inits[] = sprintf("  \$this->factories['storage']->initialize(array_merge(array(\n%s\n), sfConfig::get('sf_factory_storage_parameters', %s)));", implode("\n", $defaultParameters), var_export($parameters, true)); 
    130136          break; 
    131137 
  • trunk/lib/database/sfDatabase.class.php

    r3210 r4890  
    2323{ 
    2424  protected 
     25    $parameterHolder = null, 
    2526    $connection      = null, 
    26     $parameterHolder = null, 
    2727    $resource        = null; 
    2828 
     
    4646  public function getConnection() 
    4747  { 
    48     if ($this->connection == null
     48    if (is_null($this->connection)
    4949    { 
    5050      $this->connect(); 
     
    6363  public function getResource() 
    6464  { 
    65     if ($this->resource == null
     65    if (is_null($this->resource)
    6666    { 
    6767      $this->connect(); 
  • trunk/lib/storage/sfMySQLSessionStorage.class.php

    r4887 r4890  
    1313 * Provides support for session storage using a MySQL brand database. 
    1414 * 
    15  * <b>Required parameters:</b> 
    16  * 
    17  * # <b>db_table</b> - [none] - The database table in which session data will be 
    18  *                              stored. 
    19  * 
    20  * <b>Optional parameters:</b> 
    21  * 
    22  * # <b>db_id_col</b>    - [sess_id]   - The database column in which the 
    23  *                                       session id will be stored. 
    24  * # <b>db_data_col</b>  - [sess_data] - The database column in which the 
    25  *                                       session data will be stored. 
    26  * # <b>db_time_col</b>  - [sess_time] - The database column in which the 
    27  *                                       session timestamp will be stored. 
    28  * # <b>session_name</b> - [symfony]   - The name of the session. 
     15 * <b>parameters:</b> see sfDatabaseSessionStorage 
    2916 * 
    3017 * @package    symfony 
     
    3421 * @version    SVN: $Id$ 
    3522 */ 
    36 class sfMySQLSessionStorage extends sfSessionStorage 
     23class sfMySQLSessionStorage extends sfDatabaseSessionStorage 
    3724{ 
    38   protected 
    39     $resource = null; 
    40  
    41   /** 
    42    * Initializes this Storage instance. 
    43    * 
    44    * @param sfContext A sfContext instance 
    45    * @param array   An associative array of initialization parameters 
    46    * 
    47    * @return boolean true, if initialization completes successfully, otherwise false 
    48    * 
    49    * @throws <b>sfInitializationException</b> If an error occurs while initializing this Storage 
    50    */ 
    51   public function initialize($context, $parameters = null) 
    52   { 
    53     // disable auto_start 
    54     $parameters['auto_start'] = false; 
    55  
    56     // initialize the parent 
    57     parent::initialize($context, $parameters); 
    58  
    59     if (!$this->getParameterHolder()->has('db_table')) 
    60     { 
    61         // missing required 'db_table' parameter 
    62         throw new sfInitializationException('Factory configuration file is missing required "db_table" parameter for the Storage category.'); 
    63     } 
    64  
    65     // use this object as the session handler 
    66     session_set_save_handler(array($this, 'sessionOpen'), 
    67                              array($this, 'sessionClose'), 
    68                              array($this, 'sessionRead'), 
    69                              array($this, 'sessionWrite'), 
    70                              array($this, 'sessionDestroy'), 
    71                              array($this, 'sessionGC')); 
    72  
    73     // start our session 
    74     session_start(); 
    75   } 
    76  
    77   /** 
    78    * Closes a session. 
    79    * 
    80    * @return boolean true, if the session was closed, otherwise false 
    81    */ 
    82   public function sessionClose() 
    83   { 
    84     // do nothing 
    85     return true; 
    86   } 
    87  
    8825  /** 
    8926   * Destroys a session. 
     
    9835  { 
    9936    // get table/column 
    100     $db_table  = $this->getParameterHolder()->get('db_table'); 
    101     $db_id_col = $this->getParameterHolder()->get('db_id_col', 'sess_id'); 
     37    $db_table  = $this->getParameter('db_table'); 
     38    $db_id_col = $this->getParameter('db_id_col', 'sess_id'); 
    10239 
    10340    // cleanup the session id, just in case 
    104     $id = mysql_real_escape_string($id, $this->resource); 
     41    $id = mysql_real_escape_string($id, $this->db); 
    10542 
    10643    // delete the record associated with this id 
    10744    $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_id_col.' = \''.$id.'\''; 
    10845 
    109     if (@mysql_query($sql, $this->resource)) 
     46    if (@mysql_query($sql, $this->db)) 
    11047    { 
    11148      return true; 
     
    11350 
    11451    // failed to destroy session 
    115     throw new sfDatabaseException(sprintf('MySQLSessionStorage cannot destroy session id "%s".', $id)); 
     52    throw new sfDatabaseException(sprintf('sfMySQLSessionStorage cannot destroy session id "%s".', $id)); 
    11653  } 
    11754 
     
    12764  public function sessionGC($lifetime) 
    12865  { 
    129     // determine deletable session time 
    130     $time = time() - $lifetime; 
    131  
    13266    // get table/column 
    133     $db_table    = $this->getParameterHolder()->get('db_table'); 
    134     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); 
     67    $db_table    = $this->getParameter('db_table'); 
     68    $db_time_col = $this->getParameter('db_time_col', 'sess_time'); 
    13569 
    13670    // delete the record associated with this id 
    137     $sql = 'DELETE FROM '.$db_table.' '. 
    138            'WHERE '.$db_time_col.' < '.$time; 
     71    $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_time_col.' < '.(time() - $lifetime); 
    13972 
    140     if (@mysql_query($sql, $this->resource)) 
     73    if (!@mysql_query($sql, $this->db)) 
    14174    { 
    142       return true
     75      throw new sfDatabaseException('sfMySQLSessionStorage cannot delete old sessions.')
    14376    } 
    144  
    145     // failed to cleanup old sessions 
    146     throw new sfDatabaseException('MySQLSessionStorage cannot delete old sessions.'); 
    147   } 
    148  
    149   /** 
    150    * Opens a session. 
    151    * 
    152    * @param string 
    153    * @param string 
    154    * 
    155    * @return boolean true, if the session was opened, otherwise an exception is thrown 
    156    * 
    157    * @throws <b>sfDatabaseException</b> If a connection with the database does not exist or cannot be created 
    158    */ 
    159   public function sessionOpen($path, $name) 
    160   { 
    161     // what database are we using? 
    162     $database = $this->getParameterHolder()->get('database', 'default'); 
    163  
    164     // get the database resource 
    165     $this->resource = $this->context->getDatabaseManager()->getDatabase($database)->getResource(); 
    16677 
    16778    return true; 
     
    18091  { 
    18192    // get table/column 
    182     $db_table    = $this->getParameterHolder()->get('db_table'); 
    183     $db_data_col = $this->getParameterHolder()->get('db_data_col', 'sess_data'); 
    184     $db_id_col   = $this->getParameterHolder()->get('db_id_col', 'sess_id'); 
    185     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); 
     93    $db_table    = $this->getParameter('db_table'); 
     94    $db_data_col = $this->getParameter('db_data_col', 'sess_data'); 
     95    $db_id_col   = $this->getParameter('db_id_col', 'sess_id'); 
     96    $db_time_col = $this->getParameter('db_time_col', 'sess_time'); 
    18697 
    18798    // cleanup the session id, just in case 
    188     $id = mysql_real_escape_string($id, $this->resource); 
     99    $id = mysql_real_escape_string($id, $this->db); 
    189100 
    190101    // delete the record associated with this id 
    191     $sql = 'SELECT '.$db_data_col.' ' . 
    192            'FROM '.$db_table.' ' . 
    193            'WHERE '.$db_id_col.' = \''.$id.'\''; 
     102    $sql = 'SELECT '.$db_data_col.' FROM '.$db_table.' WHERE '.$db_id_col.' = \''.$id.'\''; 
    194103 
    195     $result = @mysql_query($sql, $this->resource); 
     104    $result = @mysql_query($sql, $this->db); 
    196105 
    197106    if ($result != false && @mysql_num_rows($result) == 1) 
     
    205114    { 
    206115      // session does not exist, create it 
    207       $sql = 'INSERT INTO '.$db_table.' ('.$db_id_col.', ' . 
    208              $db_data_col.', '.$db_time_col.') VALUES (' . 
    209              '\''.$id.'\', \'\', '.time().')'; 
     116      $sql = 'INSERT INTO '.$db_table.' ('.$db_id_col.', '.$db_data_col.', '.$db_time_col.') VALUES (\''.$id.'\', \'\', '.time().')'; 
    210117 
    211       if (@mysql_query($sql, $this->resource)) 
     118      if (@mysql_query($sql, $this->db)) 
    212119      { 
    213120        return ''; 
     
    215122 
    216123      // can't create record 
    217       throw new sfDatabaseException(sprintf('MySQLSessionStorage cannot create new record for id "%s".', $id)); 
     124      throw new sfDatabaseException(sprintf('sfMySQLSessionStorage cannot create new record for id "%s".', $id)); 
    218125    } 
    219126  } 
     
    232139  { 
    233140    // get table/column 
    234     $db_table    = $this->getParameterHolder()->get('db_table'); 
    235     $db_data_col = $this->getParameterHolder()->get('db_data_col', 'sess_data'); 
    236     $db_id_col   = $this->getParameterHolder()->get('db_id_col', 'sess_id'); 
    237     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); 
     141    $db_table    = $this->getParameter('db_table'); 
     142    $db_data_col = $this->getParameter('db_data_col', 'sess_data'); 
     143    $db_id_col   = $this->getParameter('db_id_col', 'sess_id'); 
     144    $db_time_col = $this->getParameter('db_time_col', 'sess_time'); 
    238145 
    239146    // cleanup the session id and data, just in case 
    240     $id   = mysql_real_escape_string($id, $this->resource); 
    241     $data = mysql_real_escape_string($data, $this->resource); 
     147    $id   = mysql_real_escape_string($id, $this->db); 
     148    $data = mysql_real_escape_string($data, $this->db); 
    242149 
    243150    // delete the record associated with this id 
    244     $sql = 'UPDATE '.$db_table.' ' . 
    245            'SET '.$db_data_col.' = \''.$data.'\', ' . 
    246            $db_time_col.' = '.time().' ' . 
    247            'WHERE '.$db_id_col.' = \''.$id.'\''; 
     151    $sql = 'UPDATE '.$db_table.' SET '.$db_data_col.' = \''.$data.'\', '.$db_time_col.' = '.time().' WHERE '.$db_id_col.' = \''.$id.'\''; 
    248152 
    249     if (@mysql_query($sql, $this->resource)) 
     153    if (@mysql_query($sql, $this->db)) 
    250154    { 
    251155      return true; 
     
    253157 
    254158    // failed to write session data 
    255     throw new sfDatabaseException(sprintf('MySQLSessionStorage cannot write session data for id "%s".', $id)); 
    256   } 
    257  
    258   /** 
    259    * Executes the shutdown procedure. 
    260    * 
    261    */ 
    262   public function shutdown() 
    263   { 
     159    throw new sfDatabaseException(sprintf('sfMySQLSessionStorage cannot write session data for id "%s".', $id)); 
    264160  } 
    265161} 
  • trunk/lib/storage/sfPDOSessionStorage.class.php

    r4887 r4890  
    1313 * Provides support for session storage using a PDO database abstraction layer. 
    1414 * 
    15  * <b>Required parameters:</b> 
    16  * 
    17  * # <b>db_table</b> - [none] - The database table in which session data will be stored. 
    18  * 
    19  * <b>Optional parameters:</b> 
    20  * 
    21  * # <b>database</b>     - [default]   - The database connection to use (see databases.yml). 
    22  * # <b>db_id_col</b>    - [sess_id]   - The database column in which the session id will be stored. 
    23  * # <b>db_data_col</b>  - [sess_data] - The database column in which the session data will be stored. 
    24  * # <b>db_time_col</b>  - [sess_time] - The database column in which the session timestamp will be stored. 
    25  * # <b>session_name</b> - [symfony]   - The name of the session. 
     15 * <b>parameters:</b> see sfDatabaseSessionStorage 
    2616 * 
    2717 * @package    symfony 
     
    3222 * @version    SVN: $Id$ 
    3323 */ 
    34 class sfPDOSessionStorage extends sfSessionStorage 
     24class sfPDOSessionStorage extends sfDatabaseSessionStorage 
    3525{ 
    36   /** 
    37    * PDO connection 
    38    * @var Connection 
    39    */ 
    40   protected $db; 
    41  
    42   /** 
    43    * Initializes this Storage instance. 
    44    * 
    45    * @param sfContext A sfContext instance 
    46    * @param array     An associative array of initialization parameters 
    47    * 
    48    * @return boolean true, if initialization completes successfully, otherwise false 
    49    * 
    50    * @throws <b>InitializationException</b> If an error occurs while initializing this Storage 
    51    */ 
    52   public function initialize($context, $parameters = null) 
    53   { 
    54     // disable auto_start 
    55     $parameters['auto_start'] = false; 
    56  
    57     // initialize the parent 
    58     parent::initialize($context, $parameters); 
    59  
    60     if (!$this->getParameterHolder()->has('db_table')) 
    61     { 
    62       // missing required 'db_table' parameter 
    63       $error = 'Factory configuration file is missing required "db_table" parameter for the Storage category'; 
    64  
    65       throw new sfInitializationException($error); 
    66     } 
    67  
    68     // use this object as the session handler 
    69     session_set_save_handler(array($this, 'sessionOpen'), 
    70                              array($this, 'sessionClose'), 
    71                              array($this, 'sessionRead'), 
    72                              array($this, 'sessionWrite'), 
    73                              array($this, 'sessionDestroy'), 
    74                              array($this, 'sessionGC')); 
    75  
    76     // start our session 
    77     session_start(); 
    78   } 
    79  
    80   /** 
    81   * Closes a session. 
    82   * 
    83   * @return boolean true, if the session was closed, otherwise false 
    84   */ 
    85   public function sessionClose() 
    86   { 
    87     // do nothing 
    88     return true; 
    89   } 
    90  
    9126  /** 
    9227   * Destroys a session. 
     
    10136  { 
    10237    // get table/column 
    103     $db_table  = $this->getParameterHolder()->get('db_table'); 
    104     $db_id_col = $this->getParameterHolder()->get('db_id_col', 'sess_id'); 
     38    $db_table  = $this->getParameter('db_table'); 
     39    $db_id_col = $this->getParameter('db_id_col', 'sess_id'); 
    10540 
    10641    // delete the record associated with this id 
     
    11045    { 
    11146      $stmt = $this->db->prepare($sql); 
    112       $stmt->bindParam(1, $id, PDO::PARAM_STR); // setString(1, $id); 
     47      $stmt->bindParam(1, $id, PDO::PARAM_STR); 
    11348      $stmt->execute(); 
    11449    } 
    11550    catch (PDOException $e) 
    11651    { 
    117       $error = sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage()); 
    118  
    119       throw new sfDatabaseException($error); 
     52      throw new sfDatabaseException(sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage())); 
    12053    } 
    12154  } 
     
    13265  public function sessionGC($lifetime) 
    13366  { 
    134     // determine deletable session time 
    135     $time = time() - $lifetime; 
    136  
    13767    // get table/column 
    138     $db_table    = $this->getParameterHolder()->get('db_table'); 
    139     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); 
     68    $db_table    = $this->getParameter('db_table'); 
     69    $db_time_col = $this->getParameter('db_time_col', 'sess_time'); 
    14070 
    14171    // delete the record associated with this id 
    142     $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_time_col.' < '.$time
     72    $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_time_col.' < '.(time() - $lifetime)
    14373 
    14474    try 
    14575    { 
    14676      $this->db->query($sql); 
    147       return true; 
    14877    } 
    14978    catch (PDOException $e) 
    15079    { 
    151       $error = sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage()); 
    152  
    153       throw new sfDatabaseException($error); 
    154     } 
    155   } 
    156  
    157   /** 
    158    * Opens a session. 
    159    * 
    160    * @param string 
    161    * @param string 
    162    * 
    163    * @return boolean true, if the session was opened, otherwise an exception is thrown 
    164    * 
    165    * @throws <b>DatabaseException</b> If a connection with the database does not exist or cannot be created 
    166    */ 
    167   public function sessionOpen($path, $name) 
    168   { 
    169     // what database are we using? 
    170     $database = $this->getParameterHolder()->get('database', 'default'); 
    171  
    172     $this->db = $this->context->getDatabaseManager()->getDatabase($database)->getResource(); 
    173     if ($this->db == null || !$this->db instanceof PDO) 
    174     { 
    175       $error = 'PDO dabatase connection doesn\'t exist. Unable to open session.'; 
    176  
    177       throw new sfDatabaseException($error); 
     80      throw new sfDatabaseException(sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage())); 
    17881    } 
    17982 
     
    19396  { 
    19497    // get table/columns 
    195     $db_table    = $this->getParameterHolder()->get('db_table'); 
    196     $db_data_col = $this->getParameterHolder()->get('db_data_col', 'sess_data'); 
    197     $db_id_col   = $this->getParameterHolder()->get('db_id_col', 'sess_id'); 
    198     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); 
     98    $db_table    = $this->getParameter('db_table'); 
     99    $db_data_col = $this->getParameter('db_data_col', 'sess_data'); 
     100    $db_id_col   = $this->getParameter('db_id_col', 'sess_id'); 
     101    $db_time_col = $this->getParameter('db_time_col', 'sess_time'); 
    199102 
    200103    try 
     
    216119 
    217120        $stmt = $this->db->prepare($sql); 
    218         $stmt->bindParam(1, $id, PDO::PARAM_STR); // setString(1, $id); 
    219         $stmt->bindValue(2, '', PDO::PARAM_STR); // setString(2, ''); 
    220         $stmt->bindValue(3, time(), PDO::PARAM_INT); // setInt(3, time()); 
     121        $stmt->bindParam(1, $id, PDO::PARAM_STR); 
     122        $stmt->bindValue(2, '', PDO::PARAM_STR); 
     123        $stmt->bindValue(3, time(), PDO::PARAM_INT); 
    221124        $stmt->execute(); 
    222125 
     
    226129    catch (PDOException $e) 
    227130    { 
    228       $error = sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage()); 
    229  
    230       throw new sfDatabaseException($error); 
     131      throw new sfDatabaseException(sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage())); 
    231132    } 
    232133  } 
     
    245146  { 
    246147    // get table/column 
    247     $db_table    = $this->getParameterHolder()->get('db_table'); 
    248     $db_data_col = $this->getParameterHolder()->get('db_data_col', 'sess_data'); 
    249     $db_id_col   = $this->getParameterHolder()->get('db_id_col', 'sess_id'); 
    250     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); 
     148    $db_table    = $this->getParameter('db_table'); 
     149    $db_data_col = $this->getParameter('db_data_col', 'sess_data'); 
     150    $db_id_col   = $this->getParameter('db_id_col', 'sess_id'); 
     151    $db_time_col = $this->getParameter('db_time_col', 'sess_time'); 
    251152 
    252153    $sql = 'UPDATE '.$db_table.' SET '.$db_data_col.' = ?, '.$db_time_col.' = '.time().' WHERE '.$db_id_col.'= ?'; 
     
    255156    { 
    256157      $stmt = $this->db->prepare($sql); 
    257       $stmt->bindParam(1, $data, PDO::PARAM_STR); // setString(1, $data); 
    258       $stmt->bindParam(2, $id, PDO::PARAM_STR); // setString(2, $id); 
     158      $stmt->bindParam(1, $data, PDO::PARAM_STR); 
     159      $stmt->bindParam(2, $id, PDO::PARAM_STR); 
    259160      $stmt->execute(); 
    260       return true; 
    261161    } 
    262  
    263162    catch (PDOException $e) 
    264163    { 
    265       $error = sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage()); 
    266  
    267       throw new sfDatabaseException($error); 
     164      throw new sfDatabaseException(sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage())); 
    268165    } 
    269166 
    270167    return false; 
    271168  } 
    272  
    273   /** 
    274    * Executes the shutdown procedure. 
    275    * 
    276    */ 
    277   public function shutdown() 
    278   { 
    279   } 
    280169} 
  • trunk/lib/storage/sfPostgreSQLSessionStorage.class.php

    r4887 r4890  
    1313 * Provides support for session storage using a PostgreSQL brand database. 
    1414 * 
    15  * <b>Required parameters:</b> 
    16  * 
    17  * # <b>db_table</b> - [none] - The database table in which session data will be stored. 
    18  * 
    19  * <b>Optional parameters:</b> 
    20  * 
    21  * # <b>db_id_col</b>    - [sess_id]   - The database column in which the 
    22  *                                       session id will be stored. 
    23  * # <b>db_data_col</b>  - [sess_data] - The database column in which the 
    24  *                                       session data will be stored. 
    25  * # <b>db_time_col</b>  - [sess_time] - The database column in which the 
    26  *                                       session timestamp will be stored. 
    27  * # <b>session_name</b> - [symfony]   - The name of the session. 
     15 * <b>parameters:</b> see sfDatabaseSessionStorage 
    2816 * 
    2917 * @package    symfony 
     
    3321 * @version    SVN: $Id$ 
    3422 */ 
    35 class sfPostgreSQLSessionStorage extends sfSessionStorage 
     23class sfPostgreSQLSessionStorage extends sfDatabaseSessionStorage 
    3624{ 
    37   protected 
    38     $resource = null; 
    39  
    40   /** 
    41    * Initializes this Storage instance. 
    42    * 
    43    * @param sfContext A sfContext instance 
    44    * @param array   An associative array of initialization parameters 
    45    * 
    46    * @return boolean true, if initialization completes successfully, otherwise false 
    47    * 
    48    * @throws <b>sfInitializationException</b> If an error occurs while initializing this Storage 
    49    */ 
    50   public function initialize($context, $parameters = null) 
    51   { 
    52     // disable auto_start 
    53     $parameters['auto_start'] = false; 
    54  
    55     // initialize the parent 
    56     parent::initialize($context, $parameters); 
    57  
    58     if (!$this->getParameterHolder()->has('db_table')) 
    59     { 
    60       // missing required 'db_table' parameter 
    61       throw new sfInitializationException('Factory configuration file is missing required "db_table" parameter for the Storage category.'); 
    62     } 
    63  
    64     // use this object as the session handler 
    65     session_set_save_handler(array($this, 'sessionOpen'), 
    66                              array($this, 'sessionClose'), 
    67                              array($this, 'sessionRead'), 
    68                              array($this, 'sessionWrite'), 
    69                              array($this, 'sessionDestroy'), 
    70                              array($this, 'sessionGC')); 
    71  
    72     // start our session 
    73     session_start(); 
    74   } 
    75  
    76   /** 
    77    * Closes a session. 
    78    * 
    79    * @return boolean true, if the session was closed, otherwise false 
    80    */ 
    81   public function sessionClose() 
    82   { 
    83     // do nothing 
    84     return true; 
    85   } 
    86  
    8725  /** 
    8826   * Destroys a session. 
     
    9735  { 
    9836    // get table/column 
    99     $db_table  = $this->getParameterHolder()->get('db_table'); 
    100     $db_id_col = $this->getParameterHolder()->get('db_id_col', 'sess_id'); 
     37    $db_table  = $this->getParameter('db_table'); 
     38    $db_id_col = $this->getParameter('db_id_col', 'sess_id'); 
    10139 
    10240    // cleanup the session id, just in case 
     
    10644    $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_id_col.' = \''.$id.'\''; 
    10745 
    108     if (@pg_query($this->resource, $sql)) 
     46    if (@pg_query($this->db, $sql)) 
    10947    { 
    11048      return true; 
     
    11250 
    11351    // failed to destroy session 
    114     throw new sfDatabaseException(sprintf('PostgreSQLSessionStorage cannot destroy session id "%s".', $id)); 
     52    throw new sfDatabaseException(sprintf('sfPostgreSQLSessionStorage cannot destroy session id "%s".', $id)); 
    11553  } 
    11654 
     
    12664  public function sessionGC($lifetime) 
    12765  { 
    128     // determine deletable session time 
    129     $time = time() - $lifetime; 
    130  
    13166    // get table/column 
    132     $db_table    = $this->getParameterHolder()->get('db_table'); 
    133     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); 
     67    $db_table    = $this->getParameter('db_table'); 
     68    $db_time_col = $this->getParameter('db_time_col', 'sess_time'); 
    13469 
    13570    // delete the record associated with this id 
    136     $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_time_col.' < '.$lifetime
     71    $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_time_col.' < '.(time() - $lifetime)
    13772 
    138     if (@pg_query($this->resource, $sql)) 
     73    if (!@pg_query($this->db, $sql)) 
    13974    { 
    140       return true
     75      throw new sfDatabaseException('sfPostgreSQLSessionStorage cannot delete old sessions.')
    14176    } 
    142  
    143     // failed to cleanup old sessions 
    144     throw new sfDatabaseException('PostgreSQLSessionStorage cannot delete old sessions.'); 
    145   } 
    146  
    147   /** 
    148    * Opens a session. 
    149    * 
    150    * @param string 
    151    * @param string 
    152    * 
    153    * @return boolean true, if the session was opened, otherwise an exception is thrown 
    154    * 
    155    * @throws <b>sfDatabaseException</b> If a connection with the database does 
    156    *                                  not exist or cannot be created 
    157    */ 
    158   public function sessionOpen($path, $name) 
    159   { 
    160     // what database are we using? 
    161     $database = $this->getParameterHolder()->get('database', 'default'); 
    162  
    163     // get the database resource 
    164     $this->resource = $this->context->getDatabaseManager()->getDatabase($database)->getResource(); 
    16577 
    16678    return true; 
     
    17991  { 
    18092    // get table/column 
    181     $db_table    = $this->getParameterHolder()->get('db_table'); 
    182     $db_data_col = $this->getParameterHolder()->get('db_data_col', 'sess_data'); 
    183     $db_id_col   = $this->getParameterHolder()->get('db_id_col', 'sess_id'); 
    184     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); 
     93    $db_table    = $this->getParameter('db_table'); 
     94    $db_data_col = $this->getParameter('db_data_col', 'sess_data'); 
     95    $db_id_col   = $this->getParameter('db_id_col', 'sess_id'); 
     96    $db_time_col = $this->getParameter('db_time_col', 'sess_time'); 
    18597 
    18698    // cleanup the session id, just in case 
     
    188100 
    189101    // delete the record associated with this id 
    190     $sql = 'SELECT '.$db_data_col.' ' . 
    191            'FROM '.$db_table.' ' . 
    192            'WHERE '.$db_id_col.' = \''.$id.'\''; 
     102    $sql = 'SELECT '.$db_data_col.' FROM '.$db_table.' WHERE '.$db_id_col.' = \''.$id.'\''; 
    193103 
    194     $result = @pg_query($this->resource, $sql); 
     104    $result = @pg_query($this->db, $sql); 
    195105 
    196106    if ($result != false && @pg_num_rows($result) == 1) 
     
    204114    { 
    205115      // session does not exist, create it 
    206       $sql = 'INSERT INTO '.$db_table.' ('.$db_id_col.', ' . 
    207              $db_data_col.', '.$db_time_col.') VALUES (' . 
    208              '\''.$id.'\', \'\', '.time().')'; 
     116      $sql = 'INSERT INTO '.$db_table.' ('.$db_id_col.', '.$db_data_col.', '.$db_time_col.') VALUES (\''.$id.'\', \'\', '.time().')'; 
    209117 
    210       if (@pg_query($this->resource, $sql)) 
     118      if (@pg_query($this->db, $sql)) 
    211119      { 
    212120        return ''; 
     
    214122 
    215123      // can't create record 
    216       throw new sfDatabaseException(sprintf('PostgreSQLSessionStorage cannot create new record for id "%s".', $id)); 
     124      throw new sfDatabaseException(sprintf('sfPostgreSQLSessionStorage cannot create new record for id "%s".', $id)); 
    217125    } 
    218126  } 
     
    231139  { 
    232140    // get table/column 
    233     $db_table    = $this->getParameterHolder()->get('db_table'); 
    234     $db_data_col = $this->getParameterHolder()->get('db_data_col', 'sess_data'); 
    235     $db_id_col   = $this->getParameterHolder()->get('db_id_col', 'sess_id'); 
    236     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time'); 
     141    $db_table    = $this->getParameter('db_table'); 
     142    $db_data_col = $this->getParameter('db_data_col', 'sess_data'); 
     143    $db_id_col   = $this->getParameter('db_id_col', 'sess_id'); 
     144    $db_time_col = $this->getParameter('db_time_col', 'sess_time'); 
    237145 
    238146    // cleanup the session id and data, just in case 
     
    241149 
    242150    // delete the record associated with this id 
    243     $sql = 'UPDATE '.$db_table.' '. 
    244            'SET '.$db_data_col.' = \''.$data.'\', '. 
    245            $db_time_col.' = '.time().' '. 
    246            'WHERE '.$db_id_col.' = \''.$id.'\''; 
     151    $sql = 'UPDATE '.$db_table.' SET '.$db_data_col.' = \''.$data.'\', '.$db_time_col.' = '.time().' WHERE '.$db_id_col.' = \''.$id.'\''; 
    247152 
    248     if (@pg_query($this->resource, $sql)) 
     153    if (@pg_query($this->db, $sql)) 
    249154    { 
    250155      return true; 
     
    252157 
    253158    // failed to write session data 
    254     throw new sfDatabaseException(sprintf('PostgreSQLSessionStorage cannot write session data for id "%s".', $id)); 
    255   } 
    256  
    257   /** 
    258    * Executes the shutdown procedure. 
    259    * 
    260    */ 
    261   public function shutdown() 
    262   { 
     159    throw new sfDatabaseException(sprintf('sfPostgreSQLSessionStorage cannot write session data for id "%s".', $id)); 
    263160  } 
    264161} 
  • trunk/lib/storage/sfSessionStorage.class.php

    r4887 r4890  
    2929   * Initializes this Storage instance. 
    3030   * 
    31    * @param sfContext A sfContext instance 
    3231   * @param array   An associative array of initialization parameters 
    3332   * 
     
    3635   * @throws <b>sfInitializationException</b> If an error occurs while initializing this Storage 
    3736   */ 
    38   public function initialize($context, $parameters = null) 
     37  public function initialize($parameters = null) 
    3938  { 
    4039    // initialize parent 
    41     parent::initialize($context, $parameters); 
     40    parent::initialize($parameters); 
    4241 
    4342    // set session name 
    44     $sessionName = $this->getParameterHolder()->get('session_name', 'symfony'); 
     43    $sessionName = $this->getParameter('session_name', 'symfony'); 
    4544 
    4645    session_name($sessionName); 
     
    4847    if (!(boolean) ini_get('session.use_cookies')) 
    4948    { 
    50       $sessionId = $context->getRequest()->getParameter($sessionName, ''); 
    51  
    52       if ($sessionId != '') 
     49      if ($sessionId = $this->getParameter('session_id')) 
    5350      { 
    5451        session_id($sessionId); 
     
    8784   * @return mixed Data associated with the key 
    8885   */ 
    89   public function & read($key) 
     86  public function read($key) 
    9087  { 
    9188    $retval = null; 
     
    9390    if (isset($_SESSION[$key])) 
    9491    { 
    95       $retval =& $_SESSION[$key]; 
     92      $retval = $_SESSION[$key]; 
    9693    } 
    9794 
     
    108105   * @return mixed Data associated with the key 
    109106   */ 
    110   public function & remove($key) 
     107  public function remove($key) 
    111108  { 
    112109    $retval = null; 
     
    114111    if (isset($_SESSION[$key])) 
    115112    { 
    116       $retval =& $_SESSION[$key]; 
     113      $retval = $_SESSION[$key]; 
    117114      unset($_SESSION[$key]); 
    118115    } 
     
    130127   * 
    131128   */ 
    132   public function write($key, &$data) 
     129  public function write($key, $data) 
    133130  { 
    134     $_SESSION[$key] =& $data; 
     131    $_SESSION[$key] = $data; 
    135132  } 
    136133 
  • trunk/lib/storage/sfSessionTestStorage.class.php

    r3329 r4890  
    2121  protected 
    2222    $sessionId   = null, 
    23     $sessionData = array(), 
    24     $sessionPath = null; 
     23    $sessionData = array(); 
    2524 
    2625  /** 
    2726   * Initializes this Storage instance. 
    2827   * 
    29    * @param sfContext A sfContext instance 
    3028   * @param array   An associative array of initialization parameters 
    3129   * 
     
    3432   * @throws <b>sfInitializationException</b> If an error occurs while initializing this Storage 
    3533   */ 
    36   public function initialize($context, $parameters = null) 
     34  public function initialize($parameters = null) 
    3735  { 
    3836    // initialize parent 
    39     parent::initialize($context, $parameters); 
     37    parent::initialize($parameters); 
    4038 
    41     $this->sessionPath = sfConfig::get('sf_test_cache_dir').DIRECTORY_SEPARATOR.'sessions'; 
     39    if (!$this->getParameter('session_path')) 
     40    { 
     41      throw new sfInitializationException('Factory configuration file is missing required "session_path" parameter for the "storage" category.'); 
     42    } 
    4243 
    4344    if (array_key_exists('session_id', $_SERVER)) 
     
    4647 
    4748      // we read session data from temp file 
    48       $file = $this->sessionPath.DIRECTORY_SEPARATOR.$this->sessionId.'.session'; 
     49      $file = $this->getParameter('session_path').DIRECTORY_SEPARATOR.$this->sessionId.'.session'; 
    4950      $this->sessionData = file_exists($file) ? unserialize(file_get_contents($file)) : array(); 
    5051    } 
     
    7576   * @return mixed Data associated with the key 
    7677   */ 
    77   public function & read($key) 
     78  public function read($key) 
    7879  { 
    7980    $retval = null; 
     
    8182    if (isset($this->sessionData[$key])) 
    8283    { 
    83       $retval =& $this->sessionData[$key]; 
     84      $retval = $this->sessionData[$key]; 
    8485    } 
    8586 
     
    9697   * @return mixed Data associated with the key 
    9798   */ 
    98   public function & remove($key) 
     99  public function remove($key) 
    99100  { 
    100101    $retval = null; 
     
    102103    if (isset($this->sessionData[$key])) 
    103104    { 
    104       $retval =& $this->sessionData[$key]; 
     105      $retval = $this->sessionData[$key]; 
    105106      unset($this->sessionData[$key]); 
    106107    } 
     
    118119   * 
    119120   */ 
    120   public function write($key, &$data) 
     121  public function write($key, $data) 
    121122  { 
    122     $this->sessionData[$key] =& $data; 
     123    $this->sessionData[$key] = $data; 
    123124  } 
    124125 
     
    128129  public function clear() 
    129130  { 
    130     sfToolkit::clearDirectory($this->sessionPath); 
     131    sfToolkit::clearDirectory($this->getParameter('session_path')); 
    131132  } 
    132133 
     
    140141    { 
    141142      $current_umask = umask(0000); 
    142       if (!is_dir($this->sessionPath)) 
     143      if (!is_dir($this->getParameter('session_path'))) 
    143144      { 
    144         mkdir($this->sessionPath, 0777, true); 
     145        mkdir($this->getParameter('session_path'), 0777, true); 
    145146      } 
    146147      umask($current_umask); 
    147       file_put_contents($this->sessionPath.DIRECTORY_SEPARATOR.$this->sessionId.'.session', serialize($this->sessionData)); 
     148      file_put_contents($this->getParameter('session_path').DIRECTORY_SEPARATOR.$this->sessionId.'.session', serialize($this->sessionData)); 
    148149      $this->sessionId   = ''; 
    149150      $this->sessionData = array(); 
  • trunk/lib/storage/sfStorage.class.php

    r4597 r4890  
    2222{ 
    2323  protected 
    24     $parameterHolder = null, 
    25     $context         = null; 
    26  
    27   /** 
    28    * Retrieves the current application context. 
    29    * 
    30    * @return sfContext A sfContext instance 
    31    */ 
    32   public function getContext() 
    33   { 
    34     return $this->context; 
    35   } 
     24    $parameterHolder = null; 
    3625 
    3726  /** 
    3827   * Initializes this Storage instance. 
    3928   * 
    40    * @param sfContext A sfContext instance 
    4129   * @param array   An associative array of initialization parameters 
    4230   * 
     
    4533   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfStorage 
    4634   */ 
    47   public function initialize($context, $parameters = array()) 
     35  public function initialize($parameters = array()) 
    4836  { 
    49     $this->context = $context; 
    50  
    5137    $this->parameterHolder = new sfParameterHolder(); 
    5238    $this->getParameterHolder()->add($parameters); 
     
    8571   * @throws <b>sfStorageException</b> If an error occurs while reading data from this storage 
    8672   */ 
    87   abstract function & read($key); 
     73  abstract public function read($key); 
    8874 
    8975  /** 
     
    9884   * @throws <b>sfStorageException</b> If an error occurs while removing data from this storage 
    9985   */ 
    100   abstract function & remove($key); 
     86  abstract public function remove($key); 
    10187 
    10288  /** 
     
    10591   * @throws <b>sfStorageException</b> If an error occurs while shutting down this storage 
    10692   */ 
    107   abstract function shutdown(); 
     93  abstract public function shutdown(); 
    10894 
    10995  /** 
     
    117103   * @throws <b>sfStorageException</b> If an error occurs while writing to this storage 
    118104   */ 
    119   abstract function write($key, &$data); 
     105  abstract public function write($key, $data); 
    120106 
    121107  /** 
  • trunk/test/functional/fixtures/project/apps/backend/config/factories.yml

    r2217 r4890  
    88  storage: 
    99    class: sfSessionTestStorage 
     10    param: 
     11      session_path: %SF_TEST_CACHE_DIR%/sessions 
    1012 
    1113all: 
  • trunk/test/functional/fixtures/project/apps/cache/config/factories.yml

    r2169 r4890  
    88  storage: 
    99    class: sfSessionTestStorage 
     10    param: 
     11      session_path: %SF_TEST_CACHE_DIR%/sessions 
    1012 
    1113all: 
  • trunk/test/functional/fixtures/project/apps/crud/config/factories.yml

    r2126 r4890  
    88  storage: 
    99    class: sfSessionTestStorage 
     10    param: 
     11      session_path: %SF_TEST_CACHE_DIR%/sessions 
    1012 
    1113all: 
  • trunk/test/functional/fixtures/project/apps/frontend/config/factories.yml

    r2069 r4890  
    88  storage: 
    99    class: sfSessionTestStorage 
     10    param: 
     11      session_path: %SF_TEST_CACHE_DIR%/sessions 
    1012 
    1113all: 
  • trunk/test/functional/fixtures/project/apps/i18n/config/factories.yml

    r2740 r4890  
    88  storage: 
    99    class: sfSessionTestStorage 
     10    param: 
     11      session_path: %SF_TEST_CACHE_DIR%/sessions 
    1012 
    1113all: 
  • trunk/test/unit/sfContextMock.class.php

    r4440 r4890  
    2929 
    3030      self::$instance->storage = sfStorage::newInstance('sfSessionTestStorage'); 
    31       self::$instance->storage->initialize(self::$instance); 
     31      self::$instance->storage->initialize(array('session_path' => sfConfig::get('sf_test_cache_dir').'/sessions')); 
    3232 
    3333      foreach ($factories as $type => $class) 
  • trunk/test/unit/storage/sfStorageTest.php

    r4440 r4890  
    1010 
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    12 require_once($_test_dir.'/unit/sfContextMock.class.php'); 
    1312 
    14 $t = new lime_test(19, new lime_output_color()); 
     13$t = new lime_test(17, new lime_output_color()); 
    1514 
    1615class myStorage extends sfStorage 
    1716{ 
    18   function & read($key) {} 
    19   function & remove($key) {} 
    20   function shutdown() {} 
    21   function write($key, &$data) {} 
     17  public function read($key) {} 
     18  public function remove($key) {} 
     19  public function shutdown() {} 
     20  public function write($key, $data) {} 
    2221} 
    2322 
     
    2524{ 
    2625} 
    27  
    28 $context = sfContext::getInstance(array('storage' => 'myStorage')); 
    2926 
    3027// ::newInstance() 
     
    4643$t->diag('->initialize()'); 
    4744$storage = sfStorage::newInstance('myStorage'); 
    48 $t->is($storage->getContext(), null, '->initialize() takes a sfContext object as its first argument'); 
    49 $storage->initialize($context, array('foo' => 'bar')); 
     45$storage->initialize(array('foo' => 'bar')); 
    5046$t->is($storage->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument'); 
    5147 
    5248$storage = new myStorage(); 
    53 $storage->initialize($context); 
    54  
    55 // ->getContext() 
    56 $t->diag('->getContext()'); 
    57 $storage->initialize($context); 
    58 $t->is($storage->getContext(), $context, '->getContext() returns the current context'); 
     49$storage->initialize(); 
    5950 
    6051// parameter holder proxy 
  • trunk/test/unit/user/sfUserTest.php

    r4440 r4890  
    6969  $context->getUser()->shutdown(); 
    7070  $context->getUser()->initialize($context); 
     71  $parameters = $context->getStorage()->getParameterHolder()->getAll(); 
    7172  $context->getStorage()->shutdown(); 
    72   $context->getStorage()->initialize($context); 
     73  $context->getStorage()->initialize($parameters); 
    7374} 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.