1 | <?php |
||
8 | class TypeCast |
||
9 | { |
||
10 | /** @var string */ |
||
11 | protected $paramDelimiter = ':'; |
||
12 | /** @var string */ |
||
13 | protected $keysDelimiter = '.'; |
||
14 | |||
15 | /** @var array */ |
||
16 | protected $types = []; |
||
17 | |||
18 | /** @var DeepArray */ |
||
19 | protected $deepArrayService; |
||
20 | /** @var PropException */ |
||
21 | protected $notExistValue; |
||
22 | |||
23 | 8 | public function __construct(DeepArray $deepArrayService) |
|
38 | |||
39 | /** |
||
40 | * @param array $coll |
||
41 | * @param array $rules |
||
42 | * @return array |
||
43 | * @throws PropException |
||
44 | */ |
||
45 | 1 | protected function eachHandlerType(array $coll, array $rules): array |
|
53 | |||
54 | /** |
||
55 | * @param string $type |
||
56 | * @return callable |
||
57 | */ |
||
58 | protected function setType(string $type): callable |
||
66 | |||
67 | /** |
||
68 | * @param string $name |
||
69 | * @param callable $handler |
||
70 | * @return $this |
||
71 | */ |
||
72 | 8 | public function registerType(string $name, callable $handler): self |
|
77 | |||
78 | 2 | public function getTypes(): array |
|
82 | |||
83 | /** |
||
84 | * @param array $data |
||
85 | * @param array $rules |
||
86 | * @return array |
||
87 | * @throws PropException |
||
88 | */ |
||
89 | 6 | public function cast(array $data, array $rules): array |
|
102 | |||
103 | /** |
||
104 | * @param mixed $value |
||
105 | * @param array $rules |
||
106 | * @return mixed |
||
107 | * @throws PropException |
||
108 | */ |
||
109 | 6 | protected function castValue($value, array $rules) |
|
121 | |||
122 | /** |
||
123 | * @param mixed $value |
||
124 | * @param array $params |
||
125 | * @param string $handlerAlias |
||
126 | * @return mixed |
||
127 | * @throws PropException |
||
128 | */ |
||
129 | 6 | protected function applyCastType($value, array $params, string $handlerAlias) |
|
139 | |||
140 | /** |
||
141 | * @param string $name |
||
142 | * @param array $data |
||
143 | * @param mixed $default |
||
144 | * @return mixed |
||
145 | */ |
||
146 | 6 | protected function getValue(string $name, array $data, $default) |
|
151 | |||
152 | 5 | protected function setValue(string $name, array &$data, $value) |
|
157 | |||
158 | 1 | public function extractArrayRule(array $rule): array |
|
162 | |||
163 | 6 | public function extractStringRule(string $rule): array |
|
170 | } |
||
171 |