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 19/** 20 * Class FlashMessages - Flash messages allow us to generate messages 21 * in one context, and display them in another. 22 */ 23class FlashMessages { 24 /** 25 * Add a new message to the session storage. 26 * 27 * @param string $text 28 * @param string $status "success", "info", "warning" or "danger" 29 */ 30 public static function addMessage($text, $status = 'info') { 31 $message = new \stdClass; 32 $message->text = $text; 33 $message->status = $status; 34 35 $messages = Session::get('flash_messages', array()); 36 $messages[] = $message; 37 Session::put('flash_messages', $messages); 38 } 39 40 /** 41 * Get the current messages, and remove them from session storage. 42 * 43 * @return string[] 44 */ 45 public static function getMessages() { 46 $messages = Session::get('flash_messages', array()); 47 Session::forget('flash_messages'); 48 49 return $messages; 50 } 51} 52