DetectLocaleMiddleware
class DetectLocaleMiddleware implements HTTPMiddleware (View source)
DetectLocaleMiddleware will detect if a locale has been requested (or is default) and is not the current locale, and will redirect the user to that locale if needed.
Will cascade through different checks in order, see "configuration" docs for details. Additionally, detected locales will be set in session and cookies.
Traits
Provides extensions to this object to integrate it with standard config API methods.
Config options
persist_ids | string[] | IDs to persist the locale in cookies / session in the front end, CMS, etc |
|
persist_cookie | bool | Use cookies for locale persistence. |
|
persist_cookie_expiry | int | The expiry time in days for a locale persistence cookie |
|
persist_cookie_path | string | Use this path when setting the locale cookie |
|
persist_cookie_domain | string | Use this domain when setting the locale cookie |
|
persist_cookie_http_only | bool | Use http-only cookies. Set to false if you need js access. |
Properties
protected | bool | $cookiesPersisted | Whether cookies have already been set during setPersistLocale() |
Methods
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
Gets the uninherited value for the given config option
Sets the current locale to the FluentState, provided no previous middleware has set it first
Get the current locale from routing parameters, persistence, browser locale, etc
Gets the locale currently set within either the session or cookie.
Specify the locale to persist between sessions, or to use for the locale outside of locale-routed pages (such as in unit tests, custom controllers, etc).
Get the Fluent locale persistence key. See the "persist_ids" config static.
Get locale from the domain, if the current domain has exactly one locale
Details
static Config_ForClass
config()
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
mixed
stat(string $name)
deprecated
deprecated
Get inherited config value
mixed
uninherited(string $name)
Gets the uninherited value for the given config option
$this
set_stat(string $name, mixed $value)
deprecated
deprecated
Update the config value for a given property
HTTPResponse
process(HTTPRequest $request, callable $delegate)
Sets the current locale to the FluentState, provided no previous middleware has set it first
{@inheritDoc}
protected string
getLocale(HTTPRequest $request)
Get the current locale from routing parameters, persistence, browser locale, etc
protected null|string
getPersistLocale(HTTPRequest $request)
Gets the locale currently set within either the session or cookie.
protected $this
setPersistLocale(HTTPRequest $request, string $locale)
Specify the locale to persist between sessions, or to use for the locale outside of locale-routed pages (such as in unit tests, custom controllers, etc).
Not to be confused with the temporary locale assigned with withLocale(). @todo implement this.
protected string
getPersistKey()
Get the Fluent locale persistence key. See the "persist_ids" config static.
protected mixed
getParamLocale(HTTPRequest $request)
Get locale from the query_param
protected string
getDomainLocale()
Get locale from the domain, if the current domain has exactly one locale
protected string
getDetectedLocale(HTTPRequest $request)
Use the configured LocaleDetector to guess the locale
protected string
getDefaultLocale()
Get default locale