AlterNormalizePropertyTrait
Provides a method to normalize a property value according to configurable cleaning flags.
This trait is typically used in alteration pipelines to ensure that values are cleaned, trimmed, and standardized before being stored or further processed.
The normalization behavior is controlled via CleanFlag constants:
- By default,
CleanFlag::DEFAULT | CleanFlag::RETURN_NULLis applied. - Custom flags can be provided as the first element of the
$definitionarray.
Normalization handles:
- Arrays recursively, removing empty values, nulls, or falsy values according to flags.
- Strings by trimming and optionally converting empty strings to null.
- Scalars are generally returned as-is unless
CleanFlag::FALSYis used. - Objects are returned as-is unless empty
stdClassandCleanFlag::RETURN_NULLis set.
The $modified flag is set to true if the resulting value differs from the original.
Tags
Table of Contents
Methods
- alterNormalizeProperty() : mixed
- Normalize a document property using configurable flags.
Methods
alterNormalizeProperty()
Normalize a document property using configurable flags.
public
alterNormalizeProperty(mixed $value[, array<string|int, mixed> $definition = [] ][, bool &$modified = false ]) : mixed
The normalization can be customized via the $definition array:
- If empty or no flags provided, uses CleanFlag::DEFAULT | CleanFlag::RETURN_NULL
- If a flags value is provided at index 0, uses that instead
Parameters
- $value : mixed
-
The value to normalize
- $definition : array<string|int, mixed> = []
-
Optional flags array: [CleanFlag value, ...other params]
- $modified : bool = false
-
Reference flag indicating if the value was modified
Tags
Return values
mixed —The normalized value, or null if cleaned away