Oihana PHP

InsertModel

Contract for models able to insert a new document.

An InsertModel exposes a single InsertModel::insert() operation that creates a new document in the underlying storage. Implementations usually emit beforeInsert/afterInsert signals around the operation so observers can inspect or react to the created document.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

insert()  : mixed
Inserts a new document into the model.

Methods

insert()

Inserts a new document into the model.

public insert([array<string|int, mixed> $init = [] ]) : mixed
Parameters
$init : array<string|int, mixed> = []

Operation options carrying the data to insert, typically the document payload, optional binds and a return clause describing what the call should yield.

Tags
example
use oihana\models\interfaces\InsertModel;

class UserModel implements InsertModel
{
    public function insert( array $init = [] ) : mixed
    {
        return $this->store->add( $init[ 'document' ] ?? [] ) ;
    }
}

$model = new UserModel() ;
$user  = $model->insert( [ 'document' => [ 'name' => 'Alice' ] ] ) ;
Return values
mixed

The inserted document (or its identifier/result), depending on the implementation.

On this page

Search results