0 追蹤者

類別 yii\db\pgsql\ColumnSchema

繼承關係yii\db\pgsql\ColumnSchema » yii\db\ColumnSchema » yii\base\BaseObject
實作介面yii\base\Configurable
原始碼 https://github.com/yiisoft/yii2/blob/master/framework/db/pgsql/ColumnSchema.php

PostgreSQL 資料庫的 ColumnSchema 類別。

公開屬性

隱藏繼承的屬性

屬性 類型 描述 定義於
$allowNull boolean 指示此資料行是否可為空值。 yii\db\ColumnSchema
$autoIncrement boolean 指示此資料行是否為自動遞增 yii\db\ColumnSchema
$comment string 此資料行的註解。 yii\db\ColumnSchema
$dbType string 此資料行的資料庫類型。 yii\db\ColumnSchema
$defaultValue mixed 此資料行的預設值 yii\db\ColumnSchema
$deserializeArrayColumnToArrayExpression boolean 指示陣列資料行的值是否應反序列化為 yii\db\ArrayExpression 物件。 yii\db\pgsql\ColumnSchema
$dimension integer 陣列的維度。 yii\db\pgsql\ColumnSchema
$disableArraySupport boolean 指示資料行結構描述是否應省略使用 PgSQL 陣列支援功能。 yii\db\pgsql\ColumnSchema
$disableJsonSupport boolean 指示資料行結構描述是否應省略使用 JSON 支援功能。 yii\db\pgsql\ColumnSchema
$enumValues array 可列舉的值。 yii\db\ColumnSchema
$isPrimaryKey boolean 指示此資料行是否為主鍵 yii\db\ColumnSchema
$name string 此資料行的名稱 (不含引號)。 yii\db\ColumnSchema
$phpType string 此資料行的 PHP 類型。 yii\db\ColumnSchema
$precision integer 資料行資料的精確度 (若為數值)。 yii\db\ColumnSchema
$scale integer 資料行資料的刻度 (若為數值)。 yii\db\ColumnSchema
$sequenceName string 若資料行是自動遞增,則為關聯序列的名稱 yii\db\pgsql\ColumnSchema
$size integer 資料行的顯示大小。 yii\db\ColumnSchema
$type string 此資料行的抽象類型。 yii\db\ColumnSchema
$unsigned boolean 指示此資料行是否為無符號。 yii\db\ColumnSchema

公開方法

隱藏繼承的方法

方法 描述 定義於
__call() 呼叫指定的非類別方法。 yii\base\BaseObject
__construct() 建構子。 yii\base\BaseObject
__get() 傳回物件屬性的值。 yii\base\BaseObject
__isset() 檢查屬性是否已設定,即已定義且非空值。 yii\base\BaseObject
__set() 設定物件屬性的值。 yii\base\BaseObject
__unset() 將物件屬性設定為空值。 yii\base\BaseObject
canGetProperty() 傳回一個值,指示屬性是否可讀取。 yii\base\BaseObject
canSetProperty() 傳回一個值,指示屬性是否可設定。 yii\base\BaseObject
className() 傳回此類別的完整名稱。 yii\base\BaseObject
dbTypecast() 根據 $type$dbType 轉換輸入值,以用於資料庫查詢。 yii\db\pgsql\ColumnSchema
hasMethod() 傳回值,指出是否已定義方法。 yii\base\BaseObject
hasProperty() 傳回值,指出是否已定義屬性。 yii\base\BaseObject
init() 初始化物件。 yii\base\BaseObject
phpTypecast() 從資料庫檢索後,根據 $phpType 轉換輸入值。 yii\db\pgsql\ColumnSchema

受保護的方法

隱藏繼承的方法

方法 描述 定義於
getArrayParser() 建立 ArrayParser 的實例 yii\db\pgsql\ColumnSchema
phpTypecastValue() 從 DBMS 檢索後,將 $value 轉換為 PHP 表示法。 yii\db\pgsql\ColumnSchema
typecast() 從資料庫檢索後,根據 $phpType 轉換輸入值。 yii\db\ColumnSchema

屬性詳細資訊

隱藏繼承的屬性

$deserializeArrayColumnToArrayExpression public 屬性 (自版本 2.0.14.1 起可用)
自 2.0.14.1 版本起已棄用,並將在 2.1 版本中移除。

Array 欄位值是否應反序列化為 yii\db\ArrayExpression 物件。您可以使用此屬性,以便更輕鬆地升級到 Yii 2.0.14。預設為 true,表示陣列會反序列化為 yii\db\ArrayExpression 物件。

$dimension public 屬性

陣列的維度。預設為 0,表示此欄位不是陣列。

public integer $dimension 0
$disableArraySupport public 屬性 (自版本 2.0.14.1 起可用)
自 2.0.14.1 版本起已棄用,並將在 2.1 版本中移除。

欄位綱要是否應省略使用 PgSQL 陣列支援功能。您可以使用此屬性,以便更輕鬆地升級到 Yii 2.0.14。預設為 false,表示已啟用陣列支援。

$disableJsonSupport public 屬性 (自版本 2.0.14.1 起可用)
自 2.0.14.1 版本起已棄用,並將在 2.1 版本中移除。

欄位綱要是否應省略使用 JSON 支援功能。您可以使用此屬性,以便更輕鬆地升級到 Yii 2.0.14。預設為 false,表示已啟用 JSON 支援。

$sequenceName public 屬性 (自版本 2.0.29 起可用)

若資料行是自動遞增,則為關聯序列的名稱

public string $sequenceName null

方法詳細資訊

隱藏繼承的方法

__call() public 方法

定義於: yii\base\BaseObject::__call()

呼叫指定的非類別方法。

請勿直接呼叫此方法,因為當呼叫未知方法時,PHP 魔術方法會隱含地呼叫它。

public mixed __call ( $name, $params )
$name string

方法名稱

$params array

方法參數

return mixed

方法傳回值

throws yii\base\UnknownMethodException

當呼叫未知方法時

                public function __call($name, $params)
{
    throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}

            
__construct() public 方法

定義於: yii\base\BaseObject::__construct()

建構子。

預設實作會執行兩件事

  • 使用給定的組態 $config 初始化物件。
  • 呼叫 init()

如果子類別中覆寫了此方法,建議

  • 建構子的最後一個參數是組態陣列,如這裡的 $config
  • 在建構子的結尾呼叫父類別的實作。
public void __construct ( $config = [] )
$config array

將用於初始化物件屬性的名稱-值對

                public function __construct($config = [])
{
    if (!empty($config)) {
        Yii::configure($this, $config);
    }
    $this->init();
}

            
__get() public 方法

定義於: yii\base\BaseObject::__get()

傳回物件屬性的值。

請勿直接呼叫此方法,因為當執行 $value = $object->property; 時,PHP 魔術方法會隱含地呼叫它。

另請參閱 __set()

public mixed __get ( $name )
$name string

屬性名稱

return mixed

屬性值

throws yii\base\UnknownPropertyException

如果未定義屬性

throws yii\base\InvalidCallException

如果屬性為唯寫

                public function __get($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter();
    } elseif (method_exists($this, 'set' . $name)) {
        throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
    }
    throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}

            
__isset() public 方法

定義於: yii\base\BaseObject::__isset()

檢查屬性是否已設定,即已定義且非空值。

請勿直接呼叫此方法,因為當執行 isset($object->property) 時,PHP 魔術方法會隱含地呼叫它。

請注意,如果未定義屬性,將傳回 false。

另請參閱 https://php.dev.org.tw/manual/en/function.isset.php

public boolean __isset ( $name )
$name string

屬性名稱或事件名稱

return boolean

具名屬性是否已設定 (非 null)。

                public function __isset($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter() !== null;
    }
    return false;
}

            
__set() public 方法

定義於: yii\base\BaseObject::__set()

設定物件屬性的值。

請勿直接呼叫此方法,因為當執行 $object->property = $value; 時,PHP 魔術方法會隱含地呼叫它。

另請參閱 __get()

public void __set ( $name, $value )
$name string

屬性名稱或事件名稱

$value mixed

屬性值

throws yii\base\UnknownPropertyException

如果未定義屬性

throws yii\base\InvalidCallException

如果屬性為唯讀

                public function __set($name, $value)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter($value);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
    } else {
        throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
    }
}

            
__unset() public 方法

定義於: yii\base\BaseObject::__unset()

將物件屬性設定為空值。

請勿直接呼叫此方法,因為當執行 unset($object->property) 時,PHP 魔術方法會隱含地呼叫它。

請注意,如果未定義屬性,此方法將不會執行任何動作。如果屬性為唯讀,則會擲回例外。

另請參閱 https://php.dev.org.tw/manual/en/function.unset.php

public void __unset ( $name )
$name string

屬性名稱

throws yii\base\InvalidCallException

如果屬性為唯讀。

                public function __unset($name)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter(null);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
    }
}

            
canGetProperty() public 方法

定義於: yii\base\BaseObject::canGetProperty()

傳回一個值,指示屬性是否可讀取。

如果符合以下條件,則屬性為可讀取:

  • 類別具有與指定名稱關聯的 getter 方法 (在此情況下,屬性名稱不區分大小寫);
  • 類別具有帶有指定名稱的成員變數 (當 $checkVars 為 true 時);

另請參閱 canSetProperty()

public boolean canGetProperty ( $name, $checkVars true )
$name string

屬性名稱

$checkVars boolean

是否將成員變數視為屬性

return boolean

屬性是否可讀取

                public function canGetProperty($name, $checkVars = true)
{
    return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}

            
canSetProperty() public 方法

定義於: yii\base\BaseObject::canSetProperty()

傳回一個值,指示屬性是否可設定。

如果符合以下條件,則屬性為可寫入:

  • 類別具有與指定名稱關聯的 setter 方法 (在此情況下,屬性名稱不區分大小寫);
  • 類別具有帶有指定名稱的成員變數 (當 $checkVars 為 true 時);

另請參閱 canGetProperty()

public boolean canSetProperty ( $name, $checkVars true )
$name string

屬性名稱

$checkVars boolean

是否將成員變數視為屬性

return boolean

屬性是否可寫入

                public function canSetProperty($name, $checkVars = true)
{
    return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}

            
className() public 靜態方法
自 2.0.14 版本起已棄用。在 PHP >=5.5 上,請改用 ::class

定義於: yii\base\BaseObject::className()

傳回此類別的完整名稱。

public static string className ( )
return string

此類別的完整名稱。

                public static function className()
{
    return get_called_class();
}

            
dbTypecast() public 方法

根據 $type$dbType 轉換輸入值,以用於資料庫查詢。

如果值為 null 或 yii\db\Expression,則不會轉換。

public mixed dbTypecast ( $value )
$value mixed

輸入值

return mixed

轉換後的值。這也可能是一個陣列,其中包含值作為第一個元素,PDO 型別作為第二個元素。

                public function dbTypecast($value)
{
    if ($value === null) {
        return $value;
    }
    if ($value instanceof ExpressionInterface) {
        return $value;
    }
    if ($this->dimension > 0) {
        return $this->disableArraySupport
            ? (string) $value
            : new ArrayExpression($value, $this->dbType, $this->dimension);
    }
    if (!$this->disableJsonSupport && in_array($this->dbType, [Schema::TYPE_JSON, Schema::TYPE_JSONB], true)) {
        return new JsonExpression($value, $this->dbType);
    }
    return $this->typecast($value);
}

            
getArrayParser() protected 方法

建立 ArrayParser 的實例

protected yii\db\pgsql\ArrayParser getArrayParser ( )

                protected function getArrayParser()
{
    static $parser = null;
    if ($parser === null) {
        $parser = new ArrayParser();
    }
    return $parser;
}

            
hasMethod() public 方法

定義於: yii\base\BaseObject::hasMethod()

傳回值,指出是否已定義方法。

預設實作是對 php 函數 method_exists() 的呼叫。當您實作 php 魔術方法 __call() 時,您可以覆寫此方法。

public boolean hasMethod ( $name )
$name string

方法名稱

return boolean

方法是否已定義

                public function hasMethod($name)
{
    return method_exists($this, $name);
}

            
hasProperty() public 方法

定義於: yii\base\BaseObject::hasProperty()

傳回值,指出是否已定義屬性。

如果符合以下條件,則屬性已定義:

  • 類別具有與指定名稱關聯的 getter 或 setter 方法 (在此情況下,屬性名稱不區分大小寫);
  • 類別具有帶有指定名稱的成員變數 (當 $checkVars 為 true 時);

另請參閱

public boolean hasProperty ( $name, $checkVars true )
$name string

屬性名稱

$checkVars boolean

是否將成員變數視為屬性

return boolean

屬性是否已定義

                public function hasProperty($name, $checkVars = true)
{
    return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}

            
init() public 方法

定義於: yii\base\BaseObject::init()

初始化物件。

在物件以給定組態初始化後,將在建構子的結尾呼叫此方法。

public void init ( )

                public function init()
{
}

            
phpTypecast() public 方法

從資料庫檢索後,根據 $phpType 轉換輸入值。

如果值為 null 或 yii\db\Expression,則不會轉換。

public mixed phpTypecast ( $value )
$value mixed

輸入值

return mixed

轉換後的值

                public function phpTypecast($value)
{
    if ($this->dimension > 0) {
        if ($this->disableArraySupport) {
            return $value;
        }
        if (!is_array($value)) {
            $value = $this->getArrayParser()->parse($value);
        }
        if (is_array($value)) {
            array_walk_recursive($value, function (&$val, $key) {
                $val = $this->phpTypecastValue($val);
            });
        } elseif ($value === null) {
            return null;
        }
        return $this->deserializeArrayColumnToArrayExpression
            ? new ArrayExpression($value, $this->dbType, $this->dimension)
            : $value;
    }
    return $this->phpTypecastValue($value);
}

            
phpTypecastValue() protected 方法

從 DBMS 檢索後,將 $value 轉換為 PHP 表示法。

protected boolean|mixed|null phpTypecastValue ( $value )
$value string|null

                protected function phpTypecastValue($value)
{
    if ($value === null) {
        return null;
    }
    switch ($this->type) {
        case Schema::TYPE_BOOLEAN:
            switch (strtolower($value)) {
                case 't':
                case 'true':
                    return true;
                case 'f':
                case 'false':
                    return false;
            }
            return (bool) $value;
        case Schema::TYPE_JSON:
            return $this->disableJsonSupport ? $value : json_decode($value, true);
    }
    return parent::phpTypecast($value);
}

            
typecast() protected 方法 (自版本 2.0.3 起可用)

定義於: yii\db\ColumnSchema::typecast()

從資料庫檢索後,根據 $phpType 轉換輸入值。

如果值為 null 或 yii\db\Expression,則不會轉換。

protected mixed typecast ( $value )
$value mixed

輸入值

return mixed

轉換後的值

                protected function typecast($value)
{
    if (
        $value === ''
        && !in_array(
            $this->type,
            [
                Schema::TYPE_TEXT,
                Schema::TYPE_STRING,
                Schema::TYPE_BINARY,
                Schema::TYPE_CHAR
            ],
            true
        )
    ) {
        return null;
    }
    if (
        $value === null
        || gettype($value) === $this->phpType
        || $value instanceof ExpressionInterface
        || $value instanceof Query
    ) {
        return $value;
    }
    if (
        is_array($value)
        && count($value) === 2
        && isset($value[1])
        && in_array($value[1], $this->getPdoParamTypes(), true)
    ) {
        return new PdoValue($value[0], $value[1]);
    }
    switch ($this->phpType) {
        case 'resource':
        case 'string':
            if (is_resource($value)) {
                return $value;
            }
            if (is_float($value)) {
                // ensure type cast always has . as decimal separator in all locales
                return StringHelper::floatToString($value);
            }
            if (
                is_numeric($value)
                && ColumnSchemaBuilder::CATEGORY_NUMERIC === ColumnSchemaBuilder::$typeCategoryMap[$this->type]
            ) {
                // https://github.com/yiisoft/yii2/issues/14663
                return $value;
            }
            if (PHP_VERSION_ID >= 80100 && is_object($value) && $value instanceof \BackedEnum) {
                return (string) $value->value;
            }
            return (string) $value;
        case 'integer':
            if (PHP_VERSION_ID >= 80100 && is_object($value) && $value instanceof \BackedEnum) {
                return (int) $value->value;
            }
            return (int) $value;
        case 'boolean':
            // treating a 0 bit value as false too
            // https://github.com/yiisoft/yii2/issues/9006
            return (bool) $value && $value !== "\0" && strtolower($value) !== 'false';
        case 'double':
            return (float) $value;
    }
    return $value;
}