Typecast a value
@param mixed $value
@param string $type
@return mixed The typecasted value
@deprecated since 1.1.0
190837
public static function typecast(&$value, $type)
    {
        switch ($type) {
            case Validate::TYPE_INT:
            case Validate::TYPE_UINT:
                $value = intval($value);
                break;
            case Validate::TYPE_FLOAT:
                $value = floatval($value);
                break;
            case Validate::TYPE_DOUBLE:
                $value = doubleval($value);
                break;
            case Validate::TYPE_BOOLEAN:
                $value = boolval($value);
                break;
            case Validate::TYPE_UNIX_TIMESTAMP:
                //Add the timezone offset (in minutes)
                $value = intval($value) +
                    (\Phramework\Phramework::getTimezoneOffset()*60);
                break;
        }
    }
1187917
protected function decode($value, string $type)
    {
        try {
            return $this->encoders->getEncoderForType($type)
                ->decode($value, $type, new EncodingContext());
        } catch (EncodingException | InvalidArgumentException | OutOfBoundsException $ex) {
            throw new SerializationException('Failed to deserialize value', 0, $ex);
        }
    }
1114215
protected function castToScalar($value, $type)
    {
        if ($type === 'integer') {
            return (integer) $value;
        }
        if ($type === 'boolean') {
            return (boolean) $value;
        }
        if ($type === 'float') {
            return (float) $value;
        }
        if ($type === 'string') {
            return (string) $value;
        }

        return $value;
    }
353810
public function juggle($value, $type)
    {
        // Cast non-null values
        if ( ! is_null($value)) {
            // Ensure that the type is a valid type to cast.
            // We do this check here because it might not have been done
            // as is the case when the model is first initialized.
            if ($this->checkJuggleType($type)) {
                // Get the method that the type maps to
                $method = $this->buildJuggleMethod($type);

                // Cast the value to the type using the method
                $value = $this->{$method}($value);
            }
        }

        return $value;
    }
480177
protected function castToObject($value)
    {
        if (is_scalar($value) || is_resource($value)) {
            $value = $this->dontCast($value);
        }

        return (object)$value;
    }
1003470
protected function _type_assignment_set( $type, $value )
	{
		switch ( $type ) 
		{
			case 'int':
			case 'timestamp':
				return (int) $value;
			break;

			case 'string':
				return (string) $value;
			break;

			case 'bool':
				return (bool) $value;
			break;

			// json datatype simply encode
			case 'json':
				return json_encode( $value );
			break;
		}

		return $value;
	}
593388
protected function castToClass($value)
    {
        if (!class_exists($this->class)) {
            return $this->dontCast($value, "Class doesn't exist");
        }

        if (is_object($value) && is_a($value, $this->class)) {
            return $value;
        }

        $value = $this->createWithSetState($value);

        if (!is_a($value, $this->class)) {
            $class = $this->class;
            $value = new $class($value);
        }

        return $value;
    }
428391
private function getTypedValue(string $value)
    {
        if (\in_array($value, self::$boolValues, true)) {
            return \in_array($value, self::$truthlyValues, true);
        }

        if (\is_numeric($value)) {
            return $this->getNumericValue($value);
        }

        return $value;
    }
580950
public static function castValueToDataType($value, $type)
    {
        switch ($type) {
            case Property::DATA_TYPE_FLOAT:
                return empty($value) ? null : (float) $value;
                break;

            case Property::DATA_TYPE_BOOLEAN:
                return empty($value) ? null : (bool) $value;
                break;

            case Property::DATA_TYPE_INTEGER:
                return empty($value) ? null : (int) $value;
                break;

            default:
                return $value;
                break;
        }
    }
609888
protected function castValue($value)
    {
        if (is_null($value)) {
            return $value;
        }

        if ($this->isElementOfDate() && $this->isDateCastable()) {
            return $this->fromDateTime($value);
        }

        switch ($this->getCast()) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return (float) $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);
            case 'collection':
                return new Collection($this->fromJson($value));
            case 'comma':
                return $this->fromCommaSeparated($value);
            default:
                return $value;
        }
    }
1279811
protected function cast($value)
    {
        if (strlen($value) === 0) {
            return null;
        }
        if ($this->getScale() === 0) {
            return (int)$value;
        }
        return (float)$value;
    }
810149
protected function castToType($value, $type)
    {
        switch ($type) {
            case self::TYPE_CAST_INT:
                $newValue = filter_var($value, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
                $value    = (null === $newValue) ? $value : $newValue;
                break;
            case self::TYPE_CAST_BOOL:
                $newValue = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
                $value    = (null === $newValue) ? $value : $newValue;
                break;
            case self::TYPE_CAST_FLOAT:
                $newValue = filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE);
                $value    = (null === $newValue) ? $value : $newValue;
                break;
        }

        return $value;
    }
657410
protected function castValue($value)
    {
        switch ($value) {
            case 'false':
                return false;

            case 'true':
                return true;
        }

        if (is_numeric($value)) {
            $value = intval($value);
        }

        return $value;
    }
1264204
protected function getValueForCondition($value, $type)
    {
        // check if date and not a relative value like -1 week
        if (DataTypes::DATETIME_TYPE === $type && !preg_match('/[A-Za-z]{3,}/', $value)) {
            return (new \DateTime($value))->format(\DateTime::ISO8601);
        }

        return $value;
    }
884098
public function convertToPHPValue($value, PlatformInterface $platform)
    {
        if ($value === null) {
            return;
        }

        $phpValue = \DateTime::createFromFormat('!'.$platform->getDateFormat(), $value);

        if ($phpValue === false) {
            throw TypeException::conversionToPHPFailed($value, $this->getName());
        }

        return $phpValue;
    }
137778
protected function setCast($key, $value)
    {
        if (is_null($value)) {
            return $value;
        }

        $type   = $this->getCastType($key);
        $method = 'setCast' . Str::studly($type) . 'Type';

        if (method_exists($this, $method)) {
            return $this->$method($key, $value);
        }

        return $value;
    }
812225
private function normalizeValue($value, string $type)
    {
        if (Types::ID === $type && $value) {
            if (\is_array($value)) {
                $idsArray = [];
                foreach ($value as $id) {
                    if ($id) {
                        $idsArray[] = $this->decodeID($id);
                    }
                }
                $value = $idsArray;
            } else {
                $value = $this->decodeID($value);
            }
        }

        return $value;
    }