src/Projection/EventHandler/ProjectionUpdater.php
protected function mirrorReferencedProjection(EntityReferenceInterface $projection)
    {
        $projection_type = $projection->getType();
        $mirrored_attribute_map = $projection_type->getAttributes()->filter(
            function (AttributeInterface $attribute) {
                return (bool)$attribute->getOption('mirrored', false) === true;
            }
        );

        // Don't need to load a referenced entity if the mirrored attribute map is empty
        if ($mirrored_attribute_map->isEmpty()) {
            return $projection;
        }

        // Load the referenced projection to mirror values from
        $referenced_type = $this->projection_type_map->getByClassName(
            $projection_type->getReferencedTypeClass()
        );
        $referenced_identifier = $projection->getReferencedIdentifier();
        if (empty($referenced_identifier)) {
            $this->logger->error('[Zombie Alarm] RefId EMPTY: '.json_encode($projection->getRoot()->toArray()));
            return $projection;
        }

        if ($referenced_identifier === $projection->getRoot()->getIdentifier()) {
            $referenced_projection = $projection->getRoot(); // self reference, no need to load
        } else {
            $referenced_projection = $this->loadReferencedProjection($referenced_type, $referenced_identifier);
            if (!$referenced_projection) {
                $this->logger->debug('[Zombie Alarm] Unable to load referenced projection: ' . $referenced_identifier);
                return $projection;
            }
        }

        // Add default attribute values
        $mirrored_values['@type'] = $projection_type->getPrefix();
        $mirrored_values['identifier'] = $projection->getIdentifier();
        $mirrored_values['referenced_identifier'] = $projection->getReferencedIdentifier();
        $mirrored_values = array_merge(
            $projection->createMirrorFrom($referenced_projection)->toArray(),
            $mirrored_values
        );

        return $projection_type->createEntity($mirrored_values, $projection->getParent());
    }
protected function mirrorReferencedProjection(EntityReferenceInterface $projection)
    {
        $projection_type = $projection->getType();
        $mirrored_attribute_map = $projection_type->getAttributes()->filter(
            function (AttributeInterface $attribute) {
                return (bool)$attribute->getOption('mirrored', false) === true;
            }
        );

        // Don't need to load a referenced entity if the mirrored attribute map is empty
        if ($mirrored_attribute_map->isEmpty()) {
            return $projection;
        }

        // Load the referenced projection to mirror values from
        $referenced_type = $this->projection_type_map->getByClassName(
            $projection_type->getReferencedTypeClass()
        );
        $referenced_identifier = $projection->getReferencedIdentifier();
        if (empty($referenced_identifier)) {
            $this->logger->error('[Zombie Alarm] RefId EMPTY: '.json_encode($projection->getRoot()->toArray()));
            return $projection;
        }

        if ($referenced_identifier === $projection->getRoot()->getIdentifier()) {
            $referenced_projection = $projection->getRoot(); // self reference, no need to load
        } else {
            $referenced_projection = $this->loadReferencedProjection($referenced_type, $referenced_identifier);
            if (!$referenced_projection) {
                $this->logger->debug('[Zombie Alarm] Unable to load referenced projection: ' . $referenced_identifier);
                return $projection;
            }
        }

        // Add default attribute values
        $mirrored_values['@type'] = $projection_type->getPrefix();
        $mirrored_values['identifier'] = $projection->getIdentifier();
        $mirrored_values['referenced_identifier'] = $projection->getReferencedIdentifier();
        $mirrored_values = array_merge(
            $projection->createMirrorFrom($referenced_projection)->toArray(),
            $mirrored_values
        );

        return $projection_type->createEntity($mirrored_values, $projection->getParent());
    }
protected function mirrorReferencedProjection ( EntityReferenceInterface $ projection ) { $ projection_type = $ projection -> getType ( ) ; $ mirrored_attribute_map = $ projection_type -> getAttributes ( ) -> filter ( function ( AttributeInterface $ attribute ) { return ( bool ) $ attribute -> getOption ( 'mirrored' , false ) === true ; } ) ; // Don't need to load a referenced entity if the mirrored attribute map is empty if ( $ mirrored_attribute_map -> isEmpty ( ) ) { return $ projection ; } // Load the referenced projection to mirror values from $ referenced_type = $ this -> projection_type_map -> getByClassName ( $ projection_type -> getReferencedTypeClass ( ) ) ; $ referenced_identifier = $ projection -> getReferencedIdentifier ( ) ; if ( empty ( $ referenced_identifier ) ) { $ this -> logger -> error ( '[Zombie Alarm] RefId EMPTY: ' . json_encode ( $ projection -> getRoot ( ) -> toArray ( ) ) ) ; return $ projection ; } if ( $ referenced_identifier === $ projection -> getRoot ( ) -> getIdentifier ( ) ) { $ referenced_projection = $ projection -> getRoot ( ) ; // self reference, no need to load } else { $ referenced_projection = $ this -> loadReferencedProjection ( $ referenced_type , $ referenced_identifier ) ; if ( ! $ referenced_projection ) { $ this -> logger -> debug ( '[Zombie Alarm] Unable to load referenced projection: ' . $ referenced_identifier ) ; return $ projection ; } } // Add default attribute values $ mirrored_values [ '@type' ] = $ projection_type -> getPrefix ( ) ; $ mirrored_values [ 'identifier' ] = $ projection -> getIdentifier ( ) ; $ mirrored_values [ 'referenced_identifier' ] = $ projection -> getReferencedIdentifier ( ) ; $ mirrored_values = array_merge ( $ projection -> createMirrorFrom ( $ referenced_projection ) -> toArray ( ) , $ mirrored_values ) ; return $ projection_type -> createEntity ( $ mirrored_values , $ projection -> getParent ( ) ) ; }
Evaluate and updated mirrored values from a loaded referenced projection
Evaluate and updated mirrored values from a loaded referenced projection