AlterValueTrait
Provides a method to replace a value with a fixed new one if different.
This trait is part of the alteration system and is intended to be used
in combination with AlterDocumentTrait.
It encapsulates the logic for the Alter::VALUE transformation type.
Example usage:
use oihana\models\enums\Alter;
use oihana\traits\AlterDocumentTrait;
use oihana\traits\alters\AlterValueTrait;
class Example
{
use AlterDocumentTrait, AlterValueTrait;
public function __construct()
{
$this->alters =
[
'status' => [ Alter::VALUE , 'published' ] ,
];
}
}
$doc = [ 'status' => 'draft' ];
$processor = new Example();
$result = $processor->alter($doc);
// Result:
// [
// 'status' => 'published'
// ]
Tags
Table of Contents
Methods
- alterValue() : mixed
- Replace a value with a new one if different, otherwise keep the original.
Methods
alterValue()
Replace a value with a new one if different, otherwise keep the original.
public
alterValue(mixed $value[, array<string|int, mixed> $definition = [] ][, bool &$modified = false ]) : mixed
Parameters
- $value : mixed
-
The original value
- $definition : array<string|int, mixed> = []
-
The definition reference to extract the new value to apply.
- $modified : bool = false
-
Will be set to true if the value was replaced
Return values
mixed —The altered value