Oihana PHP

ReplaceModel

Contract for models able to replace an existing document.

A ReplaceModel exposes a single ReplaceModel::replace() operation that overwrites a stored document with a brand new payload. Unlike UpdateModel::update(), which merges a partial patch, replace() swaps the whole document — any field absent from the new payload is dropped.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

replace()  : mixed
Replaces an existing document in the model.

Methods

replace()

Replaces an existing document in the model.

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

Operation options carrying the replacement, typically the target key/id, the full document payload, optional binds and a return clause.

Tags
example
use oihana\models\interfaces\ReplaceModel;

class UserModel implements ReplaceModel
{
    public function replace( array $init = [] ) : mixed
    {
        return $this->store->set( $init[ 'key' ], $init[ 'document' ] ?? [] ) ;
    }
}

$model = new UserModel() ;
$user  = $model->replace( [ 'key' => 'users/42', 'document' => [ 'name' => 'Bob' ] ] ) ;
Return values
mixed

The replaced document (or its result), depending on the implementation.

On this page

Search results