public function tearDown()
 {
     if (isset($this->savePath)) {
         Zend_Session::setOptions(array('save_path' => $this->savePath));
         unset($this->savePath);
     }
     $old = error_reporting(E_ALL | E_STRICT);
     $this->assertTrue($old === error_reporting(E_ALL | E_STRICT), 'something associated with a particular test altered error_reporting to something other than E_STRICT');
     restore_error_handler();
     Zend_Session_Namespace::unlockAll();
     // @todo: cleanup
     if (count($this->error_list)) {
         echo "**** Errors: ";
         print_r($this->error_list);
     }
     // unset all namespaces
     foreach (Zend_Session::getIterator() as $space) {
         try {
             Zend_Session::namespaceUnset($space);
         } catch (Zend_Session_Exception $e) {
             $this->assertRegexp('/read.only/i', $e->getMessage());
             return;
         }
     }
 }
Exemple #2
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     /**
      * Pegando o helper Redirector
      */
     $this->_redirect = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
     /*
      * Instanciando as variáveis de sessão do zend_auth
      */
     $authNamespace = new Zend_Session_Namespace('Zend_Auth');
     /**
      * Copiando em variáves o modulo, controlle e action
      */
     $module = strtolower($request->getModuleName());
     $controller = strtolower($request->getControllerName());
     $action = strtolower($request->getActionName());
     /**
      * Se o usuário estiver autenticado
      */
     if (Zend_Auth::getInstance()->hasIdentity()) {
         if (isset($authNamespace->timeout) && time() > $authNamespace->timeout) {
             /**
              * limpa a identidade do usuário que está um longo período sem acessar o controller
              */
             $request->setModuleName('default');
             $request->setControllerName('login');
             $request->setActionName('logout');
             $authNamespace->erro = 'Sua sessão expirou, favor logar novamente';
         } else {
             /**
              *  Usuário está ativo - atualizamos o time da sessão.
              */
             $authNamespace->timeout = strtotime(self::$_ZEND_SESSION_NAMESPACE_EXPIRATION_SECONDS . " seconds");
             /**
              * Renovando o timeout das variáves de sessão
              */
             $namesspaces = Zend_Session::getIterator();
             $namesspacesArrayCopy = $namesspaces->getArrayCopy();
             foreach ($namesspacesArrayCopy as $namesspace) {
                 $namesspace_each = new Zend_Session_Namespace($namesspace);
                 //$namesspace_each->setExpirationSeconds(self::$_ZEND_SESSION_NAMESPACE_EXPIRATION_SECONDS);
                 $namesspace_each->timeout = strtotime(self::$_ZEND_SESSION_NAMESPACE_EXPIRATION_SECONDS . " seconds");
                 $temp = $namesspace_each->timeout;
             }
         }
     }
     /** Se o usuário não possuir identidade ou a identidade foi removida devido ao timeout,
      * redirecionamos ele para a tela de login.
      */
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         if (!($module == 'default' && $controller == 'login' && $action == 'index') && !($module == 'default' && $controller == 'login' && $action == 'ajaxbanco')) {
             $request->setModuleName('default');
             $request->setControllerName('login');
             $request->setActionName('index');
             $request->setParam('sessao', 'expirada');
         }
         return;
     }
 }
Exemple #3
0
 /**
  * Cleanup operations after each test method is run
  *
  * @return void
  */
 public function tearDown()
 {
     ini_set('session.save_path', $this->_savePath);
     $this->assertSame(E_ALL | E_STRICT, error_reporting(E_ALL | E_STRICT), 'A test altered error_reporting to something other than E_ALL | E_STRICT');
     Zend_Session_Namespace::unlockAll();
     // unset all namespaces
     foreach (Zend_Session::getIterator() as $space) {
         try {
             Zend_Session::namespaceUnset($space);
         } catch (Zend_Session_Exception $e) {
             $this->assertRegexp('/read.only/i', $e->getMessage());
             return;
         }
     }
 }
 public function _ZF_expireAll($args)
 {
     Zend_Session_Core::setOptions(array('remember_me_seconds' => 15, 'gc_probability' => 2));
     session_id($args[0]);
     if (isset($args[1]) && !empty($args[1])) {
         $s = new Zend_Session($args[1]);
     } else {
         $s = new Zend_Session();
     }
     $result = '';
     foreach ($s->getIterator() as $key => $val) {
         $result .= "{$key} === {$val};";
     }
     $core = Zend_Session_Core::getInstance();
     $core->expireSessionCookie();
     $core->writeClose();
     echo $result;
 }
Exemple #5
0
 /**
  * 登録済み名前空間をすべて取得
  *
  * @static
  * @access public
  */
 public static function getIterator()
 {
     return parent::getIterator();
 }
 /**
  * test unsetAll keys in default namespace
  * expect namespace will contain no keys
  */
 public function testUnsetAllNamespace()
 {
     $s = new Zend_Session('somenamespace');
     $result = '';
     foreach ($s->getIterator() as $key => $val) {
         $result .= "{$key} === {$val};";
     }
     $this->assertTrue(empty($result), "tearDown failure, found keys in 'somenamespace' namespace: '{$result}'");
     $s->a = 'apple';
     $s->lock();
     $s->unlock();
     $s->p = 'papaya';
     $s->c = 'cherry';
     $s = new Zend_Session('somenamespace');
     $result = '';
     foreach ($s->getIterator() as $key => $val) {
         $result .= "{$key} === {$val};";
     }
     $this->assertTrue($result === 'a === apple;p === papaya;c === cherry;', "unsetAll() setup for test failed: '{$result}'");
     $s->unsetAll();
     $result = '';
     foreach ($s->getIterator() as $key => $val) {
         $result .= "{$key} === {$val};";
     }
     $this->assertTrue(empty($result), "unsetAll() did not remove keys from namespace: '{$result}'");
 }