Cast column value to PHP type

@param mixed $value
@param string $column
@return mixed
@throws \Exception
544567
protected function castToPhp($value, $column)
    {
        if ($value !== null && $this->hasCast($column) && !$this->isIgnoreCast($value)) {
            $value = $this->toPhpType($value, $this->casts[$column]);
        }

        return $value;
    }
991437
public function setValue(string $column, string $value)
    {
        $instance = $this->updateQueryInstance();

        $instance->updateQuery()->set($column, $value);

        return $instance;
    }
1373038
public function dbTypecastValue($value)
    {
        if ($value === null) {
            return null;
        }

        switch ($this->type) {
            case Schema::TYPE_BIT:
                return decbin($value);
            case Schema::TYPE_BINARY:
                return is_string($value) ? new PdoValue($value, \PDO::PARAM_LOB) : $value;
            case Schema::TYPE_TIMESTAMP:
            case Schema::TYPE_DATETIME:
                return \Yii::$app->formatter->asDatetime($value, 'yyyy-MM-dd HH:mm:ss');
            case Schema::TYPE_DATE:
                return \Yii::$app->formatter->asDate($value, 'yyyy-MM-dd');
            case Schema::TYPE_TIME:
                return \Yii::$app->formatter->asTime($value, 'HH:mm:ss');
            case Schema::TYPE_JSON:
                return new JsonExpression($value, $this->dbType);
            case Schema::TYPE_COMPOSITE:
                return new CompositeExpression($value, $this->dbType, $this);
        }

        return $this->typecast($value);
    }
374729
protected function evalSwitchTypeValue($record, $column, $value)
    {
        $contents = '';

        if ($value) {
            $contents = Lang::get('backend::lang.list.column_switch_true');
        }
        else {
            $contents = Lang::get('backend::lang.list.column_switch_false');
        }

        return $contents;
    }
937081
protected function validTypes(Column $column)
    {

        if (in_array($column->getType(), $this->columns) === false) {
            throw new ExceptionFactory('Column', ['COLUMN_DOES_NOT_SUPPORT', $column->getType(), $column->getName()]);
        }

        return true;
    }
989986
protected function castToType($value, $property)
    {
        $type = $this->getPropertyType($property);

        switch ($type) {
            case 'array':
                return is_array($value) ? $value : explode(",", $value);
            case 'bool':
            case 'boolean':
                return (boolean) $value;
            case 'int':
            case 'integer':
                return (int) $value;
            case 'string':
                return (string) $value;
            default:
                return $value;
        }
    }
201991
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;
    }
507247
public function castColumn($column)
    {
        $column = $this->connection->getQueryGrammar()->wrap($column);
        if ($this->database === 'pgsql') {
            $column = 'CAST(' . $column . ' as TEXT)';
        } elseif ($this->database === 'firebird') {
            $column = 'CAST(' . $column . ' as VARCHAR(255))';
        }

        return $column;
    }
745249
public function postField($column, $value = null)
    {
        // If the column is an array, we will assume it is an array of key-value pairs
        // and can add them each as a post field.
        if (is_array($column)) {
            return $this->postFieldNested(function ($query) use ($column) {
                foreach ($column as $key => $value) {
                    $query->postField($key, $value);
                }
            });
        }

        $this->body[] = compact('column', 'value');

        return $this;
    }
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;
        }
    }
441478
protected function cast($type, $value)
    {
        switch ($type) {
            case 'int':
            case 'integer':
            case 'tinyint':
            case 'smallint':
            case 'mediumint':
            case 'bigint':
                return (int)$value;
            case 'bit':
                return (bool)$value;
            case 'timestamp':
                return new Carbon($value);
            default:
                return $value;
        }
    }
510945
public static function typeCast($value, $type) {
		switch ($type) {
			case 'int':
				$value = (int)$value;
				break;
			case 'float':
				$value = (float)$value;
				break;
			case 'double':
				$value = (double)$value;
				break;
			case 'array':
				$value = (array)$value;
				break;
			case 'bool':
				$value = (bool)$value;
				break;
			case 'string':
				$value = (string)$value;
				break;
			default:
				return null;
		}
		return $value;
	}
1232005
private function cast($value, $type)
    {
        switch ($type) {
            case 'bool':
                return boolval($value);
                break;
            case 'int':
                return intval($value);
                break;
            case 'float':
                return floatval($value);
                break;
            case 'string':
                return $value;
                break;
            case 'array':
                if (is_array($value)) {
                    return serialize($value);
                } else {
                    return unserialize($value);
                }
                break;
            default:
                return $value;
        }
    }
950194
final public function deleteByColumn($column, $value)
    {
        $this->validateShortcutData();

        return $this->db->delete()
                        ->from(static::getTableName())
                        ->whereEquals($column, $value)
                        ->execute();
    }
1265456
public function gt($column, $value = null)
    {
        return $this->where($column, $value, Cmp::GT);
    }
380431
private function findAliasedValue(string $column, $value) {
		$alias = null;
		foreach ($this->alias_data as $k => $v) {
			// todo: maybe need column prefix with alias
			if (strpos($column, $k) !== false) {
				$alias = $k;
				break;
			}
		}
		if (!empty($alias)) {
			return $this->alias_object->getIdByCode($alias, str_replace('::id::', '', $value), true, ['skip_acl' => true]);
		} else {
			return false;
		}
	}
688092
protected function processColumnValue($column, $value)
	{
		if (!($column instanceof CDataColumn))
			return;

		if (!array_key_exists($column->name, $this->extendedSummary['columns']))
			return;

		$config = $this->extendedSummary['columns'][$column->name];
		$config['column'] = $column;

		$this->getSummaryOperationInstance($column->name, $config)
			->processValue($value);
	}