src/TypeCastArray.php
public function cast($array)
    {
        if (!is_array($array)) {
            throw new \InvalidArgumentException(sprintf('Expected an array, but got %s!', gettype($array)));
        }
        foreach ($array as $key => $value) {
            //is this a repeating array?
            $mapKey = $this->mapKey($key);
            //try to cast the value
            try {
                $array[$key] = $this[$mapKey]->cast($value);
            } catch (KeyNotFoundException $knfex) {
                //no key, no typecast, nothing happened.
            } catch (\InvalidArgumentException $iaex) {
                //unexpected value
                throw new \InvalidArgumentException(
                    sprintf(
                        'Unexpected value for key %s: %s',
                        $key,
                        $iaex->getMessage()
                    ),
                    0,
                    $iaex
                );
            }
        }
        return $array;
    }
public function cast($array)
    {
        if (!is_array($array)) {
            throw new \InvalidArgumentException(sprintf('Expected an array, but got %s!', gettype($array)));
        }
        foreach ($array as $key => $value) {
            //is this a repeating array?
            $mapKey = $this->mapKey($key);
            //try to cast the value
            try {
                $array[$key] = $this[$mapKey]->cast($value);
            } catch (KeyNotFoundException $knfex) {
                //no key, no typecast, nothing happened.
            } catch (\InvalidArgumentException $iaex) {
                //unexpected value
                throw new \InvalidArgumentException(
                    sprintf(
                        'Unexpected value for key %s: %s',
                        $key,
                        $iaex->getMessage()
                    ),
                    0,
                    $iaex
                );
            }
        }
        return $array;
    }
public function cast ( $ array ) { if ( ! is_array ( $ array ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Expected an array, but got %s!' , gettype ( $ array ) ) ) ; } foreach ( $ array as $ key => $ value ) { //is this a repeating array? $ mapKey = $ this -> mapKey ( $ key ) ; //try to cast the value try { $ array [ $ key ] = $ this [ $ mapKey ] -> cast ( $ value ) ; } catch ( KeyNotFoundException $ knfex ) { //no key, no typecast, nothing happened. } catch ( \ InvalidArgumentException $ iaex ) { //unexpected value throw new \ InvalidArgumentException ( sprintf ( 'Unexpected value for key %s: %s' , $ key , $ iaex -> getMessage ( ) ) , 0 , $ iaex ) ; } } return $ array ; }
Cast the values of the given array to the typecast information defined in this
class.

@param array $array The raw data to be typecasted.
@return array The same data structure as the input, but casted to the
typecasting information defined in this
class.
@throws \InvalidArgumentException in case the given value does not match the
typecasting information defined in this
class.
Cast the values of the given array to the typecast information defined in this class .