1 | <?php |
||
20 | final class Type |
||
21 | { |
||
22 | const STRING = 'string'; |
||
23 | const INTEGER = 'integer'; |
||
24 | const FLOAT = 'float'; |
||
25 | const BOOLEAN = 'boolean'; |
||
26 | const DATE = 'date'; |
||
27 | const OBJECT = 'object'; |
||
28 | const ARRAY = 'array'; |
||
29 | |||
30 | /** @var Key|null */ |
||
31 | private static $encryptionKey; |
||
32 | |||
33 | /** |
||
34 | * Marshals a value for a given property from storage. |
||
35 | * |
||
36 | * @param mixed $value |
||
37 | * |
||
38 | * @return mixed type-casted value |
||
39 | */ |
||
40 | public static function cast(Property $property, $value) |
||
65 | |||
66 | /** |
||
67 | * Casts a value to a string. |
||
68 | * |
||
69 | * @param mixed $value |
||
70 | */ |
||
71 | public static function to_string($value): string |
||
75 | |||
76 | /** |
||
77 | * Casts a value to an integer. |
||
78 | * |
||
79 | * @param mixed $value |
||
80 | */ |
||
81 | public static function to_integer($value): int |
||
85 | |||
86 | /** |
||
87 | * Casts a value to a float. |
||
88 | * |
||
89 | * @param mixed $value |
||
90 | */ |
||
91 | public static function to_float($value): float |
||
95 | |||
96 | /** |
||
97 | * Casts a value to a boolean. |
||
98 | * |
||
99 | * @param mixed $value |
||
100 | */ |
||
101 | public static function to_boolean($value): bool |
||
105 | |||
106 | /** |
||
107 | * Casts a date value as a UNIX timestamp. |
||
108 | * |
||
109 | * @param mixed $value |
||
110 | */ |
||
111 | public static function to_date($value): int |
||
119 | |||
120 | /** |
||
121 | * Casts a value to an array. |
||
122 | * |
||
123 | * @param mixed $value |
||
124 | */ |
||
125 | public static function to_array($value): array |
||
134 | |||
135 | /** |
||
136 | * Casts a value to an object. |
||
137 | * |
||
138 | * @param mixed $value |
||
139 | * |
||
140 | * @return object |
||
141 | */ |
||
142 | public static function to_object($value): \stdClass |
||
151 | |||
152 | /** |
||
153 | * Sets the encryption key to be used when encryption is enabled for a property. |
||
154 | */ |
||
155 | public static function setEncryptionKey(Key $key): void |
||
159 | |||
160 | /** |
||
161 | * Gets the encryption key, if used. |
||
162 | */ |
||
163 | public static function getEncryptionKey(): ?Key |
||
167 | } |
||
168 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: