d8b6ec0ac2e07ea4025118754c59f1f8f9dcf326
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / View / BackendLayout / BackendLayoutCollection.php
1 <?php
2 namespace TYPO3\CMS\Backend\View\BackendLayout;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Collection of backend layouts.
19 */
20 class BackendLayoutCollection
21 {
22 /**
23 * @var string
24 */
25 protected $identifier;
26
27 /**
28 * @var array|BackendLayout[]
29 */
30 protected $backendLayouts = [];
31
32 /**
33 * @param string $identifier
34 */
35 public function __construct($identifier)
36 {
37 $this->setIdentifier($identifier);
38 }
39
40 /**
41 * @return string
42 */
43 public function getIdentifier()
44 {
45 return $this->identifier;
46 }
47
48 /**
49 * @param string $identifier
50 * @throws \UnexpectedValueException
51 */
52 public function setIdentifier($identifier)
53 {
54 if (strpos($identifier, '__') !== false) {
55 throw new \UnexpectedValueException(
56 'Identifier "' . $identifier . '" must not contain "__"',
57 1381597631
58 );
59 }
60
61 $this->identifier = $identifier;
62 }
63
64 /**
65 * Adds a backend layout to this collection.
66 *
67 * @param BackendLayout $backendLayout
68 * @throws \LogicException
69 */
70 public function add(BackendLayout $backendLayout)
71 {
72 $identifier = $backendLayout->getIdentifier();
73
74 if (strpos($identifier, '__') !== false) {
75 throw new \UnexpectedValueException(
76 'BackendLayout Identifier "' . $identifier . '" must not contain "__"',
77 1381597628
78 );
79 }
80
81 if (isset($this->backendLayouts[$identifier])) {
82 throw new \LogicException(
83 'Backend Layout ' . $identifier . ' is already defined',
84 1381559376
85 );
86 }
87
88 $this->backendLayouts[$identifier] = $backendLayout;
89 }
90
91 /**
92 * Gets a backend layout by (regular) identifier.
93 *
94 * @param string $identifier
95 * @return NULL|BackendLayout
96 */
97 public function get($identifier)
98 {
99 $backendLayout = null;
100
101 if (isset($this->backendLayouts[$identifier])) {
102 $backendLayout = $this->backendLayouts[$identifier];
103 }
104
105 return $backendLayout;
106 }
107
108 /**
109 * Gets all backend layouts in this collection.
110 *
111 * @return array|BackendLayout[]
112 */
113 public function getAll()
114 {
115 return $this->backendLayouts;
116 }
117 }