4545use ReflectionProperty ;
4646use Reflector ;
4747use function array_key_exists ;
48+ use function array_key_last ;
4849use function array_merge ;
4950use function assert ;
50- use function count ;
5151use function get_class ;
5252use function is_a ;
5353use function is_int ;
5454use function is_string ;
55- use function PHPUnit \Framework \assertNull ;
5655use function sprintf ;
5756use const PHP_VERSION_ID ;
5857
@@ -315,33 +314,26 @@ private function resolveFieldsMeta(ReflectionClass $rootClass, CompileMeta $meta
315314 $ docs = [];
316315 $ modifiers = [];
317316 $ rules = [];
318- $ default = DefaultValueMeta::fromNothing ();
319- $ phpPropertyMeta = null ;
320- $ reflector = null ;
321- foreach ($ scopedProperty as $ scope => $ scopeConfig ) {
322- //TODO - mergování - variance, invariance
323- $ repeatable = $ scopeConfig ['repeatable ' ];
324317
325- /*
326- if ($repeatable === RepeatableBehavior::noRepeat()) {
327- //TODO - kontrolovat, že je definice jenom jedna v téhle iteraci
328- //TODO - kontrolovat, že ještě nastavená není z předchozí iterace
329- $grouped[$propertyName][$scope][] = $definition;
330- } elseif ($repeatable === RepeatableBehavior::merge()) {
331- //TODO - mergnout
332- $grouped[$propertyName][$scope][] = $definition;
333- } elseif ($repeatable === RepeatableBehavior::override()) {
334- //TODO - přepsat
335- $grouped[$propertyName][$scope][] = $definition ;
336- }
337- */
318+ $ lastPropertyConfig = $ scopedProperty [ array_key_last ( $ scopedProperty )];
319+ //TODO - z těch ostatních se mi hodí jen source, runtime resolver nepotřebuju
320+ $ lastPropertyStructure = $ lastPropertyConfig [ ' propertyStructure ' ];
321+ $ lastContextReflector = $ lastPropertyStructure -> getContextReflector ();
322+
323+ //TODO - získat 0-1, resolvnout, odstranit ze seznamu
324+ $ default = $ this -> getDefaultValue (
325+ $ lastPropertyStructure ,
326+ $ lastPropertyConfig [ ' scopedDefinitions ' ][DefaultValueModifier::class] ?? [],
327+ );
328+ $ phpPropertyMeta = PhpPropertyMeta:: from ( $ lastContextReflector ) ;
329+
330+ $ context = new MetaFieldContext ( $ this -> loader , $ this , $ default );
338331
339- foreach ($ scopeConfig ['definitionsByClass ' ] as $ className => $ classScopeConfig ) {
340- /** @var PropertyStructure $propertyStructure */
341- $ propertyStructure = $ classScopeConfig ['propertyStructure ' ];
342- $ reflector = $ propertyStructure ->getContextReflector ();
343- $ phpPropertyMeta = PhpPropertyMeta::from ($ propertyStructure ->getContextReflector ());
344- foreach ($ classScopeConfig ['definitions ' ] as $ definition ) {
332+ foreach ($ scopedProperty as $ propertyClassName => $ propertyConfig ) {
333+ foreach ($ propertyConfig ['scopedDefinitions ' ] as $ scope => $ definitions ) {
334+ foreach ($ definitions as $ definition ) {
335+ //TODO - indexovat pomocí scope, ať se pak mohou mergnout
336+ //TODO - resolve by měl být možný už tady
345337 if ($ definition instanceof CallbackDefinition) {
346338 $ callbacks [] = $ definition ;
347339 } elseif ($ definition instanceof DocDefinition) {
@@ -354,18 +346,27 @@ private function resolveFieldsMeta(ReflectionClass $rootClass, CompileMeta $meta
354346 $ this ->throwUnsupportedDefinitionType ($ definition );
355347 }
356348 }
357-
358- //TODO - tohle je blbě, pro teď good enough
359- $ default = $ this ->getDefaultValue ($ propertyStructure , $ modifiers );
360349 }
361350 }
362351
363- $ context = new MetaFieldContext ($ this ->loader , $ this , $ default );
352+ /*
353+ if ($repeatable === RepeatableBehavior::noRepeat()) {
354+ //TODO - kontrolovat, že je definice jenom jedna v téhle iteraci
355+ //TODO - kontrolovat, že ještě nastavená není z předchozí iterace
356+ $grouped[$propertyName][$scope][] = $definition;
357+ } elseif ($repeatable === RepeatableBehavior::merge()) {
358+ //TODO - mergnout
359+ $grouped[$propertyName][$scope][] = $definition;
360+ } elseif ($repeatable === RepeatableBehavior::override()) {
361+ //TODO - přepsat
362+ $grouped[$propertyName][$scope][] = $definition;
363+ }
364+ */
364365
365366 //TODO - předávat definice nestrukturovaně? jen seskupené podle scope
366367 $ field = new FieldRuntimeMeta (
367368 //TODO - resolve volat při zpracování definic per-class
368- $ this ->resolveCallbacksMeta ($ callbacks , $ context , $ reflector ),
369+ $ this ->resolveCallbacksMeta ($ callbacks , $ context , $ lastContextReflector ),
369370 $ this ->resolveDocsMeta ($ docs , $ context ),
370371 $ this ->resolveFieldModifiersMeta ($ modifiers , $ context ),
371372 $ this ->resolveRuleMeta ($ rules [0 ], $ context ),
@@ -485,8 +486,7 @@ private function propertyNameToFieldName(FieldRuntimeMeta $fieldMeta)
485486 */
486487 private function resolveFieldMeta (
487488 ReflectionClass $ rootClass ,
488- FieldCompileMeta $ fieldMeta ,
489- RuleDefinition $ ruleDefinition
489+ FieldCompileMeta $ fieldMeta
490490 ): FieldRuntimeMeta
491491 {
492492 $ fieldStructure = $ fieldMeta ->getPropertyStructure ();
@@ -510,31 +510,6 @@ private function resolveFieldMeta(
510510 if (!$ classReflector ->isSubclassOf (MappedObject::class)) {
511511 $ this ->throwFieldMetaOutsideOfMappedObject ($ rootClass , $ classReflector , $ fieldStructure ->getSource ());
512512 }
513-
514- $ callbacks = $ docs = $ modifiers = [];
515- foreach ($ fieldMeta ->getDefinitions () as $ definition ) {
516- if ($ definition instanceof CallbackDefinition) {
517- $ callbacks [] = $ definition ;
518- } elseif ($ definition instanceof DocDefinition) {
519- $ docs [] = $ definition ;
520- } elseif ($ definition instanceof ModifierDefinition) {
521- $ modifiers [] = $ definition ;
522- } elseif (!$ definition instanceof RuleDefinition) {
523- $ this ->throwUnsupportedDefinitionType ($ definition );
524- }
525- }
526-
527- $ defaultValue = $ this ->getDefaultValue ($ fieldMeta ->getPropertyStructure (), $ modifiers );
528- $ context = new MetaFieldContext ($ this ->loader , $ this , $ defaultValue );
529-
530- return new FieldRuntimeMeta (
531- $ this ->resolveCallbacksMeta ($ callbacks , $ context , $ reflector ),
532- $ this ->resolveDocsMeta ($ docs , $ context ),
533- $ this ->resolveFieldModifiersMeta ($ modifiers , $ context ),
534- $ this ->resolveRuleMeta ($ ruleDefinition , $ context ),
535- $ defaultValue ,
536- PhpPropertyMeta::from ($ reflector ),
537- );
538513 }
539514
540515 /**
@@ -707,14 +682,12 @@ public function resolveRuleMeta(RuleDefinition $definition, MetaFieldContext $co
707682 }
708683
709684 /**
710- * @param list<ModifierDefinition > $modifiers
685+ * @param list<MetaDefinition > $defaultModifiers
711686 */
712- private function getDefaultValue (PropertyStructure $ propertyStructure , array $ modifiers ): DefaultValueMeta
687+ private function getDefaultValue (PropertyStructure $ propertyStructure , array $ defaultModifiers ): DefaultValueMeta
713688 {
714- foreach ($ modifiers as $ modifier ) {
715- if ($ modifier ->getHandler () === DefaultValueModifier::class) {
716- return DefaultValueMeta::fromValue ($ modifier ->getArgs ()[DefaultValueModifier::Value]);
717- }
689+ foreach ($ defaultModifiers as $ modifier ) {
690+ return DefaultValueMeta::fromValue ($ modifier ->getArgs ()[DefaultValueModifier::Value]);
718691 }
719692
720693 $ property = $ propertyStructure ->getContextReflector ();
0 commit comments