Oihana PHP

AlterKeyTrait

Provides support for defining and initializing the default "alter key".

The alter key is used by alteration traits (e.g., AlterUrlPropertyTrait) to resolve which property or contextual key should be used when applying transformations in a model's alteration pipeline.

By default, the alter key is initialized to Schema::ID, but it can be overridden at construction time or during initialization using the ModelParam::ALTER_KEY parameter.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Properties

$alterKey  : string
The default property key used when an alteration needs to read a value from the document.

Methods

initializeAlterKey()  : static
Initializes the {@see $alterKey} property from an initialization array.

Properties

$alterKey

The default property key used when an alteration needs to read a value from the document.

public string $alterKey = \org\schema\constants\Schema::ID

Consumed for instance by AlterUrlPropertyTrait to pick which property provides the final URL segment when none is given explicitly. Defaults to Schema::ID.

Tags
see
AlterUrlPropertyTrait

Methods

initializeAlterKey()

Initializes the {@see $alterKey} property from an initialization array.

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

Reads ModelParam::ALTER_KEY from $init; when absent, the key falls back to Schema::ID. Returns the current instance for fluent chaining.

Parameters
$init : array<string|int, mixed> = []

Initialization options; the ModelParam::ALTER_KEY entry, when present, overrides the default alter key.

Tags
example
use oihana\models\enums\ModelParam;

$this->initializeAlterKey( [ ModelParam::ALTER_KEY => 'slug' ] );
// $this->alterKey === 'slug'

$this->initializeAlterKey();
// $this->alterKey === Schema::ID  (default)
Return values
static

The current instance, for method chaining.

On this page

Search results