Final Class Yiisoft\Db\Schema\Data\JsonLazyArray
| Inheritance | Yiisoft\Db\Schema\Data\JsonLazyArray |
|---|---|
| Implements | ArrayAccess, Countable, IteratorAggregate, JsonSerializable, Yiisoft\Db\Schema\Data\LazyArrayInterface |
| Uses Traits | Yiisoft\Db\Schema\Data\LazyArrayTrait |
Represents a JSON array value retrieved from the database.
Initially, the value is a string that parsed into an array when it's accessed as an array or iterated over.
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $value | array|string | Yiisoft\Db\Schema\Data\JsonLazyArray |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Db\Schema\Data\JsonLazyArray | |
| count() | Yiisoft\Db\Schema\Data\LazyArrayTrait | |
| getIterator() | Yiisoft\Db\Schema\Data\LazyArrayTrait | |
| getRawValue() | The raw value that can be represented as: - a string retrieved value from the database that can be parsed into an array; - an array of values if the value is already parsed. | Yiisoft\Db\Schema\Data\LazyArrayTrait |
| getValue() | Returns parsed and typecasted value. | Yiisoft\Db\Schema\Data\LazyArrayTrait |
| jsonSerialize() | Yiisoft\Db\Schema\Data\LazyArrayTrait | |
| offsetExists() | Yiisoft\Db\Schema\Data\LazyArrayTrait | |
| offsetGet() | Yiisoft\Db\Schema\Data\LazyArrayTrait | |
| offsetSet() | Yiisoft\Db\Schema\Data\LazyArrayTrait | |
| offsetUnset() | Yiisoft\Db\Schema\Data\LazyArrayTrait |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| prepareValue() | Prepares the value to be used as an array or throws an exception if it's impossible. | Yiisoft\Db\Schema\Data\JsonLazyArray |
Property Details
Method Details
| public mixed __construct ( string $value ) | ||
| $value | string |
The string retrieved value from the database that can be parsed into an array. |
public function __construct(
string $value,
) {
$this->value = $value;
}
Defined in: Yiisoft\Db\Schema\Data\LazyArrayTrait::count()
| public integer count ( ) |
public function count(): int
{
$this->prepareValue();
return count($this->value);
}
| public ArrayIterator getIterator ( ) |
public function getIterator(): ArrayIterator
{
$this->prepareValue();
return new ArrayIterator($this->value);
}
Defined in: Yiisoft\Db\Schema\Data\LazyArrayTrait::getRawValue()
The raw value that can be represented as: - a string retrieved value from the database that can be parsed into an array; - an array of values if the value is already parsed.
| public array|string getRawValue ( ) |
public function getRawValue(): array|string
{
return $this->value;
}
Defined in: Yiisoft\Db\Schema\Data\LazyArrayTrait::getValue()
Returns parsed and typecasted value.
| public array getValue ( ) |
public function getValue(): array
{
$this->prepareValue();
return $this->value;
}
| public array jsonSerialize ( ) |
public function jsonSerialize(): array
{
return $this->getValue();
}
| public boolean offsetExists ( integer|string $offset ) | ||
| $offset | integer|string |
The offset to check. |
public function offsetExists(mixed $offset): bool
{
$this->prepareValue();
return isset($this->value[$offset]);
}
| public mixed offsetGet ( integer|string $offset ) | ||
| $offset | integer|string |
The offset to retrieve. |
public function offsetGet(mixed $offset): mixed
{
$this->prepareValue();
return $this->value[$offset];
}
| public void offsetSet ( integer|string $offset, mixed $value ) | ||
| $offset | integer|string |
The offset to assign the value to. |
| $value | mixed | |
public function offsetSet(mixed $offset, mixed $value): void
{
$this->prepareValue();
$this->value[$offset] = $value;
}
| public void offsetUnset ( integer|string $offset ) | ||
| $offset | integer|string |
The offset to unset. |
public function offsetUnset(mixed $offset): void
{
$this->prepareValue();
unset($this->value[$offset]);
}
Prepares the value to be used as an array or throws an exception if it's impossible.
| protected void prepareValue ( ) |
protected function prepareValue(): void
{
if (is_string($this->value)) {
$value = json_decode($this->value, true, 512, JSON_THROW_ON_ERROR);
if (!is_array($value)) {
throw new InvalidArgumentException('JSON value must be a valid string array representation.');
}
$this->value = $value;
}
}
Signup or Login in order to comment.