|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Copyright (C) 2018 |
|
5
|
|
|
* Nathan Boiron <[email protected]> |
|
6
|
|
|
* Romain Canon <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This file is part of the TYPO3 NotiZ project. |
|
9
|
|
|
* It is free software; you can redistribute it and/or modify it |
|
10
|
|
|
* under the terms of the GNU General Public License, either |
|
11
|
|
|
* version 3 of the License, or any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* For the full copyright and license information, see: |
|
14
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace CuyZ\Notiz\Core\Property\Factory; |
|
18
|
|
|
|
|
19
|
|
|
use CuyZ\Notiz\Core\Exception\EntryNotFoundException; |
|
20
|
|
|
use CuyZ\Notiz\Core\Property\PropertyEntry; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* A container for a list of property entries that are fetched from a property |
|
24
|
|
|
* definition. |
|
25
|
|
|
* |
|
26
|
|
|
* @see \CuyZ\Notiz\Core\Property\Factory\PropertyDefinition |
|
27
|
|
|
* |
|
28
|
|
|
* The differences with a property definition is that you can not add more |
|
29
|
|
|
* entries, you may only modify the data from the existing ones: setting their |
|
30
|
|
|
* values, manipulating other arbitrary data, other... |
|
31
|
|
|
*/ |
|
32
|
|
|
class PropertyContainer |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var PropertyDefinition |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $definition; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var PropertyEntry[] |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $properties = []; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param PropertyDefinition $definition |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct(PropertyDefinition $definition) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->definition = $definition; |
|
50
|
|
|
|
|
51
|
|
|
foreach ($definition->getEntries() as $property) { |
|
52
|
|
|
/* |
|
53
|
|
|
* Every property is cloned, to insure the base property wont be |
|
54
|
|
|
* modified. |
|
55
|
|
|
*/ |
|
56
|
|
|
$this->properties[$property->getName()] = clone $property; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Freezes all registered properties entries. |
|
62
|
|
|
* |
|
63
|
|
|
* @see \CuyZ\Notiz\Core\Property\PropertyEntry::freeze |
|
64
|
|
|
*/ |
|
65
|
|
|
public function freeze() |
|
66
|
|
|
{ |
|
67
|
|
|
foreach ($this->properties as $property) { |
|
68
|
|
|
$property->freeze(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getPropertyType() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->definition->getPropertyType(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param string $name |
|
82
|
|
|
* @return bool |
|
83
|
|
|
*/ |
|
84
|
|
|
public function hasEntry($name) |
|
85
|
|
|
{ |
|
86
|
|
|
return isset($this->properties[$name]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param string $name |
|
91
|
|
|
* @return PropertyEntry |
|
92
|
|
|
* |
|
93
|
|
|
* @throws EntryNotFoundException |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getEntry($name) |
|
96
|
|
|
{ |
|
97
|
|
|
if (false === $this->hasEntry($name)) { |
|
98
|
|
|
throw EntryNotFoundException::propertyEntryNotFound($name, $this->definition->getEventClassName(), $this->getPropertyType(), $this); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $this->properties[$name]; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return PropertyEntry[] |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getEntries() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->properties; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|