0 位追蹤者

類別 yii\db\SqlToken

所有類別 | 屬性 | 方法 | 常數
繼承yii\db\SqlToken » yii\base\BaseObject
實作ArrayAccess, yii\base\Configurable
自版本起可用2.0.13
原始碼 https://github.com/yiisoft/yii2/blob/master/framework/db/SqlToken.php

SqlToken 代表由 yii\db\SqlTokenizer 或其子類別產生的 SQL 語法單元。

公開屬性

隱藏繼承的屬性

屬性 類型 描述 定義於
$children yii\db\SqlToken[] 子語法單元。 yii\db\SqlToken
$content string|null 語法單元內容。 yii\db\SqlToken
$endOffset integer 原始 SQL 語法單元結束位置。 yii\db\SqlToken
$hasChildren boolean 語法單元是否包含子語法單元。 yii\db\SqlToken
$isCollection boolean 語法單元是否代表語法單元集合。 yii\db\SqlToken
$parent yii\db\SqlToken Parent token. yii\db\SqlToken
$sql string SQL 程式碼。 yii\db\SqlToken
$startOffset integer Original SQL token start position. yii\db\SqlToken
$type integer 語法單元類型。 yii\db\SqlToken

公開方法

隱藏繼承的方法

方法 描述 定義於
__call() 呼叫未定義為類別方法的指定方法。 yii\base\BaseObject
__construct() 建構子。 yii\base\BaseObject
__get() 傳回物件屬性的值。 yii\base\BaseObject
__isset() 檢查屬性是否已設定,亦即已定義且非 null。 yii\base\BaseObject
__set() 設定物件屬性的值。 yii\base\BaseObject
__toString() 傳回代表語法單元的 SQL 程式碼。 yii\db\SqlToken
__unset() 將物件屬性設定為 null。 yii\base\BaseObject
canGetProperty() 傳回值,指示屬性是否可讀取。 yii\base\BaseObject
canSetProperty() 傳回值,指示屬性是否可設定。 yii\base\BaseObject
className() 傳回此類別的完整限定名稱。 yii\base\BaseObject
getChildren() 傳回子語法單元。 yii\db\SqlToken
getHasChildren() 傳回此權杖是否代表權杖集合,且是否包含非零數量的子權杖。 yii\db\SqlToken
getIsCollection() 傳回此權杖是否代表權杖集合。 yii\db\SqlToken
getSql() 傳回代表語法單元的 SQL 程式碼。 yii\db\SqlToken
hasMethod() 傳回一個值,指出是否已定義方法。 yii\base\BaseObject
hasProperty() 傳回一個值,指出是否已定義屬性。 yii\base\BaseObject
init() 初始化物件。 yii\base\BaseObject
matches() 傳回此權杖(包含其子權杖)是否符合指定的「pattern」SQL 程式碼。 yii\db\SqlToken
offsetExists() 傳回在指定偏移量處是否有子權杖。 yii\db\SqlToken
offsetGet() 傳回在指定偏移量處的子權杖。 yii\db\SqlToken
offsetSet() 將子權杖新增至此權杖。 yii\db\SqlToken
offsetUnset() 移除在指定偏移量處的子權杖。 yii\db\SqlToken
setChildren() 設定子權杖的列表。 yii\db\SqlToken

Constants

隱藏繼承的常數

Constant Value 描述 定義於
TYPE_CODE 0 yii\db\SqlToken
TYPE_IDENTIFIER 6 yii\db\SqlToken
TYPE_KEYWORD 4 yii\db\SqlToken
TYPE_OPERATOR 5 yii\db\SqlToken
TYPE_PARENTHESIS 3 yii\db\SqlToken
TYPE_STATEMENT 1 yii\db\SqlToken
TYPE_STRING_LITERAL 7 yii\db\SqlToken
TYPE_TOKEN 2 yii\db\SqlToken

Property Details

隱藏繼承的屬性

$children public property

子語法單元。

public yii\db\SqlToken[] $children null
$content public property

語法單元內容。

public string|null $content null
$endOffset public property

原始 SQL 語法單元結束位置。

public integer $endOffset null
$hasChildren public property

語法單元是否包含子語法單元。

public boolean $hasChildren null
$isCollection public property

語法單元是否代表語法單元集合。

public boolean $isCollection null
$parent public property

Parent token.

public yii\db\SqlToken $parent null
$sql public property

SQL 程式碼。

public string $sql null
$startOffset public property

Original SQL token start position.

public integer $startOffset null
$type public property
public integer $type self::TYPE_TOKEN

Method Details

隱藏繼承的方法

__call() public method

Defined in: 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 method

Defined in: 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 method

Defined in: yii\base\BaseObject::__get()

傳回物件屬性的值。

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

另請參閱 __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 method

Defined in: yii\base\BaseObject::__isset()

檢查屬性是否已設定,亦即已定義且非 null。

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

請注意,如果未定義屬性,將會傳回 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 method

Defined in: yii\base\BaseObject::__set()

設定物件屬性的值。

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

另請參閱 __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);
    }
}

            
__toString() public method

傳回代表語法單元的 SQL 程式碼。

public string __toString ( )
return string

SQL 程式碼。

                public function __toString()
{
    return $this->getSql();
}

            
__unset() public method

Defined in: yii\base\BaseObject::__unset()

將物件屬性設定為 null。

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

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

另請參閱 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 method

Defined in: 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 method

Defined in: 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 static method
自 2.0.14 版本起已棄用。在 PHP >=5.5 版本上,請改用 ::class

Defined in: yii\base\BaseObject::className()

傳回此類別的完整限定名稱。

public static string className ( )
return string

此類別的完整限定名稱。

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

            
getChildren() public method

傳回子語法單元。

public yii\db\SqlToken[] getChildren ( )
return yii\db\SqlToken[]

子語法單元。

                public function getChildren()
{
    return $this->_children;
}

            
getHasChildren() public method

傳回此權杖是否代表權杖集合,且是否包含非零數量的子權杖。

public boolean getHasChildren ( )
return boolean

語法單元是否包含子語法單元。

                public function getHasChildren()
{
    return $this->getIsCollection() && !empty($this->_children);
}

            
getIsCollection() public method

傳回此權杖是否代表權杖集合。

public boolean getIsCollection ( )
return boolean

語法單元是否代表語法單元集合。

                public function getIsCollection()
{
    return in_array($this->type, [
        self::TYPE_CODE,
        self::TYPE_STATEMENT,
        self::TYPE_PARENTHESIS,
    ], true);
}

            
getSql() public method

傳回代表語法單元的 SQL 程式碼。

public string getSql ( )
return string

SQL 程式碼。

                public function getSql()
{
    $code = $this;
    while ($code->parent !== null) {
        $code = $code->parent;
    }
    return mb_substr($code->content, $this->startOffset, $this->endOffset - $this->startOffset, 'UTF-8');
}

            
hasMethod() public method

Defined in: 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 method

Defined in: 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 method

Defined in: yii\base\BaseObject::init()

初始化物件。

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

public void init ( )

                public function init()
{
}

            
matches() public method

傳回此權杖(包含其子權杖)是否符合指定的「pattern」SQL 程式碼。

用法範例

$patternToken = (new \yii\db\sqlite\SqlTokenizer('SELECT any FROM any'))->tokenize();
if ($sqlToken->matches($patternToken, 0, $firstMatchIndex, $lastMatchIndex)) {
    // ...
}
public boolean matches ( yii\db\SqlToken $patternToken, $offset 0, &$firstMatchIndex null, &$lastMatchIndex null )
$patternToken yii\db\SqlToken

要比對的權杖化 SQL 程式碼。除了標準 SQL 之外,還支援 any 關鍵字,它將比對任何數量的關鍵字、識別符、空白字元。

$offset integer

開始查找的權杖子項偏移量。

$firstMatchIndex integer|null

成功比對開始的權杖子項偏移量。

$lastMatchIndex integer|null

成功比對結束的權杖子項偏移量。

return boolean

指示此權杖是否符合模式 SQL 程式碼。

                public function matches(SqlToken $patternToken, $offset = 0, &$firstMatchIndex = null, &$lastMatchIndex = null)
{
    if (!$patternToken->getHasChildren()) {
        return false;
    }
    $patternToken = $patternToken[0];
    return $this->tokensMatch($patternToken, $this, $offset, $firstMatchIndex, $lastMatchIndex);
}

            
offsetExists() public method

傳回在指定偏移量處是否有子權杖。

此方法是 SPL ArrayAccess 介面所要求的。當您使用類似 isset($token[$offset]) 的語法時,會隱含地呼叫它。

public boolean offsetExists ( $offset )
$offset integer

子權杖偏移量。

return boolean

指示權杖是否存在。

                #[\ReturnTypeWillChange]
public function offsetExists($offset)
{
    return isset($this->_children[$this->calculateOffset($offset)]);
}

            
offsetGet() public method

傳回在指定偏移量處的子權杖。

此方法是 SPL ArrayAccess 介面所要求的。當您使用類似 $child = $token[$offset]; 的語法時,會隱含地呼叫它。

public yii\db\SqlToken|null offsetGet ( $offset )
$offset integer

子權杖偏移量。

return yii\db\SqlToken|null

指定偏移量處的子權杖,如果沒有權杖則為 null

                #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
    $offset = $this->calculateOffset($offset);
    return isset($this->_children[$offset]) ? $this->_children[$offset] : null;
}

            
offsetSet() public method

將子權杖新增至此權杖。

此方法是 SPL ArrayAccess 介面所要求的。當您使用類似 $token[$offset] = $child; 的語法時,會隱含地呼叫它。

public void offsetSet ( $offset, $token )
$offset integer|null

子權杖偏移量。

$token yii\db\SqlToken

要新增的權杖。

                #[\ReturnTypeWillChange]
public function offsetSet($offset, $token)
{
    $token->parent = $this;
    if ($offset === null) {
        $this->_children[] = $token;
    } else {
        $this->_children[$this->calculateOffset($offset)] = $token;
    }
    $this->updateCollectionOffsets();
}

            
offsetUnset() public method

移除在指定偏移量處的子權杖。

此方法是 SPL ArrayAccess 介面所要求的。當您使用類似 unset($token[$offset]) 的語法時,會隱含地呼叫它。

public void offsetUnset ( $offset )
$offset integer

子權杖偏移量。

                #[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
    $offset = $this->calculateOffset($offset);
    if (isset($this->_children[$offset])) {
        array_splice($this->_children, $offset, 1);
    }
    $this->updateCollectionOffsets();
}

            
setChildren() public method

設定子權杖的列表。

public void setChildren ( $children )
$children yii\db\SqlToken[]

子語法單元。

                public function setChildren($children)
{
    $this->_children = [];
    foreach ($children as $child) {
        $child->parent = $this;
        $this->_children[] = $child;
    }
    $this->updateCollectionOffsets();
}