public function castValue($field, $value, $cast = true)
    {
        if (! array_key_exists($field, $this->casts) || ! $cast)
            // no cast configured for said field. Nothing done.
            return $value;

        $types = [
            "boolean", "bool", "integer", "int", "float", "double",
            "string", "array", "object", "null"
        ];

        // validate type cast is valid
        $type = $this->casts[$field];
        if (! in_array($type, $types)) {
            throw new RuntimeException("Cast of field '" . $field . "' to type '" . $type . "' not possible. Please define only scalar type casts.");
        }

        $output = $value;
        $result = settype($output, $type);

        if ($result === true)
            return $output;

        return $value;
    }
public function castValue($field, $value, $cast = true)
    {
        if (! array_key_exists($field, $this->casts) || ! $cast)
            // no cast configured for said field. Nothing done.
            return $value;

        $types = [
            "boolean", "bool", "integer", "int", "float", "double",
            "string", "array", "object", "null"
        ];

        // validate type cast is valid
        $type = $this->casts[$field];
        if (! in_array($type, $types)) {
            throw new RuntimeException("Cast of field '" . $field . "' to type '" . $type . "' not possible. Please define only scalar type casts.");
        }

        $output = $value;
        $result = settype($output, $type);

        if ($result === true)
            return $output;

        return $value;
    }
public function castValue ( $ field , $ value , $ cast = true ) { if ( ! array_key_exists ( $ field , $ this -> casts ) || ! $ cast ) // no cast configured for said field. Nothing done. return $ value ; $ types = [ "boolean" , "bool" , "integer" , "int" , "float" , "double" , "string" , "array" , "object" , "null" ] ; // validate type cast is valid $ type = $ this -> casts [ $ field ] ; if ( ! in_array ( $ type , $ types ) ) { throw new RuntimeException ( "Cast of field '" . $ field . "' to type '" . $ type . "' not possible. Please define only scalar type casts." ) ; } $ output = $ value ; $ result = settype ( $ output , $ type ) ; if ( $ result === true ) return $ output ; return $ value ; }
This method will read the `casts` instance property and
automatically cast the `value` provided in the set cast
type.

@see http://php.net/manual/en/function.settype.php
@param   string      $field
@param   mixed       $value
@return  mixed
This method will read the casts instance property and automatically cast the value provided in the set cast type .