public static function hydrate(array $data, ByConfigBuilder $config)
    {
        // When entity is not available. Only use the collection to set the data
        if ($config->getEntity() === false) {
            return $config->getCollectionEntity($data);
        }

        // When there is no collection specified. Make sure there will be an array to iterate through
        if ($config->isCollection() === false) {
            $data = array($data);
        }

        $rows = array();

        // Loop through the data
        foreach ($data as $index => $row) {
            $rows[$index] = $entity = $config->getEntity();

            foreach ($row as $field => $value) {
                // Skip field if not defined in the configuration
                if ($config->hasField($field) === false) {
                    $catchAll = $config->getCatchAllSetter();

                    if ($catchAll !== null) {
                        call_user_func(array($entity, $catchAll), $field, $value);
                    }

                    continue;
                }

                $callable = array($entity, $config->getSetter($field));

                if ($config->isInclude($field) === true) {
                    if (is_array($value) === false) {
                        throw new Exception\HydrateFailed(sprintf(static::$exceptions[1], $field, gettype($value)));
                    }

                    $value = static::hydrate($value, $config->getInclude($field));
                } else if ($config->getFormatter($field) !== null) {
                    $value = call_user_func($config->getFormatter($field), $value);
                }

                // Add the value
                call_user_func($callable, $value);
            }
        }

        return ($config->isCollection() === true) ? $config->getCollectionEntity($rows) : $entity;
    }
public static function hydrate(array $data, ByConfigBuilder $config)
    {
        // When entity is not available. Only use the collection to set the data
        if ($config->getEntity() === false) {
            return $config->getCollectionEntity($data);
        }

        // When there is no collection specified. Make sure there will be an array to iterate through
        if ($config->isCollection() === false) {
            $data = array($data);
        }

        $rows = array();

        // Loop through the data
        foreach ($data as $index => $row) {
            $rows[$index] = $entity = $config->getEntity();

            foreach ($row as $field => $value) {
                // Skip field if not defined in the configuration
                if ($config->hasField($field) === false) {
                    $catchAll = $config->getCatchAllSetter();

                    if ($catchAll !== null) {
                        call_user_func(array($entity, $catchAll), $field, $value);
                    }

                    continue;
                }

                $callable = array($entity, $config->getSetter($field));

                if ($config->isInclude($field) === true) {
                    if (is_array($value) === false) {
                        throw new Exception\HydrateFailed(sprintf(static::$exceptions[1], $field, gettype($value)));
                    }

                    $value = static::hydrate($value, $config->getInclude($field));
                } else if ($config->getFormatter($field) !== null) {
                    $value = call_user_func($config->getFormatter($field), $value);
                }

                // Add the value
                call_user_func($callable, $value);
            }
        }

        return ($config->isCollection() === true) ? $config->getCollectionEntity($rows) : $entity;
    }
public static function hydrate ( array $ data , ByConfigBuilder $ config ) { // When entity is not available. Only use the collection to set the data
 if ( $ config -> getEntity ( ) === false ) { return $ config -> getCollectionEntity ( $ data ) ; } // When there is no collection specified. Make sure there will be an array to iterate through
 if ( $ config -> isCollection ( ) === false ) { $ data = array ( $ data ) ; } $ rows = array ( ) ; // Loop through the data
 foreach ( $ data as $ index => $ row ) { $ rows [ $ index ] = $ entity = $ config -> getEntity ( ) ; foreach ( $ row as $ field => $ value ) { // Skip field if not defined in the configuration
 if ( $ config -> hasField ( $ field ) === false ) { $ catchAll = $ config -> getCatchAllSetter ( ) ; if ( $ catchAll !== null ) { call_user_func ( array ( $ entity , $ catchAll ) , $ field , $ value ) ; } continue ; } $ callable = array ( $ entity , $ config -> getSetter ( $ field ) ) ; if ( $ config -> isInclude ( $ field ) === true ) { if ( is_array ( $ value ) === false ) { throw new Exception \ HydrateFailed ( sprintf ( static :: $ exceptions [ 1 ] , $ field , gettype ( $ value ) ) ) ; } $ value = static :: hydrate ( $ value , $ config -> getInclude ( $ field ) ) ; } else if ( $ config -> getFormatter ( $ field ) !== null ) { $ value = call_user_func ( $ config -> getFormatter ( $ field ) , $ value ) ; } // Add the value
 call_user_func ( $ callable , $ value ) ; } } return ( $ config -> isCollection ( ) === true ) ? $ config -> getCollectionEntity ( $ rows ) : $ entity ; }
Hydrate array data to an object based on the configuration given

@param array $data
@param ByConfigBuilder $config

@return object | \ArrayIterator on a collection
Hydrate array data to an object based on the configuration given