\Charcoal\ObjectRoutableTrait

Full implementation, as Trait, of the {@see \Charcoal\Object\RoutableInterface}.

This implementation uses a secondary model, \Charcoal\Object\ObjectRoute, to collect all routes of routable models under a single source.

Summary

Methods
Properties
Constants
setSlugPattern()
slugPattern()
slugPrefix()
slugSuffix()
isSlugEditable()
setSlug()
slug()
generateSlug()
url()
slugify()
createRouteObject()
objectRouteClass()
modelFactory()
templateIdent()
No public properties found
No constants found
generateRoutePattern()
parseRouteToken()
filterRouteToken()
generateObjectRoute()
getLatestObjectRoute()
finalizeSlug()
deleteObjectRoutes()
setObjectRouteClass()
$slug
N/A
No private methods found
$isSlugEditable
$slugPattern
$slugPrefix
$slugSuffix
$latestObjectRoute
$objectRouteClass
N/A

Properties

$slug

$slug : \Charcoal\Translation\TranslationString|string|null

The object's route.

Type

\Charcoal\Translation\TranslationString|string|null

$isSlugEditable

$isSlugEditable : boolean|null

Whether the slug is editable.

If FALSE, the slug is always auto-generated from its pattern. If TRUE, the slug is auto-generated only if the slug is empty.

Type

boolean|null

$slugPattern

$slugPattern : \Charcoal\Translation\TranslationString|string|null

The object's route pattern.

Type

\Charcoal\Translation\TranslationString|string|null

$slugPrefix

$slugPrefix : \Charcoal\Translation\TranslationString|string|null

A prefix for the object's route.

Type

\Charcoal\Translation\TranslationString|string|null

$slugSuffix

$slugSuffix : \Charcoal\Translation\TranslationString|string|null

A suffix for the object's route.

Type

\Charcoal\Translation\TranslationString|string|null

$objectRouteClass

$objectRouteClass : string

The class name of the object route model.

Must be a fully-qualified PHP namespace and an implementation of \Charcoal\Object\ObjectRouteInterface. Used by the model factory.

Type

string

Methods

setSlugPattern()

setSlugPattern(mixed  $pattern) : \Charcoal\Object\RoutableInterface

Set the object's URL slug pattern.

Parameters

mixed $pattern

The slug pattern.

Returns

\Charcoal\Object\RoutableInterface

Chainable

slugPattern()

slugPattern() : \Charcoal\Translation\TranslationString|null

Retrieve the object's URL slug pattern.

Throws

\InvalidArgumentException

If a slug pattern is not defined.

Returns

\Charcoal\Translation\TranslationString|null

slugPrefix()

slugPrefix() : \Charcoal\Translation\TranslationString|null

Retrieve route prefix for the object's URL slug pattern.

Returns

\Charcoal\Translation\TranslationString|null

slugSuffix()

slugSuffix() : \Charcoal\Translation\TranslationString|null

Retrieve route suffix for the object's URL slug pattern.

Returns

\Charcoal\Translation\TranslationString|null

isSlugEditable()

isSlugEditable() : boolean

Determine if the slug is editable.

Returns

boolean

setSlug()

setSlug(mixed  $slug) : \Charcoal\Object\RoutableInterface

Set the object's URL slug.

Parameters

mixed $slug

The slug.

Returns

\Charcoal\Object\RoutableInterface

Chainable

slug()

slug() : \Charcoal\Translation\TranslationString|null

Retrieve the object's URL slug.

Returns

\Charcoal\Translation\TranslationString|null

generateSlug()

generateSlug() : \Charcoal\Translation\TranslationString

Generate a URL slug from the object's URL slug pattern.

Throws

\UnexpectedValueException

If the slug is empty.

Returns

\Charcoal\Translation\TranslationString

url()

url(string|null  $lang = null) : \Charcoal\Translation\TranslationString|string

Retrieve the object's URI.

Parameters

string|null $lang

If object is multilingual, return the object route for the specified locale.

Returns

\Charcoal\Translation\TranslationString|string

slugify()

slugify(string  $str) : string

Convert a string into a slug.

Parameters

string $str

The string to slugify.

Returns

string —

The slugified string.

objectRouteClass()

objectRouteClass() : string

Retrieve the class name of the object route model.

Returns

string

modelFactory()

modelFactory() : \Charcoal\Factory\FactoryInterface

Retrieve the object model factory.

Returns

\Charcoal\Factory\FactoryInterface

templateIdent()

templateIdent() : mixed

Retrieve the routable object's template identifier.

Returns

mixed

generateRoutePattern()

generateRoutePattern(string  $pattern) : string

Generate a route from the given pattern.

Parameters

string $pattern

The slug pattern.

Returns

string —

Returns the generated route.

parseRouteToken()

parseRouteToken(string|array  $token) : string

Parse the given slug (URI token) for the current object.

Parameters

string|array $token

The token to parse relative to the model entry.

Throws

\InvalidArgumentException

If a route token is not a string.

Returns

string

filterRouteToken()

filterRouteToken(mixed  $value, string  $token = null) : string

Filter the given value for a URI.

Parameters

mixed $value

A value to filter.

string $token

The parsed token.

Returns

string —

The filtered $value.

generateObjectRoute()

generateObjectRoute(mixed  $slug = null) : void

Route generation.

Saves all routes to \Charcoal\Object\ObjectRoute.

Parameters

mixed $slug

Slug by langs.

getLatestObjectRoute()

getLatestObjectRoute(string|null  $lang = null) : \Charcoal\Object\ObjectRouteInterface

Retrieve the latest object route.

Parameters

string|null $lang

If object is multilingual, return the object route for the specified locale.

Throws

\InvalidArgumentException

If the given language is invalid.

Returns

\Charcoal\Object\ObjectRouteInterface

Latest object route.

finalizeSlug()

finalizeSlug(string  $slug) : string

Finalize slug.

Adds any prefix and suffix defined in the routable configuration set.

Parameters

string $slug

A slug.

Throws

\UnexpectedValueException

If the slug affixes are invalid.

Returns

string

deleteObjectRoutes()

deleteObjectRoutes() : boolean

Delete all object routes.

Should be called on object deletion \Charcoal\Model\AbstractModel::preDelete().

Returns

boolean —

Success or failure.

setObjectRouteClass()

setObjectRouteClass(string  $className) : \Charcoal\Object\AbstractPropertyDisplay

Set the class name of the object route model.

Parameters

string $className

The class name of the object route model.

Throws

\InvalidArgumentException

If the class name is not a string.

Returns

\Charcoal\Object\AbstractPropertyDisplay —

Chainable