class FluentDirectorExtension extends Extension (View source)

Fluent extension for \SilverStripe\Control\Director to apply routing rules for locales

Traits

Provides extensions to this object to integrate it with standard config API methods.

Config options

allowed_actions

This is used by extensions designed to be applied to controllers.

from  Extension
detect_locale bool

Determine if the site should detect the browser locale for new users. Turn this off to disable 302 redirects on the home page.

remember_locale bool

Determine if the locale should be remembered across multiple sessions via cookies. If this is left on then visitors to the home page will be redirected to the locale they last viewed. This may interefere with some applications and can be turned off to prevent unexpected redirects.

query_param string

Request parameter to store the locale in

disable_default_prefix bool

Allow the prefix for the default Locale (IsDefault = 1) to be disabled.

force_domain bool

Whether to force "domain mode"

Properties

protected T $owner

The object this extension is applied to.

from  Extension

Methods

public
__construct()

No description

public static 
add_to_class(string $class, string $extensionClass, mixed $args = null)

Called when this extension is added to a particular class

public
setOwner(object $owner)

Set the owner of this extension.

public
mixed
withOwner(mixed $owner, callable $callback, array $args = [])

Temporarily modify the owner. The original owner is ensured to be restored

public
clearOwner()

Clear the current owner, and restore extension to the state prior to the last setOwner()

public
T
getOwner()

Returns the owner of this extension.

public static 
string
get_classname_without_arguments(string $extensionStr)

Helper method to strip eval'ed arguments from a string that's passed to DataObject::$extensions or Object::add_extension().

public
mixed
invokeExtension(object $owner, string $method, array ...$arguments)

Invoke extension point. This will prefer explicit extend prefixed methods.

public static 
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

public
updateRules(array $rules)

Forces regeneration of all locale routes

protected
array
getExplicitRoutes(array $originalRules)

Generate an array of explicit routing rules for each locale

protected
string
getRuleController(array|string $existingRule, Locale $localeObj)

Get controller that fluent should inject

protected
array
insertRuleBefore(array $rules, string $key, array $rule, bool $prependIfMissing = true)

Inserts the given rule(s) before another rule

protected
string
encodeRoutePrefix(string $url)

Safely encode urls

Details

__construct()

No description

static add_to_class(string $class, string $extensionClass, mixed $args = null)

Called when this extension is added to a particular class

Parameters

string $class
string $extensionClass
mixed $args

setOwner(object $owner)

Set the owner of this extension.

Parameters

object $owner

The owner object

mixed withOwner(mixed $owner, callable $callback, array $args = [])

Temporarily modify the owner. The original owner is ensured to be restored

Parameters

mixed $owner

Owner to set

callable $callback

Callback to invoke

array $args

Args to pass to callback

Return Value

mixed

clearOwner()

Clear the current owner, and restore extension to the state prior to the last setOwner()

T getOwner()

Returns the owner of this extension.

Return Value

T

static string get_classname_without_arguments(string $extensionStr)

Helper method to strip eval'ed arguments from a string that's passed to DataObject::$extensions or Object::add_extension().

Parameters

string $extensionStr

E.g. "Versioned('Stage','Live')"

Return Value

string

Extension classname, e.g. "Versioned"

mixed invokeExtension(object $owner, string $method, array ...$arguments)

Invoke extension point. This will prefer explicit extend prefixed methods.

Parameters

object $owner
string $method
array ...$arguments

Return Value

mixed

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

updateRules(array $rules)

Forces regeneration of all locale routes

Parameters

array $rules

Exceptions

Exception

protected array getExplicitRoutes(array $originalRules)

Generate an array of explicit routing rules for each locale

Parameters

array $originalRules

Return Value

array

protected string getRuleController(array|string $existingRule, Locale $localeObj)

Get controller that fluent should inject

Parameters

array|string $existingRule
Locale $localeObj

Return Value

string

Class name of controller to use

protected array insertRuleBefore(array $rules, string $key, array $rule, bool $prependIfMissing = true)

Inserts the given rule(s) before another rule

Parameters

array $rules

Array of rules to insert before

string $key

Rule to insert the new rules before

array $rule

New Rules to insert

bool $prependIfMissing

Prepend the new rules if the insert before rule cannot be found

Return Value

array

Resulting array of rules

protected string encodeRoutePrefix(string $url)

Safely encode urls

Parameters

string $url

Return Value

string

URL encoded url