AlterUrlPropertyTrait
Provides a method to generate a URL string from a document property.
This trait depends on KeyValueTrait to safely read values from arrays or objects.
Example usage:
use oihana\traits\alters\AlterUrlPropertyTrait;
$document = ['id' => 42];
$url = $this->alterUrlProperty($document, ['/base/path']);
// returns '/base/path/42'
Tags
Table of Contents
Methods
- alterUrlProperty() : string
- Generates a document URL using a property as the final path segment.
Methods
alterUrlProperty()
Generates a document URL using a property as the final path segment.
public
alterUrlProperty(array<string|int, mixed>|object $document[, array<string|int, mixed> $options = [] ][, bool|null $isArray = null ][, bool &$modified = false ][, string $propertyName = 'id' ]) : string
Parameters
- $document : array<string|int, mixed>|object
-
Document to read the property from.
- $options : array<string|int, mixed> = []
-
Optional array of parameters :
- [0] string Base path prefix
- [1] string Property name to use (default 'id')
- $isArray : bool|null = null
-
Optionally force document type (true=array, false=object)
- $modified : bool = false
-
Reference variable updated if URL was altered
- $propertyName : string = 'id'
-
Default property name if not specified in options (default 'id')
Return values
string —The generated URL