Jenssegers\Model\Model::castAttribute PHP Метод

castAttribute() защищенный Метод

Cast an attribute to a native PHP type.
protected castAttribute ( string $key, mixed $value ) : mixed
$key string
$value mixed
Результат mixed
    protected function castAttribute($key, $value)
    {
        if (is_null($value)) {
            return $value;
        }
        switch ($this->getCastType($key)) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return (double) $value;
            case 'string':
                return (string) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'object':
                return $this->fromJson($value, true);
            case 'array':
            case 'json':
                return $this->fromJson($value);
            default:
                return $value;
        }
    }