Oihana PHP System

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\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
since
1.0.0

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, mixed $newValue[, bool &$modified = false ]) : mixed
Parameters
$value : mixed

The original value

$newValue : mixed

The value to replace with

$modified : bool = false

Will be set to true if the value was replaced

Return values
mixed

The altered value


        
On this page

Search results