protected function transform(Aggregate $aggregatedEntity): array
    {
        $baseAttributes = $aggregatedEntity->getRawAttributes();

        $relationAttributes = [];

        // First we'll handle each relationships that are a one to one
        // relation, and which will be saved as a CachedRelationship
        // object inside the cache.

        // NOTE : storing localRelationships maybe useless has we store
        // the foreign key in the attributes already.

        foreach ($this->entityMap->getSingleRelationships() as $relation) {
            $aggregates = $aggregatedEntity->getRelationship($relation);

            if (count($aggregates) == 1) {
                $related = $aggregates[0];
                $relationAttributes[$relation] = new CachedRelationship($related->getEntityHash());
            }
            if (count($aggregates) > 1) {
                throw new MappingException("Single Relationship '$relation' contains several related entities");
            }
        }

        // Then we'll handle the 'many' relationships and store them as
        // an array of CachedRelationship objects.

        foreach ($this->entityMap->getManyRelationships() as $relation) {
            $aggregates = $aggregatedEntity->getRelationship($relation);

            $relationAttributes[$relation] = [];

            foreach ($aggregates as $aggregate) {
                $relationAttributes[$relation][] = new CachedRelationship(
                    $aggregate->getEntityHash(),
                    $aggregate->getPivotAttributes()
                );
            }
        }

        return $baseAttributes + $relationAttributes;
    }
protected function transform(Aggregate $aggregatedEntity): array
    {
        $baseAttributes = $aggregatedEntity->getRawAttributes();

        $relationAttributes = [];

        // First we'll handle each relationships that are a one to one
        // relation, and which will be saved as a CachedRelationship
        // object inside the cache.

        // NOTE : storing localRelationships maybe useless has we store
        // the foreign key in the attributes already.

        foreach ($this->entityMap->getSingleRelationships() as $relation) {
            $aggregates = $aggregatedEntity->getRelationship($relation);

            if (count($aggregates) == 1) {
                $related = $aggregates[0];
                $relationAttributes[$relation] = new CachedRelationship($related->getEntityHash());
            }
            if (count($aggregates) > 1) {
                throw new MappingException("Single Relationship '$relation' contains several related entities");
            }
        }

        // Then we'll handle the 'many' relationships and store them as
        // an array of CachedRelationship objects.

        foreach ($this->entityMap->getManyRelationships() as $relation) {
            $aggregates = $aggregatedEntity->getRelationship($relation);

            $relationAttributes[$relation] = [];

            foreach ($aggregates as $aggregate) {
                $relationAttributes[$relation][] = new CachedRelationship(
                    $aggregate->getEntityHash(),
                    $aggregate->getPivotAttributes()
                );
            }
        }

        return $baseAttributes + $relationAttributes;
    }
protected function transform ( Aggregate $ aggregatedEntity ) : array { $ baseAttributes = $ aggregatedEntity -> getRawAttributes ( ) ; $ relationAttributes = [ ] ; // First we'll handle each relationships that are a one to one // relation, and which will be saved as a CachedRelationship // object inside the cache. // NOTE : storing localRelationships maybe useless has we store // the foreign key in the attributes already. foreach ( $ this -> entityMap -> getSingleRelationships ( ) as $ relation ) { $ aggregates = $ aggregatedEntity -> getRelationship ( $ relation ) ; if ( count ( $ aggregates ) == 1 ) { $ related = $ aggregates [ 0 ] ; $ relationAttributes [ $ relation ] = new CachedRelationship ( $ related -> getEntityHash ( ) ) ; } if ( count ( $ aggregates ) > 1 ) { throw new MappingException ( "Single Relationship '$relation' contains several related entities" ) ; } } // Then we'll handle the 'many' relationships and store them as // an array of CachedRelationship objects. foreach ( $ this -> entityMap -> getManyRelationships ( ) as $ relation ) { $ aggregates = $ aggregatedEntity -> getRelationship ( $ relation ) ; $ relationAttributes [ $ relation ] = [ ] ; foreach ( $ aggregates as $ aggregate ) { $ relationAttributes [ $ relation ] [ ] = new CachedRelationship ( $ aggregate -> getEntityHash ( ) , $ aggregate -> getPivotAttributes ( ) ) ; } } return $ baseAttributes + $ relationAttributes ; }
Transform an Aggregated Entity into a cache record.

@param Aggregate $aggregatedEntity

@throws MappingException

@return array
Transform an Aggregated Entity into a cache record .