src/Architect.php
public function parseData($data, array $modes, $key = null)
    {
        $return = [];

        uksort($modes, function ($a, $b) {
            return substr_count($b, '.')-substr_count($a, '.');
        });

        if (Utility::isCollection($data)) {
            $parsed = $this->parseCollection($modes, $data, $return);
        } else {
            $parsed = $this->parseResource($modes, $data, $return);
        }

        if ($key !== null) {
            $return[$key] = $parsed;
        } else {
            if (in_array('sideload', $modes)) {
                throw new InvalidArgumentException('$key cannot be null when ' .
                                    'resources are transformed using sideload.');
            }

            $return = $parsed;
        }

        return $return;
    }
public function parseData($data, array $modes, $key = null)
    {
        $return = [];

        uksort($modes, function ($a, $b) {
            return substr_count($b, '.')-substr_count($a, '.');
        });

        if (Utility::isCollection($data)) {
            $parsed = $this->parseCollection($modes, $data, $return);
        } else {
            $parsed = $this->parseResource($modes, $data, $return);
        }

        if ($key !== null) {
            $return[$key] = $parsed;
        } else {
            if (in_array('sideload', $modes)) {
                throw new InvalidArgumentException('$key cannot be null when ' .
                                    'resources are transformed using sideload.');
            }

            $return = $parsed;
        }

        return $return;
    }
public function parseData ( $ data , array $ modes , $ key = null ) { $ return = [ ] ; uksort ( $ modes , function ( $ a , $ b ) { return substr_count ( $ b , '.' ) - substr_count ( $ a , '.' ) ; } ) ; if ( Utility :: isCollection ( $ data ) ) { $ parsed = $ this -> parseCollection ( $ modes , $ data , $ return ) ; } else { $ parsed = $ this -> parseResource ( $ modes , $ data , $ return ) ; } if ( $ key !== null ) { $ return [ $ key ] = $ parsed ; } else { if ( in_array ( 'sideload' , $ modes ) ) { throw new InvalidArgumentException ( '$key cannot be null when ' . 'resources are transformed using sideload.' ) ; } $ return = $ parsed ; } return $ return ; }
Parse a collection using given modes.
@param  mixed $data The collection to be parsed
@param  array  $modes The modes to be used, format is ['relation' => 'mode']
@param  string $key A key to hoist the collection into the root array
@return array
Parse a collection using given modes .