FlashMessageService.php 1.44 KB
Newer Older
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
9
10
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
11
 *
12
13
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
16
 * The TYPO3 project - inspiring people to share!
 */
Wouter Wolters's avatar
Wouter Wolters committed
17

18
19
namespace TYPO3\CMS\Core\Messaging;

20
21
22
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

23
24
25
/**
 * A class representing flash messages.
 */
26
class FlashMessageService implements SingletonInterface
27
28
29
30
{
    /**
     * Array of \TYPO3\CMS\Core\Messaging\FlashMessageQueue objects
     *
31
     * @var FlashMessageQueue[]
32
     */
33
    protected $flashMessageQueues = [];
34

35
36
37
38
39
    /**
     * Return the message queue for the given identifier.
     * If no queue exists, an empty one will be created.
     *
     * @param string $identifier
40
     * @return FlashMessageQueue
41
     */
42
    public function getMessageQueueByIdentifier($identifier = FlashMessageQueue::FLASHMESSAGE_QUEUE): FlashMessageQueue
43
44
    {
        if (!isset($this->flashMessageQueues[$identifier])) {
45
46
            $this->flashMessageQueues[$identifier] = GeneralUtility::makeInstance(
                FlashMessageQueue::class,
47
48
49
50
51
                $identifier
            );
        }
        return $this->flashMessageQueues[$identifier];
    }
52
}