クラス yii\db\ArrayExpression
| 継承 | yii\db\ArrayExpression |
|---|---|
| 実装 | ArrayAccess、Countable、IteratorAggregate、yii\db\ExpressionInterface |
| 利用可能なバージョン | 2.0.14 |
| ソースコード | https://github.com/yiisoft/yii2/blob/master/framework/db/ArrayExpression.php |
クラス ArrayExpression は、配列のSQL式を表します。
このタイプの式は、条件の中でも使用できます。
$query->andWhere(['@>', 'items', new ArrayExpression([1, 2, 3], 'integer')])
これは、DBMS によって、適切に準備された条件になります。例えば、PostgreSQL では、WHERE "items" @> ARRAY[1, 2, 3]::integer[] とコンパイルされます。
公開メソッド
| メソッド | 説明 | 定義元 |
|---|---|---|
| __construct() | ArrayExpression コンストラクタ。 | yii\db\ArrayExpression |
| count() | オブジェクトの要素数を数えます。 | yii\db\ArrayExpression |
| getDimension() | yii\db\ArrayExpression | |
| getIterator() | 外部イテレータを取得します。 | yii\db\ArrayExpression |
| getType() | yii\db\ArrayExpression | |
| getValue() | yii\db\ArrayExpression | |
| offsetExists() | オフセットが存在するかどうか。 | yii\db\ArrayExpression |
| offsetGet() | 取得するオフセット。 | yii\db\ArrayExpression |
| offsetSet() | 設定するオフセット。 | yii\db\ArrayExpression |
| offsetUnset() | 設定解除するオフセット。 | yii\db\ArrayExpression |
メソッドの詳細
ArrayExpression コンストラクタ。
| public void __construct ( $value、$type = null、$dimension = 1 ) | ||
| $value | array|yii\db\QueryInterface|混合 |
配列の内容。値の配列、またはこれらの値を返すクエリとして表されます。単一の値は、1つの要素を含む配列として扱われます。 |
| $type | string|null |
配列要素の型。デフォルトは |
| $dimension | integer |
要素を選択するために必要なインデックスの数。 |
public function __construct($value, $type = null, $dimension = 1)
{
if ($value instanceof self) {
$value = $value->getValue();
}
$this->value = $value;
$this->type = $type;
$this->dimension = $dimension;
}
オブジェクトの要素数を数えます。
| public integer count ( ) | ||
| 戻り値 | integer |
カスタムカウントを整数で返します。 戻り値は整数に変換されます。 |
|---|---|---|
#[\ReturnTypeWillChange]
public function count()
{
return count($this->value);
}
| public integer getDimension ( ) | ||
| 戻り値 | integer |
要素を選択するために必要なインデックスの数。 |
|---|---|---|
public function getDimension()
{
return $this->dimension;
}
外部イテレータを取得します。
| public Traversable getIterator ( ) | ||
| 戻り値 | Traversable |
IteratorまたはTraversableを実装するオブジェクトのインスタンス。 |
|---|---|---|
| スロー | yii\base\InvalidConfigException |
ArrayExpressionがQueryInterfaceオブジェクトを含む場合。 |
#[\ReturnTypeWillChange]
public function getIterator()
{
$value = $this->getValue();
if ($value instanceof QueryInterface) {
throw new InvalidConfigException('The ArrayExpression class can not be iterated when the value is a QueryInterface object');
}
if ($value === null) {
$value = [];
}
return new \ArrayIterator($value);
}
| public array|混合|yii\db\QueryInterface getValue ( ) |
public function getValue()
{
return $this->value;
}
オフセットが存在するかどうか。
| public boolean offsetExists ( $offset ) | ||
| $offset | mixed |
チェック対象のオフセット。 |
| 戻り値 | boolean |
成功時はtrue、失敗時はfalse。 ブール値以外が返された場合、ブール値に変換されます。 |
|---|---|---|
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->value[$offset]);
}
取得するオフセット。
| public mixed offsetGet ( $offset ) | ||
| $offset | mixed |
取得するオフセット。 |
| 戻り値 | mixed |
あらゆる型の値を返す可能性があります。 |
|---|---|---|
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->value[$offset];
}
設定するオフセット。
| public void offsetSet ( $offset, $value ) | ||
| $offset | mixed |
値を代入するオフセット。 |
| $value | mixed |
設定する値。 |
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->value[$offset] = $value;
}
設定解除するオフセット。
| public void offsetUnset ( $offset ) | ||
| $offset | mixed |
解除するオフセット。 |
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->value[$offset]);
}
サインアップ または ログイン してコメントしてください。