123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <?php
- namespace yii\db;
- use Traversable;
- use yii\base\InvalidConfigException;
- class ArrayExpression implements ExpressionInterface, \ArrayAccess, \Countable, \IteratorAggregate
- {
-
- private $type;
-
- private $value;
-
- private $dimension;
-
- 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 function getType()
- {
- return $this->type;
- }
-
- public function getValue()
- {
- return $this->value;
- }
-
- public function getDimension()
- {
- return $this->dimension;
- }
-
- public function offsetExists($offset)
- {
- return isset($this->value[$offset]);
- }
-
- public function offsetGet($offset)
- {
- return $this->value[$offset];
- }
-
- public function offsetSet($offset, $value)
- {
- $this->value[$offset] = $value;
- }
-
- public function offsetUnset($offset)
- {
- unset($this->value[$offset]);
- }
-
- public function count()
- {
- return count($this->value);
- }
-
- 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);
- }
- }
|