92ffe1f6ae89bc89610b47b5433b3b810ce9690b
[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 text file 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 * This object is deprecated as Extbase uses the FlashMessageService provided
38 * by the core from 6.1 on. Therefore please do not use this object but call
39 * (Abstract)Controller->controllerContext->getFlashMessageQueue() instead.
40 *
41 * For sure you are free to use TYPO3\CMS\Core\Messaging\FlashMessageService
42 * and fetch a custom FlashMessageQueue by calling
43 * FlashMessageQueue->getMessageQueueByIdentifier('customIdentifier')
44 *
45 * @deprecated since Extbase 6.1, will be removed 2 versions later
46 */
47 class FlashMessageContainer implements \TYPO3\CMS\Core\SingletonInterface {
48
49 /**
50 * @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
51 */
52 protected $controllerContext;
53
54 /**
55 * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
56 * @deprecated since 6.1, will be removed 2 versions later
57 */
58 public function setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext) {
59 $this->controllerContext = $controllerContext;
60 }
61
62 /**
63 * Add another flash message.
64 * Severity can be specified and must be one of
65 * \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE,
66 * \TYPO3\CMS\Core\Messaging\FlashMessage::INFO,
67 * \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
68 * \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
69 * \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
70 *
71 * @param string $message
72 * @param string $title optional message title
73 * @param integer $severity optional severity code. One of the \TYPO3\CMS\Core\Messaging\FlashMessage constants
74 * @throws \InvalidArgumentException
75 * @return void
76 * @deprecated since 6.1, will be removed 2 versions later
77 */
78 public function add($message, $title = '', $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK) {
79 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
80 if (!is_string($message)) {
81 throw new \InvalidArgumentException(
82 'The flash message must be string, ' . gettype($message) . ' given.',
83 1243258395
84 );
85 }
86 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
87 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
88 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, $title, $severity, TRUE
89 );
90 $this->controllerContext->getFlashMessageQueue()->enqueue($flashMessage);
91 }
92
93 /**
94 * @return array An array of flash messages: array<\TYPO3\CMS\Core\Messaging\FlashMessage>
95 * @deprecated since 6.1, will be removed 2 versions later
96 */
97 public function getAllMessages() {
98 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
99 return $this->controllerContext->getFlashMessageQueue()->getAllMessages();
100 }
101
102 /**
103 * @return void
104 * @deprecated since 6.1, will be removed 2 versions later
105 */
106 public function flush() {
107 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
108 $this->controllerContext->getFlashMessageQueue()->getAllMessagesAndFlush();
109 }
110
111 /**
112 * @return array An array of flash messages: array<\TYPO3\CMS\Core\Messaging\FlashMessage>
113 * @deprecated since 6.1, will be removed 2 versions later
114 */
115 public function getAllMessagesAndFlush() {
116 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
117 return $this->controllerContext->getFlashMessageQueue()->getAllMessagesAndFlush();
118 }
119 }