1 | <?php |
||
5 | class Rule |
||
6 | { |
||
7 | /** |
||
8 | * @var string |
||
9 | */ |
||
10 | private $class; |
||
11 | |||
12 | /** |
||
13 | * Property => Key |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | private $map = []; |
||
18 | |||
19 | /** |
||
20 | * Key => Property |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | private $reflectedMap = []; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | private $constructors = []; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | private $serializers = []; |
||
35 | |||
36 | /** |
||
37 | * Rule constructor. |
||
38 | * |
||
39 | * @param string $class |
||
40 | */ |
||
41 | public function __construct($class) |
||
45 | |||
46 | /** |
||
47 | * Create new rule |
||
48 | * |
||
49 | * @param string $class |
||
50 | * |
||
51 | * @return Rule |
||
52 | */ |
||
53 | public static function create(string $class): Rule |
||
57 | |||
58 | /** |
||
59 | * Create rule with one-to-one mapping |
||
60 | * |
||
61 | * @param string $class |
||
62 | * |
||
63 | * @return Rule |
||
64 | */ |
||
65 | public static function createDefault(string $class): Rule |
||
79 | |||
80 | /** |
||
81 | * Simple property-key pair assigning |
||
82 | * |
||
83 | * @param string $property Object property |
||
84 | * @param string $key Map key |
||
85 | * |
||
86 | * @return $this |
||
87 | */ |
||
88 | public function assign(string $property, string $key) |
||
94 | |||
95 | /** |
||
96 | * Assign property constructor |
||
97 | * |
||
98 | * @param string $property |
||
99 | * @param string $key |
||
100 | * @param callable $fx |
||
101 | * |
||
102 | * @return $this |
||
103 | */ |
||
104 | public function assignConstructor(string $property, string $key, callable $fx) |
||
111 | |||
112 | /** |
||
113 | * Assign property serializer |
||
114 | * |
||
115 | * @param string $property |
||
116 | * @param string $key |
||
117 | * @param callable $fx |
||
118 | * |
||
119 | * @return $this |
||
120 | */ |
||
121 | public function assignSerializer(string $property, string $key, callable $fx) |
||
128 | |||
129 | /** |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getClass(): string |
||
136 | |||
137 | /** |
||
138 | * @return array |
||
139 | */ |
||
140 | public function getMap(): array |
||
144 | |||
145 | /** |
||
146 | * @return array |
||
147 | */ |
||
148 | public function getReflectedMap(): array |
||
152 | |||
153 | /** |
||
154 | * @param string $property |
||
155 | * |
||
156 | * @return callable|null |
||
157 | */ |
||
158 | public function getConstructor(string $property) |
||
162 | |||
163 | /** |
||
164 | * @param string $property |
||
165 | * |
||
166 | * @return callable|null |
||
167 | */ |
||
168 | public function getSerializer(string $property) |
||
172 | |||
173 | /** |
||
174 | * @param string $property |
||
175 | * @param string $key |
||
176 | */ |
||
177 | private function doAssign(string $property, string $key) |
||
182 | } |
||
183 |