0 follower

Trait Yiisoft\ActiveRecord\Trait\EventsTrait

Method Details

Hide inherited methods

delete() public method

public integer delete ( )

                public function delete(): int
{
    $eventDispatcher = EventDispatcherProvider::get(static::class);
    $eventDispatcher->dispatch($event = new BeforeDelete($this));
    if ($event->isDefaultPrevented()) {
        return $event->getReturnValue() ?? 0;
    }
    $result = parent::delete();
    $eventDispatcher->dispatch(new AfterDelete($this, $result));
    return $result;
}

            
insert() public method

public void insert ( array|null $properties null )
$properties array|null

                public function insert(?array $properties = null): void
{
    $eventDispatcher = EventDispatcherProvider::get(static::class);
    $eventDispatcher->dispatch($event = new BeforeInsert($this, $properties));
    if ($event->isDefaultPrevented()) {
        return;
    }
    parent::insert($properties);
    $eventDispatcher->dispatch(new AfterInsert($this));
}

            
populateRecord() public method

public Yiisoft\ActiveRecord\Trait\EventsTrait populateRecord ( array|object $data )
$data array|object

                public function populateRecord(array|object $data): static
{
    $eventDispatcher = EventDispatcherProvider::get(static::class);
    $eventDispatcher->dispatch($event = new BeforePopulate($this, $data));
    if ($event->isDefaultPrevented()) {
        return $this;
    }
    parent::populateRecord($data);
    $eventDispatcher->dispatch(new AfterPopulate($this, $data));
    return $this;
}

            
query() public static method

public static Yiisoft\ActiveRecord\ActiveQueryInterface query ( Yiisoft\ActiveRecord\ActiveRecordInterface|Closure|string|null $modelClass null )
$modelClass Yiisoft\ActiveRecord\ActiveRecordInterface|Closure|string|null

                public static function query(ActiveRecordInterface|Closure|string|null $modelClass = null): ActiveQueryInterface
{
    $model = match (true) {
        $modelClass === null => new static(),
        is_string($modelClass) => new $modelClass(),
        $modelClass instanceof ActiveRecordInterface => $modelClass,
        default => ($modelClass)(),
    };
    $eventDispatcher = EventDispatcherProvider::get($model::class);
    $eventDispatcher->dispatch($event = new BeforeCreateQuery($model));
    if ($event->isDefaultPrevented()) {
        return $event->getReturnValue();
    }
    $query = parent::query($model);
    $eventDispatcher->dispatch(new AfterCreateQuery($model, $query));
    return $query;
}

            
save() public method

public void save ( array|null $properties null )
$properties array|null

                public function save(?array $properties = null): void
{
    $eventDispatcher = EventDispatcherProvider::get(static::class);
    $eventDispatcher->dispatch($event = new BeforeSave($this, $properties));
    if ($event->isDefaultPrevented()) {
        return;
    }
    parent::save($properties);
    $eventDispatcher->dispatch(new AfterSave($this));
}

            
update() public method

public integer update ( array|null $properties null )
$properties array|null

                public function update(?array $properties = null): int
{
    $eventDispatcher = EventDispatcherProvider::get(static::class);
    $eventDispatcher->dispatch($event = new BeforeUpdate($this, $properties));
    if ($event->isDefaultPrevented()) {
        return $event->getReturnValue() ?? 0;
    }
    $result = parent::update($properties);
    $eventDispatcher->dispatch(new AfterUpdate($this, $result));
    return $result;
}

            
upsert() public method

public void upsert ( array|null $insertProperties null, array|boolean $updateProperties true )
$insertProperties array|null
$updateProperties array|boolean

                public function upsert(?array $insertProperties = null, array|bool $updateProperties = true): void
{
    $eventDispatcher = EventDispatcherProvider::get(static::class);
    $eventDispatcher->dispatch($event = new BeforeUpsert($this, $insertProperties, $updateProperties));
    if ($event->isDefaultPrevented()) {
        return;
    }
    parent::upsert($insertProperties, $updateProperties);
    $eventDispatcher->dispatch(new AfterUpsert($this));
}