src/TypeCastObject.php
public function cast($object)
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException(sprintf('Expected an object, but got %s!', gettype($object)));
        }
        foreach ($this->map as $name => $type) {
            if (isset($object->{$name})) {
                try {
                    $object->{$name} = $type->cast($object->{$name});
                } catch (\InvalidArgumentException $iaex) {
                    //unexpected value
                    throw new \InvalidArgumentException(
                        sprintf(
                            'Unexpected value for property %s: %s',
                            $name,
                            $iaex->getMessage()
                        ),
                        0,
                        $iaex
                    );
                }
            }
        }
        return $object;
    }
public function cast($object)
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException(sprintf('Expected an object, but got %s!', gettype($object)));
        }
        foreach ($this->map as $name => $type) {
            if (isset($object->{$name})) {
                try {
                    $object->{$name} = $type->cast($object->{$name});
                } catch (\InvalidArgumentException $iaex) {
                    //unexpected value
                    throw new \InvalidArgumentException(
                        sprintf(
                            'Unexpected value for property %s: %s',
                            $name,
                            $iaex->getMessage()
                        ),
                        0,
                        $iaex
                    );
                }
            }
        }
        return $object;
    }
public function cast ( $ object ) { if ( ! is_object ( $ object ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Expected an object, but got %s!' , gettype ( $ object ) ) ) ; } foreach ( $ this -> map as $ name => $ type ) { if ( isset ( $ object -> { $ name } ) ) { try { $ object -> { $ name } = $ type -> cast ( $ object -> { $ name } ) ; } catch ( \ InvalidArgumentException $ iaex ) { //unexpected value throw new \ InvalidArgumentException ( sprintf ( 'Unexpected value for property %s: %s' , $ name , $ iaex -> getMessage ( ) ) , 0 , $ iaex ) ; } } } return $ object ; }
Cast the public values of the given object to the typecast information
defined in this class.

@param object $object The raw data to be typecasted.
@return object 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 public values of the given object to the typecast information defined in this class .