66
77use JetBrains \PhpStorm \Language ;
88use TypeLang \Mapper \Configuration ;
9+ use TypeLang \Mapper \Context \Path \Entry \ArrayIndexEntry ;
910use TypeLang \Mapper \Context \Path \Entry \EntryInterface ;
11+ use TypeLang \Mapper \Context \Path \Entry \ObjectEntry ;
12+ use TypeLang \Mapper \Context \Path \Entry \ObjectPropertyEntry ;
13+ use TypeLang \Mapper \Context \Path \Entry \UnionLeafEntry ;
1014use TypeLang \Mapper \Context \Path \PathInterface ;
1115use TypeLang \Mapper \Type \Coercer \TypeCoercerInterface ;
1216use TypeLang \Mapper \Type \Extractor \TypeExtractorInterface ;
@@ -126,13 +130,13 @@ protected function __construct(
126130 /**
127131 * Creates new child context.
128132 */
129- public function enter (mixed $ value , EntryInterface $ entry , ?Configuration $ override = null ): self
133+ public function enter (mixed $ value , EntryInterface $ entry , ?Configuration $ config = null ): self
130134 {
131135 // Original configuration
132136 $ original = $ this ->original ?? $ this ->config ;
133137
134138 // Configuration of the current context
135- $ current = $ override ?? $ original ;
139+ $ current = $ config ?? $ original ;
136140
137141 // Do not set "previous" config in case of
138142 // "current" config is original
@@ -153,6 +157,46 @@ public function enter(mixed $value, EntryInterface $entry, ?Configuration $overr
153157 );
154158 }
155159
160+ /**
161+ * Creates an "array index" child context
162+ *
163+ * @param array-key $index
164+ */
165+ public function enterIntoArrayIndex (mixed $ value , int |string $ index , ?Configuration $ config = null ): self
166+ {
167+ return $ this ->enter ($ value , new ArrayIndexEntry ($ index ), $ config );
168+ }
169+
170+ /**
171+ * Creates an "object" child context
172+ *
173+ * @param class-string $class
174+ */
175+ public function enterIntoObject (mixed $ value , string $ class , ?Configuration $ config = null ): self
176+ {
177+ return $ this ->enter ($ value , new ObjectEntry ($ class ), $ config );
178+ }
179+
180+ /**
181+ * Creates an "object's property" child context
182+ *
183+ * @param non-empty-string $name
184+ */
185+ public function enterIntoObjectProperty (mixed $ value , string $ name , ?Configuration $ override = null ): self
186+ {
187+ return $ this ->enter ($ value , new ObjectPropertyEntry ($ name ), $ override );
188+ }
189+
190+ /**
191+ * Creates an "union leaf" child context
192+ *
193+ * @param int<0, max> $index
194+ */
195+ public function enterIntoUnionLeaf (mixed $ value , int $ index , ?Configuration $ override = null ): self
196+ {
197+ return $ this ->enter ($ value , new UnionLeafEntry ($ index ), $ override );
198+ }
199+
156200 /**
157201 * A more convenient and correct way to get current "object as array"
158202 * configuration value.
0 commit comments