public function reverseTransform($value)
    {
        $collection = new ArrayCollection();

        if ('' === $value || null === $value) {
            return $collection;
        }

        if (!is_string($value)) {
            throw new UnexpectedTypeException($value, 'string');
        }

        if ($this->onlyKeysInReverse) {
            $ids = \explode($this->separatorIfOnlyKeysInReverse, $value);
        } else {
            $ids = array();
            foreach (json_decode($value, true) as $subValue) {
                if (!empty($subValue[$this->arrayIdentifierName])) {
                    $ids[] = $subValue[$this->arrayIdentifierName];
                }
            }
        }

        $ids = \array_unique($ids);
        if (count($ids) == 0) {
            return $collection;
        }
        if (count($ids) > $this->maxResults) {
            throw new TransformationFailedException(
                sprintf('This collection should contain %s elements or less.', $this->maxResults)
            );
        }

        try {
            $hash = $this->getCacheHash($ids);
            if (array_key_exists($hash, $this->cachedResults)) {
                $collection = $this->cachedResults[$hash];
            } else {
                //Result not in cache

                $queryBuilderLoader = new ORMQueryBuilderLoader($this->queryBuilder);

                foreach ($queryBuilderLoader->getEntitiesByIds($this->identifier, $ids) as $entity) {
                    $collection->add($entity);
                }
                $this->cachedResults[$hash] = $collection; //Saves result in cache
            }
        } catch (\Exception $e) {
            throw new TransformationFailedException('Tranformation: Query Error');
        }

        return $collection;
    }
public function reverseTransform($value)
    {
        $collection = new ArrayCollection();

        if ('' === $value || null === $value) {
            return $collection;
        }

        if (!is_string($value)) {
            throw new UnexpectedTypeException($value, 'string');
        }

        if ($this->onlyKeysInReverse) {
            $ids = \explode($this->separatorIfOnlyKeysInReverse, $value);
        } else {
            $ids = array();
            foreach (json_decode($value, true) as $subValue) {
                if (!empty($subValue[$this->arrayIdentifierName])) {
                    $ids[] = $subValue[$this->arrayIdentifierName];
                }
            }
        }

        $ids = \array_unique($ids);
        if (count($ids) == 0) {
            return $collection;
        }
        if (count($ids) > $this->maxResults) {
            throw new TransformationFailedException(
                sprintf('This collection should contain %s elements or less.', $this->maxResults)
            );
        }

        try {
            $hash = $this->getCacheHash($ids);
            if (array_key_exists($hash, $this->cachedResults)) {
                $collection = $this->cachedResults[$hash];
            } else {
                //Result not in cache

                $queryBuilderLoader = new ORMQueryBuilderLoader($this->queryBuilder);

                foreach ($queryBuilderLoader->getEntitiesByIds($this->identifier, $ids) as $entity) {
                    $collection->add($entity);
                }
                $this->cachedResults[$hash] = $collection; //Saves result in cache
            }
        } catch (\Exception $e) {
            throw new TransformationFailedException('Tranformation: Query Error');
        }

        return $collection;
    }
public function reverseTransform ( $ value ) { $ collection = new ArrayCollection ( ) ; if ( '' === $ value || null === $ value ) { return $ collection ; } if ( ! is_string ( $ value ) ) { throw new UnexpectedTypeException ( $ value , 'string' ) ; } if ( $ this -> onlyKeysInReverse ) { $ ids = \ explode ( $ this -> separatorIfOnlyKeysInReverse , $ value ) ; } else { $ ids = array ( ) ; foreach ( json_decode ( $ value , true ) as $ subValue ) { if ( ! empty ( $ subValue [ $ this -> arrayIdentifierName ] ) ) { $ ids [ ] = $ subValue [ $ this -> arrayIdentifierName ] ; } } } $ ids = \ array_unique ( $ ids ) ; if ( count ( $ ids ) == 0 ) { return $ collection ; } if ( count ( $ ids ) > $ this -> maxResults ) { throw new TransformationFailedException ( sprintf ( 'This collection should contain %s elements or less.' , $ this -> maxResults ) ) ; } try { $ hash = $ this -> getCacheHash ( $ ids ) ; if ( array_key_exists ( $ hash , $ this -> cachedResults ) ) { $ collection = $ this -> cachedResults [ $ hash ] ; } else { //Result not in cache $ queryBuilderLoader = new ORMQueryBuilderLoader ( $ this -> queryBuilder ) ; foreach ( $ queryBuilderLoader -> getEntitiesByIds ( $ this -> identifier , $ ids ) as $ entity ) { $ collection -> add ( $ entity ) ; } $ this -> cachedResults [ $ hash ] = $ collection ; //Saves result in cache } } catch ( \ Exception $ e ) { throw new TransformationFailedException ( 'Tranformation: Query Error' ) ; } return $ collection ; }
Transforms JSON to Collection entities
@param string $value
@return Collection
Transforms JSON to Collection entities