class IdentityRoutePart extends DynamicRoutePart (View source)

Identity Route Part This route part can be used to create and resolve ObjectPathMappings.

This handler is used by default, if an objectType is specified for a route part in the routing configuration:

name: 'Some route for xyz entities' uriPattern: '{xyz}' routeParts: 'xyz': objectType: 'Some\Package\Domain\Model\Xyz'

Properties

protected string $name

Name of the Route Part

from  AbstractRoutePart
protected mixed $value

Value of the Route Part after decoding.

from  AbstractRoutePart
protected mixed $defaultValue

Default value of the Route Part.

from  AbstractRoutePart
protected bool $isOptional

Specifies whether this Route Part is optional. Which means it's put in parentheses in the routes URI pattern.

from  AbstractRoutePart
protected bool $lowerCase

Specifies whether this Route Part should be converted to lower case when resolved.

from  AbstractRoutePart
protected array $options

Contains options for this Route Part.

from  AbstractRoutePart
protected PersistenceManagerInterface $persistenceManager
protected string $splitString

The split string represents the end of a Dynamic Route Part.

from  DynamicRoutePart
protected RouteParameters $parameters

The Routing RouteParameters passed to matchWithParameters() These allow sub classes to adjust the matching behavior accordingly

from  DynamicRoutePart
protected ReflectionService $reflectionService
protected ObjectPathMappingRepository $objectPathMappingRepository
protected class-string $objectType

The object type (class name) of the entity this route part belongs to

protected string $uriPattern

pattern for the URI representation (for example "{date:Y}/{date:m}/{date.d}/{title}")

Methods

void
setName(string $partName)

Sets name of the Route Part.

string
getName()

Returns name of the Route Part.

bool
hasValue()

Returns true if a value is set for this Route Part, otherwise false.

mixed
getValue()

Returns value of the Route Part. Before match() is called this returns NULL.

bool
hasDefaultValue()

Returns true if a default value is set for this Route Part, otherwise false.

void
setDefaultValue(mixed $defaultValue)

Sets default value of the Route Part.

mixed
getDefaultValue()

Gets default value of the Route Part.

void
setOptional(bool $isOptional)

Specifies whether this Route part is optional.

bool
isOptional()

Getter for $this->isOptional.

void
setLowerCase(bool $lowerCase)

Specifies whether this Route part should be converted to lower case when resolved.

bool
isLowerCase()

Getter for $this->lowerCase.

void
setOptions(array $options)

Defines options for this Route Part.

array
getOptions()

No description

void
setSplitString(string $splitString)

Sets split string of the Route Part.

match(string $routePath)

Checks whether this Dynamic Route Part corresponds to the given $routePath.

bool
matchWithParameters(string $routePath, RouteParameters $parameters)

Checks whether this Dynamic Route Part corresponds to the given $routePath.

string
findValueToMatch(string|null $routePath)

Returns the first part of $routePath that should be evaluated in matchValue().

matchValue(string $value)

Checks, whether given value can be matched.

void
removeMatchingPortionFromRequestPath(string $routePath, string $valueToMatch)

Removes matching part from $routePath.

resolve(array $routeValues)

Checks whether $routeValues contains elements which correspond to this Dynamic Route Part.

resolveWithParameters(array $routeValues, RouteParameters $parameters)

Checks whether $routeValues contains elements which correspond to this Dynamic Route Part.

string|array|null
findValueToResolve(array $routeValues)

Returns the route value of the current route part.

resolveValue(mixed $value)

Resolves the given entity and sets the value to a URI representation (path segment) that matches $this->uriPattern and is unique for the given object.

void
setObjectType(class-string $objectType)

No description

class-string
getObjectType()

No description

void
setUriPattern(string $uriPattern)

No description

string
getUriPattern()

If $this->uriPattern is specified, this will be returned, otherwise identity properties of $this->objectType are returned in the format {property1}/{property2}/{property3}.

string|null
getObjectIdentifierFromPathSegment(string $pathSegment)

Retrieves the object identifier from the given $pathSegment.

string|int
getPathSegmentByIdentifier(string $identifier)

Generates a unique string for the given identifier according to $this->uriPattern.

string
createPathSegmentForObject(mixed $object)

Creates a URI representation (path segment) for the given object matching $this->uriPattern.

void
storeObjectPathMapping(string $pathSegment, string|int $identifier)

Creates a new ObjectPathMapping and stores it in the repository

string
rewriteForUri(string $value)

Transforms the given string into a URI compatible format without special characters.

Details

void setName(string $partName)

Sets name of the Route Part.

Parameters

string $partName

Return Value

void

string getName()

Returns name of the Route Part.

Return Value

string

bool hasValue()

Returns true if a value is set for this Route Part, otherwise false.

Return Value

bool

mixed getValue()

Returns value of the Route Part. Before match() is called this returns NULL.

Return Value

mixed

bool hasDefaultValue()

Returns true if a default value is set for this Route Part, otherwise false.

Return Value

bool

void setDefaultValue(mixed $defaultValue)

Sets default value of the Route Part.

Parameters

mixed $defaultValue

Return Value

void

mixed getDefaultValue()

Gets default value of the Route Part.

Return Value

mixed $defaultValue

void setOptional(bool $isOptional)

Specifies whether this Route part is optional.

Parameters

bool $isOptional

true: this Route part is optional. false: this Route part is required.

Return Value

void

bool isOptional()

Getter for $this->isOptional.

Return Value

bool

true if this Route part is optional, otherwise false.

See also

setOptional()

void setLowerCase(bool $lowerCase)

Specifies whether this Route part should be converted to lower case when resolved.

Parameters

bool $lowerCase

true: this Route part is converted to lower case. false: this Route part is not altered.

Return Value

void

bool isLowerCase()

Getter for $this->lowerCase.

Return Value

bool

true if this Route part will be converted to lower case, otherwise false.

See also

setLowerCase()

void setOptions(array $options)

Defines options for this Route Part.

Options can be used to enrich a route part with parameters or settings like case sensivity.

Parameters

array $options

Return Value

void

array getOptions()

No description

Return Value

array

options of this Route Part.

void setSplitString(string $splitString)

Sets split string of the Route Part.

Parameters

string $splitString

Return Value

void

final bool|MatchResult match(string $routePath)

Checks whether this Dynamic Route Part corresponds to the given $routePath.

Parameters

string $routePath

The request path to be matched - without query parameters, host and fragment.

Return Value

bool|MatchResult

true or an instance of MatchResult if Route Part matched $routePath, otherwise false.

See also

matchWithParameters()

final bool matchWithParameters(string $routePath, RouteParameters $parameters)

Checks whether this Dynamic Route Part corresponds to the given $routePath.

On successful match this method sets $this->value to the corresponding uriPart and shortens $routePath respectively.

Parameters

string $routePath

The request path to be matched - without query parameters, host and fragment.

RouteParameters $parameters

The Routing RouteParameters that can be registered via HTTP middleware

Return Value

bool

true if Route Part matched $routePath, otherwise false.

protected string findValueToMatch(string|null $routePath)

Returns the first part of $routePath that should be evaluated in matchValue().

If no split string is set (route part is the last in the routes uriPattern), the complete $routePart is returned. Otherwise the part is returned that matches the specified uriPattern of this route part.

Parameters

string|null $routePath

The request path to be matched

Return Value

string

value to match, or an empty string if $routePath is empty or split string was not found

protected bool|MatchResult matchValue(string $value)

Checks, whether given value can be matched.

If the value is empty, false is returned. Otherwise the ObjectPathMappingRepository is asked for a matching ObjectPathMapping. If that is found the identifier is stored in $this->value, otherwise this route part does not match.

Parameters

string $value

value to match

Return Value

bool|MatchResult

An instance of MatchResult if value could be matched successfully, otherwise false.

protected void removeMatchingPortionFromRequestPath(string $routePath, string $valueToMatch)

Removes matching part from $routePath.

This method can be overridden by custom RoutePartHandlers to implement custom matching mechanisms.

Parameters

string $routePath

The request path to be matched

string $valueToMatch

The matching value

Return Value

void

final bool|ResolveResult resolve(array $routeValues)

Checks whether $routeValues contains elements which correspond to this Dynamic Route Part.

If a corresponding element is found in $routeValues, this element is removed from the array.

Parameters

array $routeValues

An array with key/value pairs to be resolved by Dynamic Route Parts.

Return Value

bool|ResolveResult

true or an instance of ResolveResult if Route Part can resolve one or more $routeValues elements, otherwise false.

See also

resolveWithParameters()

final bool|ResolveResult resolveWithParameters(array $routeValues, RouteParameters $parameters)

Checks whether $routeValues contains elements which correspond to this Dynamic Route Part.

If a corresponding element is found in $routeValues, this element is removed from the array.

Parameters

array $routeValues

An array with key/value pairs to be resolved by Dynamic Route Parts.

RouteParameters $parameters

The Routing RouteParameters that can be registered via HTTP middleware

Return Value

bool|ResolveResult

true or an instance of ResolveResult if Route Part can resolve one or more $routeValues elements, otherwise false.

protected string|array|null findValueToResolve(array $routeValues)

Returns the route value of the current route part.

This method can be overridden by custom RoutePartHandlers to implement custom resolving mechanisms.

Parameters

array $routeValues

An array with key/value pairs to be resolved by Dynamic Route Parts.

Return Value

string|array|null

value to resolve.

protected bool|ResolveResult resolveValue(mixed $value)

Resolves the given entity and sets the value to a URI representation (path segment) that matches $this->uriPattern and is unique for the given object.

Parameters

mixed $value

value to resolve

Return Value

bool|ResolveResult

An instance of ResolveResult if value could be resolved successfully, otherwise false.

void setObjectType(class-string $objectType)

No description

Parameters

class-string $objectType

Return Value

void

class-string getObjectType()

No description

Return Value

class-string

void setUriPattern(string $uriPattern)

No description

Parameters

string $uriPattern

Return Value

void

string getUriPattern()

If $this->uriPattern is specified, this will be returned, otherwise identity properties of $this->objectType are returned in the format {property1}/{property2}/{property3}.

If $this->objectType does not contain identity properties, an empty string is returned.

Return Value

string

protected string|null getObjectIdentifierFromPathSegment(string $pathSegment)

Retrieves the object identifier from the given $pathSegment.

If no UriPattern is set, the $pathSegment is expected to be the (URL-encoded) identifier otherwise a matching ObjectPathMapping fetched from persistence If no matching ObjectPathMapping was found or the given $pathSegment is no valid identifier NULL is returned.

Parameters

string $pathSegment

the query path segment to convert

Return Value

string|null

the technical identifier of the object or NULL if it couldn't be found

protected string|int getPathSegmentByIdentifier(string $identifier)

Generates a unique string for the given identifier according to $this->uriPattern.

If no UriPattern is set, the path segment is equal to the (URL-encoded) $identifier - otherwise a matching ObjectPathMapping is fetched from persistence. If no ObjectPathMapping exists for the given identifier, a new ObjectPathMapping is created.

Parameters

string $identifier

the technical identifier of the object

Return Value

string|int

the resolved path segment(s)

Exceptions

InfiniteLoopException

protected string createPathSegmentForObject(mixed $object)

Creates a URI representation (path segment) for the given object matching $this->uriPattern.

Parameters

mixed $object

object of type $this->objectType

Return Value

string

URI representation (path segment) of the given object

Exceptions

InvalidUriPatternException

protected void storeObjectPathMapping(string $pathSegment, string|int $identifier)

Creates a new ObjectPathMapping and stores it in the repository

Parameters

string $pathSegment
string|int $identifier

Return Value

void

protected string rewriteForUri(string $value)

Transforms the given string into a URI compatible format without special characters.

In the long term this should be done with proper transliteration

use transliteration of the I18n sub package

Parameters

string $value

Return Value

string