Ejemplo n.º 1
0
 function start()
 {
     if (self::$started) {
         return;
     } elseif (self::$started === NULL && defined('SID')) {
         throw new InvalidStateException('A session had already been started by session.auto-start or session_start().');
     }
     $this->configure($this->options);
     NDebug::tryError();
     session_start();
     if (NDebug::catchError($e)) {
         @session_write_close();
         throw new InvalidStateException($e->getMessage());
     }
     self::$started = TRUE;
     if ($this->regenerationNeeded) {
         session_regenerate_id(TRUE);
         $this->regenerationNeeded = FALSE;
     }
     unset($_SESSION['__NT'], $_SESSION['__NS'], $_SESSION['__NM']);
     $nf =& $_SESSION['__NF'];
     if (empty($nf)) {
         $nf = array('C' => 0);
     } else {
         $nf['C']++;
     }
     $browserKey = $this->getHttpRequest()->getCookie('nette-browser');
     if (!$browserKey) {
         $browserKey = (string) lcg_value();
     }
     $browserClosed = !isset($nf['B']) || $nf['B'] !== $browserKey;
     $nf['B'] = $browserKey;
     $this->sendCookie();
     if (isset($nf['META'])) {
         $now = time();
         foreach ($nf['META'] as $namespace => $metadata) {
             if (is_array($metadata)) {
                 foreach ($metadata as $variable => $value) {
                     if (!empty($value['B']) && $browserClosed || !empty($value['T']) && $now > $value['T'] || $variable !== '' && is_object($nf['DATA'][$namespace][$variable]) && (isset($value['V']) ? $value['V'] : NULL) !== NClassReflection::from($nf['DATA'][$namespace][$variable])->getAnnotation('serializationVersion')) {
                         if ($variable === '') {
                             unset($nf['META'][$namespace], $nf['DATA'][$namespace]);
                             continue 2;
                         }
                         unset($nf['META'][$namespace][$variable], $nf['DATA'][$namespace][$variable]);
                     }
                 }
             }
         }
     }
     register_shutdown_function(array($this, 'clean'));
 }