Пример #1
0
 static function read($id)
 {
     if (!isset(self::$session_save_path)) {
         self::$session_save_path = self::savePath();
     }
     if (!empty(self::$session_db_connection)) {
         self::gc(ini_get('session.gc_maxlifetime'));
         $session_db_id_field = self::$session_db_id_field;
         $session_db_data_field = self::$session_db_data_field;
         $rows = self::$session_db->select('*', self::$session_db_table)->where(array(self::$session_db_id_field => $id))->limit(1)->fetchDbRows(self::$session_db_row_class);
         if (count($rows) > 0) {
             // Store the row from session table, to update later
             self::$session_db_row = $rows[0];
             return (string) self::$session_db_row->{$session_db_data_field};
         } else {
             // Create a new row to be saved in the session table
             $db_row_class = self::$db_row_class;
             self::$session_db_row = new $db_row_class();
             // Make sure it has a primary key!
             if (count(self::$session_db_row->getPrimaryKey) != 1) {
                 trigger_error("The primary key of " . self::$session_db_row_class . " has to consist of exactly 1 field!", E_WARNING);
             }
             self::$session_db_row->{$session_db_id_field} = $id;
             return '';
             // empty session. We return empty string instead of NULL.
         }
     } else {
         $sess_file = self::$session_save_path . "/sess_{$id}";
         if (!file_exists($sess_file)) {
             return null;
         }
         return (string) file_get_contents($sess_file);
     }
 }