1 | <?php |
||
13 | class Manager |
||
14 | { |
||
15 | private $properties = []; |
||
16 | |||
17 | /** |
||
18 | * Add a new property to the stack |
||
19 | * @param string $name the property name |
||
20 | * @param string $type the data type for the property (string, int, bool, etc) |
||
21 | * @param mixed $default the default value, until explicity assigned this is |
||
22 | * the value for the property |
||
23 | */ |
||
24 | 18 | public function addProperty($name, $type = null, $default = null): Property |
|
31 | |||
32 | /** |
||
33 | * Get the property by its name |
||
34 | * |
||
35 | * @param string $name |
||
36 | * @return Property |
||
37 | * @throws Exception if the property doesn't exist |
||
38 | */ |
||
39 | 12 | public function getProperty(string $name): Property |
|
40 | { |
||
41 | 12 | if (!$this->hasProperty($name)) { |
|
42 | 3 | throw new PropertyException('Unknown property "'.$name.'"'); |
|
43 | } |
||
44 | 9 | return $this->properties[$name]; |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Does the manager contain an instance of the property |
||
49 | * based on it's name |
||
50 | * @param string $name property identifier |
||
51 | * @return boolean |
||
52 | */ |
||
53 | 18 | public function hasProperty(string $name): bool |
|
57 | |||
58 | /** |
||
59 | * Remove the property from the manager |
||
60 | * @param string $name |
||
61 | * @return bool |
||
62 | */ |
||
63 | 3 | public function removeProperty(string $name): bool |
|
71 | |||
72 | /** |
||
73 | * Get the value of the property, if it exists |
||
74 | * @param string $name property name |
||
75 | * @return mixed |
||
76 | * @throws Exception if the property doesn't exist |
||
77 | */ |
||
78 | 9 | public function getValue(string $name) |
|
82 | |||
83 | /** |
||
84 | * Set the value of the property, if it exists |
||
85 | * @param string $name the property identifier |
||
86 | * @param mixed $value the value to store against the property |
||
87 | * @throws Exception if the property doesn't exist |
||
88 | */ |
||
89 | 6 | public function setValue(string $name, $value) |
|
93 | } |
||
94 |