0 follower

Trait Yiisoft\ActiveRecord\Trait\ArrayAccessTrait

Method Details

Hide inherited methods

get() public method

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

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

public boolean isRelationPopulated ( string $name )
$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 {@see \Yiisoft\ActiveRecord\Trait\ArrayAccess}.

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

public boolean offsetExists ( string $offset )
$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 mixed offsetGet ( string $offset )
$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 {@see \Yiisoft\ActiveRecord\Trait\ArrayAccess}.

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

public void offsetSet ( string $offset, mixed $value )
$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 {@see \Yiisoft\ActiveRecord\Trait\ArrayAccess}.

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

public void offsetUnset ( string $offset )
$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 void populateRelation ( string $name, Yiisoft\ActiveRecord\ActiveRecordInterface|array|null $record )
$name string
$record Yiisoft\ActiveRecord\ActiveRecordInterface|array|null
return void
resetRelation() public method

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

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