Beispiel #1
0
 /**
  * addMessage() - Add a message to flash message
  *
  * @param  string $message
  * @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
  */
 public function addMessage($message)
 {
     if (self::$_messageAdded === false) {
         self::$_session->setExpirationHops(1, null, true);
     }
     if (!is_array(self::$_session->{$this->_namespace})) {
         self::$_session->{$this->_namespace} = array();
     }
     self::$_session->{$this->_namespace}[] = $message;
     return $this;
 }
Beispiel #2
0
 /**
  * addMessage() - Add a message to flash message
  *
  * @param  string $message
  * @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
  */
 public function addMessage($message, $namespace = null)
 {
     if (!is_string($namespace) || $namespace == '') {
         $namespace = $this->getNamespace();
     }
     if (self::$_messageAdded === false) {
         self::$_session->setExpirationHops(1, null, true);
     }
     if (!is_array(self::$_session->{$namespace})) {
         self::$_session->{$namespace} = array();
     }
     self::$_session->{$namespace}[] = $message;
     self::$_messageAdded = true;
     return $this;
 }
Beispiel #3
0
 /**
  * addVar() - Add a message to flash message
  *
  * @param  string $var
  * @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
  */
 public function addVar($var, $name = false)
 {
     if (self::$_varAdded === false) {
         self::$_session->setExpirationHops(1, null, true);
     }
     if (!is_array(self::$_session->{$this->_namespace})) {
         self::$_session->{$this->_namespace} = array();
     }
     if ($name) {
         self::$_session->{$this->_namespace}[$name] = $var;
     } else {
         self::$_session->{$this->_namespace}[] = $var;
     }
     return $this;
 }
 /**
  * setMessage() - method set message and type
  *
  * @param string $type
  * @param string $message
  * @param mixed $value
  * @param int $len
  * @return \Extlib\Controller\Action\Helper\FlashMessage
  */
 public function setMessage($type, $message, $value = null, $len = 25)
 {
     if (!in_array(strtolower($type), self::$_allowedTypes)) {
         throw new \Zend_Controller_Action_Exception('Incorrect type of message!');
     }
     if (!\Zend_Validate::is($len, 'Int')) {
         throw new \Zend_Controller_Action_Exception("Param 'len' must be a int value!");
     }
     if (null !== $this->_translator) {
         $message = $this->_translator->translate($message);
     }
     if (null !== $value) {
         if (strlen($value) > $len) {
             $value = mb_substr($value, 0, $len, 'UTF-8') . '..';
         }
         $message = str_replace(self::VALUE_PATTERN, $value, $message);
     }
     self::$_session->setExpirationHops(1, null, true);
     self::$_session->{$this->_namespace} = array(strtolower($type) => $message);
     self::$_messageAdded = true;
     return $this;
 }
 /**
  * test expiration of namespace variables by hops
  * expect expiration of specified keys in the proper number of hops
  */
 public function testSetExpireSessionVarsByHopsOnUse()
 {
     $s = new Zend_Session('expireGuava');
     $expireBeforeHop = 2;
     $s->setExpirationHops($expireBeforeHop, 'g', true);
     // only count a hop, when namespace is used
     $s->g = 'guava';
     $s->p = 'peach';
     $s->p = 'plum';
     $id = session_id();
     session_write_close();
     // release session so process below can use it
     // we are not accessing (using) the "expireGuava" namespace, so these hops should have no effect
     for ($i = 1; $i <= $expireBeforeHop + 2; $i++) {
         exec($this->script . "expireAll {$id} notused", $result);
         $result = $this->sortResult($result);
         $this->assertTrue($result === '', "iteration over named Zend_Session namespace failed (result='{$result}'; hop #{$i})");
     }
     for ($i = 1; $i <= $expireBeforeHop + 2; $i++) {
         exec($this->script . "expireAll {$id} expireGuava", $result);
         $result = $this->sortResult($result);
         if ($i > $expireBeforeHop) {
             $expect = ';p === plum';
             $this->assertTrue($result === $expect, "unexpected results iterating over named Zend_Session namespace (result='{$result}'; expected '{$expect}'; hop #{$i})");
         } else {
             $expect = ';g === guava;p === plum';
             $this->assertTrue($result === $expect, "unexpected results iterating over named Zend_Session namespace (result='{$result}'; expected '{$expect}'; hop #{$i})");
         }
     }
     session_start();
     // resume artificially suspended session
     $core = Zend_Session_Core::getInstance();
     $core->destroy();
 }
 /**
  * test expiration of namespace variables by hops
  * expect expiration of specified keys in the proper number of hops
  */
 public function setExpireSessionVarsByHops()
 {
     $s = new Zend_Session('expireGuava');
     $expireBeforeHop = 4;
     $s->setExpirationHops($expireBeforeHop, 'g');
     $s->g = 'guava';
     $s->p = 'peach';
     $s->p = 'plum';
     $id = session_id();
     session_write_close();
     // release session so process below can use it
     for ($i = 1; $i <= $expireBeforeHop + 2; $i++) {
         exec($this->script . "expireAll {$id} expireGuava", $result);
         $result = $this->sortResult($result);
         if ($i > $expireBeforeHop) {
             $this->assertTrue($result === ';p === plum', "iteration over named Zend_Session namespace failed (result='{$result}'; hop #{$i})");
         } else {
             $this->assertTrue($result === ';g === guava;p === plum', "iteration over named Zend_Session namespace failed (result='{$result}'; hop #{$i})");
         }
     }
     session_start();
     // resume artificially suspended session
 }