Oihana PHP

Alter uses ConstantsTrait

Enumeration of all transformation or filter operations that can be applied to an object property or an array key.

Each constant represents a type of alteration that can be performed when normalizing or processing data within models or collections.

Examples of usage include:

  • Converting a value to a specific type (INT, FLOAT)
  • Cleaning or normalizing arrays or strings (CLEAN, NORMALIZE)
  • Parsing or serializing JSON (JSON_PARSE, JSON_STRINGIFY)
  • Applying custom callbacks (CALL) or map (MAP)
  • Extracting values via getters (GET)
  • Handling URLs or array transformations (URL, ARRAY)

Always reference these constants instead of the raw string so that an alter pipeline keeps working if a value ever changes (no magic strings).

Example:

use oihana\models\enums\Alter;

// An alter definition mapping properties to the operation to apply.
$alters =
[
    'price'    => [ Alter::FLOAT ] ,
    'quantity' => [ Alter::INT ] ,
    'tags'     => [ Alter::JSON_PARSE ] ,
    'avatar'   => [ Alter::URL ] ,
];
Tags
author

Marc Alcaraz

since
1.0.0
see
AlterDocumentTrait

For usage of alter rules in models.

Table of Contents

Constants

ARRAY  : string = 'array'
Wraps the value into an array (or normalizes it to an array form).
CALL  : string = 'call'
Applies a user-supplied callback to the value.
CLEAN  : string = 'clean'
Cleans the value (e.g. trims/strips empty entries).
FLOAT  : string = 'float'
Casts the value to a floating-point number.
GET  : string = 'get'
Extracts a value through a getter.
HYDRATE  : string = 'hydrate'
Hydrates the value into a typed object/model instance.
INT  : string = 'int'
Casts the value to an integer.
JSON_PARSE  : string = 'jsonParse'
Decodes a JSON string into its PHP value.
JSON_STRINGIFY  : string = 'jsonStringify'
Encodes the value into a JSON string.
LIST  : string = 'list'
Treats the value as a list (collection of items).
LISTIFY  : string = 'listify'
Coerces the value into a list, wrapping a single item when needed.
MAP  : string = 'map'
Maps each element of the value through a transformation.
NORMALIZE  : string = 'normalize'
Normalizes the value (e.g. canonical form, whitespace/casing).
NOT  : string = 'not'
Negates the value (logical/boolean inversion).
URL  : string = 'url'
Resolves the value into a document/resource URL.
VALUE  : string = 'value'
Replaces the value with a fixed/computed value.

Constants

ARRAY

Wraps the value into an array (or normalizes it to an array form).

public string ARRAY = 'array'

CALL

Applies a user-supplied callback to the value.

public string CALL = 'call'

CLEAN

Cleans the value (e.g. trims/strips empty entries).

public string CLEAN = 'clean'

FLOAT

Casts the value to a floating-point number.

public string FLOAT = 'float'

GET

Extracts a value through a getter.

public string GET = 'get'

HYDRATE

Hydrates the value into a typed object/model instance.

public string HYDRATE = 'hydrate'

INT

Casts the value to an integer.

public string INT = 'int'

JSON_PARSE

Decodes a JSON string into its PHP value.

public string JSON_PARSE = 'jsonParse'

JSON_STRINGIFY

Encodes the value into a JSON string.

public string JSON_STRINGIFY = 'jsonStringify'

LIST

Treats the value as a list (collection of items).

public string LIST = 'list'

LISTIFY

Coerces the value into a list, wrapping a single item when needed.

public string LISTIFY = 'listify'

MAP

Maps each element of the value through a transformation.

public string MAP = 'map'

NORMALIZE

Normalizes the value (e.g. canonical form, whitespace/casing).

public string NORMALIZE = 'normalize'

NOT

Negates the value (logical/boolean inversion).

public string NOT = 'not'

URL

Resolves the value into a document/resource URL.

public string URL = 'url'

VALUE

Replaces the value with a fixed/computed value.

public string VALUE = 'value'
On this page

Search results