public function setUp() { $savePath = ini_get('session.save_path'); if (strpos($savePath, ';')) { $savePath = explode(';', $savePath); $savePath = array_pop($savePath); } if (empty($savePath)) { $this->markTestSkipped('Cannot test FlashMessenger due to unavailable session save path'); } if (headers_sent()) { $this->markTestSkipped('Cannot test FlashMessenger: cannot start session because headers already sent'); } \Zend\Session\Manager::start(); $this->front = \Zend\Controller\Front::getInstance(); $this->front->resetInstance(); $this->front->setControllerDirectory(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . '_files'); $this->front->returnResponse(true); $this->request = new \Zend\Controller\Request\Http(); $this->request->setControllerName('helper-flash-messenger'); $this->response = new \Zend\Controller\Response\Cli(); $this->controller = new \HelperFlashMessengerController($this->request, $this->response, array()); $this->helper = new \Zend\Controller\Action\Helper\FlashMessenger($this->controller); }
/** * 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; }
/** * 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 (!isset(self::$_session->{$this->_namespace}) || !self::$_session->{$this->_namespace} instanceof SplQueue) { self::$_session->{$this->_namespace} = new SplQueue(); } self::$_session->{$this->_namespace}->push($message); return $this; }
/** * exit(): Perform exit for redirector * * @return void */ public function redirectAndExit() { if ($this->getCloseSessionOnExit()) { // Close session, if started if (class_exists('Zend_Session', false) && Session\Manager::isStarted()) { Session\Manager::writeClose(); } elseif (isset($_SESSION)) { session_write_close(); } } $this->getResponse()->sendHeaders(); exit; }