0 follower

Trait Yiisoft\ActiveRecord\Trait\ArrayAccessTrait

Method Details

Hide inherited methods

get() public method

public get( string $name ): mixed
$name string
return mixed
hasProperty() public method

public hasProperty( string $name ): boolean
$name string
return boolean
isRelationPopulated() public method

public isRelationPopulated( string $name ): boolean
$name string
return boolean
offsetExists() public method

Returns whether there is an element at the specified offset.

This method is required by the SPL interface \Yiisoft\ActiveRecord\Trait\ArrayAccess.

It is implicitly called when you use something like isset($model[$offset]).

public offsetExists( string $offset ): boolean
$offset string

The offset to check on.

return boolean

Whether an offset exists.

                public function offsetExists(mixed $offset): bool
{
    if ($this->hasProperty($offset)) {
        return $this->get($offset) !== null;
    }
    if (property_exists($this, $offset)) {
        return isset($this->$offset);
    }
    if ($this->isRelationPopulated($offset)) {
        return $this->relation($offset) !== null;
    }
    return false;
}

            
offsetGet() public method

public offsetGet( string $offset ): mixed
$offset string

The offset to retrieve element.

                public function offsetGet(mixed $offset): mixed
{
    if ($this->hasProperty($offset)) {
        return $this->get($offset);
    }
    if (property_exists($this, $offset)) {
        return $this->$offset ?? null;
    }
    return $this->relation($offset);
}

            
offsetSet() public method

Sets the element at the specified offset.

This method is required by the SPL interface \Yiisoft\ActiveRecord\Trait\ArrayAccess.

It is implicitly called when you use something like $model[$offset] = $item;.

public offsetSet( string $offset, mixed $value ): void
$offset string

The offset to set element.

$value mixed

                public function offsetSet(mixed $offset, mixed $value): void
{
    if ($this->hasProperty($offset)) {
        $this->set($offset, $value);
        return;
    }
    if (property_exists($this, $offset)) {
        $this->$offset = $value;
        return;
    }
    if ($value instanceof ActiveRecordInterface || is_array($value) || $value === null) {
        $this->populateRelation($offset, $value);
        return;
    }
    throw new InvalidArgumentException('Setting unknown property: ' . static::class . '::' . $offset);
}

            
offsetUnset() public method

Sets the element value at the specified offset to null.

This method is required by the SPL interface \Yiisoft\ActiveRecord\Trait\ArrayAccess.

It is implicitly called when you use something like unset($model[$offset]).

public offsetUnset( string $offset ): void
$offset string

The offset to unset element.

                public function offsetUnset(mixed $offset): void
{
    if ($this->hasProperty($offset) || property_exists($this, $offset)) {
        $this->set($offset, null);
        unset($this->$offset);
        return;
    }
    $this->resetRelation($offset);
}

            
populateRelation() public method

public populateRelation( string $name, Yiisoft\ActiveRecord\ActiveRecordInterface|array|null $record ): void
$name string
$record Yiisoft\ActiveRecord\ActiveRecordInterface|array|null
return void
resetRelation() public method

public resetRelation( string $name ): void
$name string
return void
set() public method

public set( string $name, mixed $value ): void
$name string
$value mixed
return void