Converts the input value according to [[phpType]] after retrieval from the database.
If the value is null or an [[Expression]], it will not be converted.
@param mixed $value input value
@return mixed converted value
@since 2.0.3
552033
protected function typecast($value)
    {
        if ($value === '' && $this->type !== Schema::TYPE_STRING) {
            return null;
        }
        if ($value === null || gettype($value) === $this->phpType || $value instanceof Expression) {
            return $value;
        }
        switch ($this->phpType) {
            case 'resource':
            case 'string':
                return is_resource($value) ? $value : (string) $value;
            case 'int':
            case 'integer':
                return (int) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'double':
                return (double) $value;
        }

        return $value;
    }
1167406
public function getPDOConstantType($value)
    {

        switch (true) {
            case is_int($value):
                $type = PDO::PARAM_INT;
                break;
            case is_bool($value):
                $type = PDO::PARAM_BOOL;
                break;
            case (null === $value):
                $type = PDO::PARAM_NULL;
                break;
            default:
                $type = PDO::PARAM_STR;
        }
        return $type;
    }
672780
private function parseType(string $value)
    {
        if ((substr($value, 0, 1) === '"' && substr($value, -1) === '"') || (substr($value, 0, 1) === "'" && substr($value, -1) === "'")) {
            return substr($value, 1, strlen($value) - 2);
        }

        return Parse::toType($value);
    }
1249090
private function resolve($value): Input
    {
        $rules = $this->queueOfRules->toArray();
        $input = Input::make($value);

        foreach ($rules as $rule) {
            $input = $rule->execute($input);
        }

        $input = $this->applyTypeValidation($input);

        return $input;
    }
234711
function checkType($value)
    {
        if( $this->type !== null ) {
            // check type constraints
            if( $this->isTypeInteger() ) {
                if( ! is_numeric($value) )
                    throw new NonNumericException;
                $value = (int) $value;
            }
        }
        return $value;
    }
778597
public function reverseTransform($value)
    {
        if (!is_scalar($value)) {
            throw new TransformationFailedException('Expected a scalar.');
        }

        if ('' === $value) {
            return null;
        }

        $result = $value;

        if (!is_numeric($result)) {
            throw new TransformationFailedException('Value is not numeric.');
        }

        if (\is_string($result)) {
            if (false !== mb_strpos($result, '.')) {
                $result = (float) $result;
            } else {
                $result = (int) $result;
            }
        }

        if ($result >= PHP_INT_MAX || $result <= -PHP_INT_MAX) {
            throw new TransformationFailedException('I don\'t have a clear idea what infinity looks like.');
        }

        return $this->round($result);
    }
657699
public static function convertUnmappedToPHPValue($value)
    {
        $type  = key($value);
        $value = current($value);

        switch ($type) {
            case 'S':
            case 'B':
            case 'BOOL':
                return $value;
            case 'NULL':
                return null;
            case 'N':
                // Use type coercion to unmarshal numbers to int/float.
                return $value + 0;
            case 'M':
            case 'L':
                foreach ($value as $k => $v) {
                    $value[$k] = self::convertUnmappedToPHPValue($v);
                }

                return $value;
            case 'BS':
            case 'NS':
            case 'SS':
                $childType = substr($type, 0, 1);

                return array_map(
                    function ($childValue) use ($childType) {
                        return self::convertUnmappedToPHPValue([$childType => $childValue]);
                    },
                    $value
                );
        }

        throw new \UnexpectedValueException("Unexpected type: $type.");
    }
239416
protected function getValueType($value)
    {
        switch (true) {
            case is_scalar($value):
                $type = gettype($value);
                break;

            case is_array($value):
                $type = 'array';
                break;

            case is_object($value):
                $type = get_class($value);
                break;

            case is_resource($value):
                $type = 'resource';
                break;

            default:
                $type = 'unknown';
                break;
        }

        return $type;
    }
1173812
protected function _getValueByType($value, $type)
	{
		if( !is_null($value) )
		{
			switch( $type )
			{
				case "id":
					if( array_contains( array('',null), $value, true ) )
					{
						$value = null;
					}
					else
					{
						$value = intval( $value );
					}
				break;
				case "bool":
				case "boolean":
					$value = (bool) $value;
				break;
				case "int":
					$value = (int) $value;
					break;
				case "float":
					$value = (float) $value;
				break;
				case "object":
				case "array":
					if(is_object($value) || !is_array($value))
					{
						$value = unserialize($value);
					}
				break;
				case "date":
					if($value == '0000-00-00' || $value == '')
					{
						$value = null;
					}
				break;
				case "time":
					if($value == '00:00:00' || $value == '')
					{
						$value = null;
					}
				break;
				case "datetime":
					if($value == '0000-00-00 00:00:00' || $value == '')
					{
						$value = null;
					}
				break;
				case "text":
				default:
					$value = (string) $value;
				break;
			}
		}

		return $value;
	}
1090488
private function getValueType($value)
	{
		if (is_numeric($value)) {
			return Type::NUMBER;
		}

		if (is_array($value)) {
			return Type::STRING_SET;
		}

		return Type::STRING;
	}
687678
public static function phpValueToJs($value)
    {
        // For object which has own __toString method
        if ($value instanceof JsModelAbstract) {
            return $value->toJsString();
        }
        // For object which has own __toString method
        elseif (is_object($value) && method_exists($value, '__toString')) {
            return self::phpValueToJs($value->__toString());
        }
        // For an object or associative array
        elseif (is_object($value) || (is_array($value) && array_values($value) !== $value)) {
            $jsObject = array();
            foreach ($value as $paramName => $paramValue) {
                $paramName = addcslashes($paramName, '\'\\');
                $jsObject[] = "'$paramName':" . self::phpValueToJs($paramValue);
            }

            return sprintf('{%1$s}', implode($jsObject, ','));
        }
        // For a sequential array
        elseif (is_array($value)) {
            $jsArray = array();
            foreach ($value as $item) {
                $jsArray[] = self::phpValueToJs($item);
            }

            return sprintf('[%1$s]', implode($jsArray, ','));
        }
        // For string
        elseif (is_string($value)) {
            $value = addcslashes($value, '\'\\');

            return "'$value'";
        }
        // For boolean
        elseif (is_bool($value)) {
            return true === $value ? 'true' : 'false';
        }
        // For numbers
        elseif (is_numeric($value)) {
            return $value;
        }
        // For null
        elseif (is_null($value)) {
            return 'null';
        }
        // Otherwise
        else {
            return 'undefined';
        }
    }
104444
public static function parse($value)
    {
        $expression = Expression::getExpression();

        $return = preg_match(
            $expression,
            $value,
            $matches
        );

        if (!$return) {
            return null;
        }

        $parsed = new \stdClass();

        $parsed->key = $matches['key'];
        $parsed->mode = Globals::KEY_VARIABLE;

        if (isset($matches['function']) && !empty($matches['function'])) {
            $parsed->mode = Globals::KEY_FUNCTION;

            if (key_exists('parameters', $matches)  && strlen((string)$matches['parameters'])) {
                //Handles only one parameter
                $parsed->parameters = [$matches['parameters']];
            }
        } elseif (isset($matches['array'])  && !empty($matches['array'])) {
            $parsed->mode = Globals::KEY_ARRAY;
            //should exists
            $parsed->index = $matches['index'];
        }

        return $parsed;
    }
1108836
public function transform($value)
    {
        if (null === $value) {
            return null;
        }

        if (!is_string($value)) {
            throw new UnexpectedTypeException($value, 'string');
        }

        return true;
    }
1222027
public static function decode($value)
    {
        if (empty($value)) {
            return null;
        }

        if (!is_string($value)) {
            throw new \InvalidArgumentException(sprintf(
                "Value type '%s' is not a PHP string so it cannot be unserialized.",
                gettype($value)
            ));
        }

        $data = unserialize($value);

        return $data;
    }
846813
function parseValue($value) {
        try {
            return \Plasma\Types\TypeExtensionsManager::getManager()->decodeType($this->type, $value)->getValue();
        } catch (\Plasma\Exception $e) {
            /* Continue regardless of error */
        }
        
        return $value;
    }
37492
protected function convertType(string $value)
    {
        $val = \mb_strtolower($value);
        if ($val === 'true') {
            return true;
        } elseif ($val === 'false') {
            return false;
        } elseif ($val === 'null') {
            return null;
        } elseif (\mb_strpos($val, '.') !== false && \is_numeric($val)) {
            return (float) $val;
        } elseif (\is_numeric($val)) {
            return (int) $val;
        }

        return $this->replaceVariables($value);
    }
570880
public static function resolveType($value): string
    {
        if (is_array($value)) {
            if (count($value) === 0) {
                return 'array';
            }

            return self::resolveType($value[0]) . '[]';
        }

        return is_object($value) ? get_class($value) : gettype($value);
    }