1<?php 2namespace Fisharebest\Webtrees; 3 4/** 5 * webtrees: online genealogy 6 * Copyright (C) 2015 webtrees development team 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19use Zend_Controller_Action_HelperBroker; 20 21/** 22 * Class FlashMessages - Flash messages allow us to generate messages 23 * in one context, and display them in another. 24 */ 25class FlashMessages { 26 /** 27 * Add a new message to the session storage. 28 * 29 * @param string $text 30 * @param string $status "success", "info", "warning" or "danger" 31 */ 32 public static function addMessage($text, $status = 'info') { 33 $message = new \stdClass; 34 $message->text = $text; 35 $message->status = $status; 36 $flash_messenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); 37 38 $flash_messenger->addMessage($message); 39 } 40 41 /** 42 * Get the current messages, and remove them from session storage. 43 * 44 * @return string[] 45 */ 46 public static function getMessages() { 47 $flash_messenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); 48 49 $messages = array(); 50 51 // Get messages from previous requests 52 foreach ($flash_messenger->getMessages() as $message) { 53 $messages[] = $message; 54 } 55 56 // Get messages from the current request 57 foreach ($flash_messenger->getCurrentMessages() as $message) { 58 $messages[] = $message; 59 } 60 $flash_messenger->clearCurrentMessages(); 61 62 return $messages; 63 } 64} 65