Oihana PHP

DeleteModel

Contract for models able to delete a document.

A DeleteModel exposes a single DeleteModel::delete() operation that removes one (or, depending on the options, several) document(s) from the underlying storage. To wipe an entire collection at once, see DeleteAllModel or TruncateModel.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

delete()  : null|array<string|int, mixed>|object
Deletes a document, or a set of documents, in the model.

Methods

delete()

Deletes a document, or a set of documents, in the model.

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

Operation options identifying what to delete, typically a key/id, a set of conditions with their binds and an optional return clause.

Tags
example
use oihana\models\interfaces\DeleteModel;

class UserModel implements DeleteModel
{
    public function delete( array $init = [] ) : null|array|object
    {
        return $this->store->remove( $init[ 'key' ] ?? null ) ;
    }
}

$model   = new UserModel() ;
$removed = $model->delete( [ 'key' => 'users/42' ] ) ;
Return values
null|array<string|int, mixed>|object

The deleted document(s) when the implementation returns them, otherwise null.

On this page

Search results