1414use TypeLang \Mapper \Type \TypeInterface ;
1515use TypeLang \Parser \Node \Stmt \TypeStatement ;
1616
17+ /**
18+ * @template-implements \IteratorAggregate<array-key, Context>
19+ */
1720abstract class Context implements
1821 TypeExtractorInterface,
1922 TypeParserInterface,
20- TypeRepositoryInterface
23+ TypeRepositoryInterface,
24+ \IteratorAggregate,
25+ \Countable
2126{
2227 protected function __construct (
23- protected readonly mixed $ value ,
24- protected readonly Direction $ direction ,
25- protected readonly Configuration $ config ,
26- protected readonly TypeExtractorInterface $ extractor ,
27- protected readonly TypeParserInterface $ parser ,
28- protected readonly TypeRepositoryInterface $ types ,
28+ public readonly mixed $ value ,
29+ public readonly Direction $ direction ,
30+ public readonly Configuration $ config ,
31+ public readonly TypeExtractorInterface $ extractor ,
32+ public readonly TypeParserInterface $ parser ,
33+ public readonly TypeRepositoryInterface $ types ,
2934 ) {}
3035
3136 /**
3237 * Creates new child context.
3338 */
34- public function enter (
35- mixed $ value ,
36- EntryInterface $ entry ,
37- ?bool $ strictTypes = null ,
38- ?bool $ objectAsArray = null ,
39- ): self {
39+ public function enter (mixed $ value , EntryInterface $ entry , ?Configuration $ override = null ): self
40+ {
4041 return new ChildContext (
4142 parent: $ this ,
4243 entry: $ entry ,
@@ -46,16 +47,10 @@ public function enter(
4647 extractor: $ this ->extractor ,
4748 parser: $ this ->parser ,
4849 types: $ this ->types ,
49- overrideStrictTypes: $ strictTypes ,
50- overrideObjectAsArray: $ objectAsArray ,
50+ override: $ override ,
5151 );
5252 }
5353
54- public function getValue (): mixed
55- {
56- return $ this ->value ;
57- }
58-
5954 public function isObjectAsArray (): bool
6055 {
6156 return $ this ->config ->isObjectAsArray ();
@@ -127,7 +122,15 @@ public function getStatementByValue(mixed $value): TypeStatement
127122 public function getTypeByValue (mixed $ value ): TypeInterface
128123 {
129124 return $ this ->types ->getTypeByStatement (
130- statement: $ this ->getStatementByValue ($ value )
125+ statement: $ this ->getStatementByValue ($ value ),
131126 );
132127 }
128+
129+ /**
130+ * @return int<1, max>
131+ */
132+ public function count (): int
133+ {
134+ return \iterator_count ($ this );
135+ }
133136}
0 commit comments