1 | <?php |
||
12 | class TypeProperty |
||
13 | { |
||
14 | /** |
||
15 | * Store the value type |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | private $type; |
||
20 | |||
21 | /** |
||
22 | * Type checker for this property |
||
23 | * |
||
24 | * @var TypeChecker |
||
25 | */ |
||
26 | private $checker; |
||
27 | |||
28 | /** |
||
29 | * Set if the type check allows null |
||
30 | * |
||
31 | * @var bool |
||
32 | */ |
||
33 | private $allowNull; |
||
34 | |||
35 | /** |
||
36 | * @param string $type |
||
37 | * @param bool $allowNull |
||
38 | */ |
||
39 | 156 | public function __construct($type, $allowNull = false) |
|
58 | |||
59 | /** |
||
60 | * Helper method to throw an exception |
||
61 | * |
||
62 | * @param string $reason |
||
63 | * @param string $type |
||
64 | * @return TypePropertyException |
||
65 | */ |
||
66 | 3 | private function newConstructorException($reason, $type = '') |
|
71 | |||
72 | /** |
||
73 | * Check if a value match with this type. It may allow nulls. |
||
74 | * |
||
75 | * @param mixed $value |
||
76 | * @return bool |
||
77 | */ |
||
78 | 123 | public function check($value) |
|
82 | |||
83 | /** |
||
84 | * Return the allowed types for this property. |
||
85 | * Its used for the validations inside the constructor. |
||
86 | * |
||
87 | * To restrict to a certain types return the array with the list of types |
||
88 | * |
||
89 | * If a non array is returned then any type is allowed |
||
90 | * |
||
91 | * @return array|null |
||
92 | */ |
||
93 | 153 | public function getAllowedTypes() |
|
97 | |||
98 | /** |
||
99 | * Returns the type specification of the values |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | 130 | public function getType() |
|
107 | |||
108 | /** |
||
109 | * When converting this object to string it return the type |
||
110 | * @see TypeProperty::getType |
||
111 | * @return string |
||
112 | */ |
||
113 | 18 | public function __toString() |
|
117 | } |
||
118 |