[TASK] Update t3lib mentions
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Mvc / Controller / FlashMessageContainer.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Mvc\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
8 * Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * This is a container for all Flash Messages. It is of scope session, but as Extbase
32 * has no session scope, we need to save it manually.
33 *
34 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
35 * @api
36 */
37 class FlashMessageContainer implements \TYPO3\CMS\Core\SingletonInterface {
38
39 /**
40 * @var \TYPO3\CMS\Core\Messaging\FlashMessageQueue Default queue
41 */
42 protected $flashMessageQueue = NULL;
43
44 /**
45 * Constructor
46 */
47 public function __construct() {
48 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
49 $flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
50 'TYPO3\\CMS\\Core\\Messaging\\FlashMessageService'
51 );
52 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
53 $this->flashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
54 }
55
56 /**
57 * Add another flash message.
58 * Severity can be specified and must be one of
59 * \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE,
60 * \TYPO3\CMS\Core\Messaging\FlashMessage::INFO,
61 * \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
62 * \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
63 * \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
64 *
65 * @param string $message
66 * @param string $title optional message title
67 * @param integer $severity optional severity code. One of the \TYPO3\CMS\Core\Messaging\FlashMessage constants
68 * @throws \InvalidArgumentException
69 * @return void
70 * @api
71 */
72 public function add($message, $title = '', $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK) {
73 if (!is_string($message)) {
74 throw new \InvalidArgumentException(
75 'The flash message must be string, ' . gettype($message) . ' given.',
76 1243258395
77 );
78 }
79 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
80 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
81 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, $title, $severity, TRUE
82 );
83 $this->flashMessageQueue->enqueue($flashMessage);
84 }
85
86 /**
87 * Get all flash messages currently available.
88 *
89 * @return array<\TYPO3\CMS\Core\Messaging\FlashMessage> An array of flash messages
90 * @api
91 */
92 public function getAllMessages() {
93 return $this->flashMessageQueue->getAllMessages();
94 }
95
96 /**
97 * Reset all flash messages.
98 *
99 * @return void
100 * @api
101 */
102 public function flush() {
103 $this->flashMessageQueue->getAllMessagesAndFlush();
104 }
105
106 /**
107 * Get all flash messages currently available. And removes them from the session.
108 *
109 * @return array<\TYPO3\CMS\Core\Messaging\FlashMessage> An array of flash messages
110 * @api
111 */
112 public function getAllMessagesAndFlush() {
113 return $this->flashMessageQueue->getAllMessagesAndFlush();
114 }
115 }
116
117 ?>