PHP Класс Fluent

Автор: Damian Mooyman ([email protected])
Наследование: extends Object, implements TemplateGlobalProvider
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_search_dapter FluentSearchAdapter Cached search adapter
$force_is_frontend boolean If set, "is_frontend" can be forced to return a value
$last_set_locale Indicates the last locale set via Cookies, in order to prevent excessive Cookie setting

Открытые методы

Метод Описание
alias ( string $locale ) : string Determine the alias to use for a specific locale
any_match ( string $value, array $patterns ) : boolean Helper function to check if the value given is present in any of the patterns.
current_locale ( boolean $persist = true ) : string Gets the current locale
db_field_for_locale ( string $field, string $locale ) Determine the DB field name to use for the given base field
default_locale ( mixed $domain = null ) : string Retrieves the default locale
detect_browser_locale ( mixed $domain = null ) : string Determines the locale best matching the given list of browser locales
disable_default_prefix ( ) : boolean Check if default locale should have prefix disabled
domain_for_locale ( string $locale ) Determine the home domain for this locale
domains ( ) : array Retrieves any configured domains, assuming the site is running in domain mode.
get_persist_locale ( string $key = null ) : string | null Gets the locale currently set within either the session or cookie.
get_request_locale ( ) : string Gets the locale requested directly in the request, either via route, post, or query parameters
get_template_global_variables ( ) : array
init ( ) Initialise routes
install_locale ( boolean $persist = true ) Installs the current locale into i18n
isFieldModified ( DataObject $object, FormField $field, string | null $locale = null ) : boolean Given a field on an object and optionally a locale, compare its locale value against the default locale value to determine if the value is changed at the given locale.
is_domain_mode ( ) : boolean Determine if the website is in domain segmentation mode
is_frontend ( boolean $ignoreController = false ) : boolean Determines behaviour of locale filter in this request, by detecting whether to present an admin view of the site, or a frontend view.
is_locale ( string $locale ) : boolean Determine if a locale code is within the range of configured locales
locale_baseurl ( string $locale = null ) : string Determine the baseurl within a specified $locale.
locale_names ( ) : array Retrieves the list of locale names as an associative array
locale_native_name ( string $locale ) : string Fetch a native language string from the i18n class via a passed locale in the format "XX_xx". In the event a match cannot be found in any framework resource, an empty string is returned.
locales ( mixed $domain = null ) : array Retrieves the list of locales
regenerate_routes ( ) Forces regeneration of all locale routes
search_adapter ( ) : FluentSearchAdapter Retrieves a search adapter for the current database adapter
set_force_is_frontend ( boolean $force = true ) Sets whether to force "is_frontend" to return true or false. This can be used for situations where the frontend controllers are not involved, e.g. API modules, unit testing or retrieving data programmatically.
set_persist_locale ( string $locale, string $key = null ) 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).
with_locale ( string $locale, callable $callback ) : mixed Executes a callback with a locale to temporarily emulate.

Описание методов

alias() публичный статический Метод

Determine the alias to use for a specific locale
public static alias ( string $locale ) : string
$locale string Locale in language_Country format
Результат string Locale in its original form, or its alias if one exists

any_match() публичный статический Метод

This function is case sensitive by default.
public static any_match ( string $value, array $patterns ) : boolean
$value string A string value to check against, potentially with parameters (E.g. 'Varchar(1023)')
$patterns array A list of strings, some of which may be regular expressions
Результат boolean True if this $value is present in any of the $patterns

current_locale() публичный статический Метод

Gets the current locale
public static current_locale ( boolean $persist = true ) : string
$persist boolean Attempt to persist any detected locale within session / cookies
Результат string i18n locale code

db_field_for_locale() публичный статический Метод

Determine the DB field name to use for the given base field
public static db_field_for_locale ( string $field, string $locale )
$field string DB field name
$locale string Locale to use

default_locale() публичный статический Метод

Retrieves the default locale
public static default_locale ( mixed $domain = null ) : string
$domain mixed Domain to determine the default locale for. If null, the global default will be returned. If true, then the current domain will be used.
Результат string

detect_browser_locale() публичный статический Метод

Determines the locale best matching the given list of browser locales
public static detect_browser_locale ( mixed $domain = null ) : string
$domain mixed Domain to determine the locales for. If null, the global list be returned. If true, then the current domain will be used.
Результат string The matching locale, or null if none could be determined

disable_default_prefix() публичный статический Метод

Check if default locale should have prefix disabled
public static disable_default_prefix ( ) : boolean
Результат boolean

domain_for_locale() публичный статический Метод

Determine the home domain for this locale
public static domain_for_locale ( string $locale )
$locale string

domains() публичный статический Метод

Retrieves any configured domains, assuming the site is running in domain mode.
public static domains ( ) : array
Результат array List of domains and their respective configuration information

get_persist_locale() публичный статический Метод

Gets the locale currently set within either the session or cookie.
public static get_persist_locale ( string $key = null ) : string | null
$key string ID to retrieve persistant locale from. Will automatically detect if omitted. Either Fluent::config()->persist_id or Fluent::config()->persist_id_cms.
Результат string | null The locale, if available

get_request_locale() публичный статический Метод

Gets the locale requested directly in the request, either via route, post, or query parameters
public static get_request_locale ( ) : string
Результат string The locale, if available

get_template_global_variables() публичный статический Метод

public static get_template_global_variables ( ) : array
Результат array

init() публичный статический Метод

Initialise routes
public static init ( )

install_locale() публичный статический Метод

Installs the current locale into i18n
public static install_locale ( boolean $persist = true )
$persist boolean Attempt to persist any detected locale within session / cookies

isFieldModified() публичный статический Метод

Given a field on an object and optionally a locale, compare its locale value against the default locale value to determine if the value is changed at the given locale.
public static isFieldModified ( DataObject $object, FormField $field, string | null $locale = null ) : boolean
$object DataObject
$field FormField
$locale string | null Optional: if not provided, will be gathered from the request
Результат boolean

is_domain_mode() публичный статический Метод

Determine if the website is in domain segmentation mode
public static is_domain_mode ( ) : boolean
Результат boolean

is_frontend() публичный статический Метод

If viewing in the CMS items filtered by locale will always be visible, but in the frontend will be filtered as expected. For the sake of unit tests Fluent assumes a frontend execution environment.
public static is_frontend ( boolean $ignoreController = false ) : boolean
$ignoreController boolean Flag to indicate whether the current controller should be ignored, and detection should be performed by inspecting the URL. Used for testing. Defaults to false.
Результат boolean Flag indicating if the translation should act on the frontend

is_locale() публичный статический Метод

Determine if a locale code is within the range of configured locales
public static is_locale ( string $locale ) : boolean
$locale string
Результат boolean True if this locale is valid

locale_baseurl() публичный статический Метод

Determine the baseurl within a specified $locale.
public static locale_baseurl ( string $locale = null ) : string
$locale string Locale, or null to use current locale
Результат string

locale_names() публичный статический Метод

Retrieves the list of locale names as an associative array
public static locale_names ( ) : array
Результат array List of locale names mapped by locale code

locale_native_name() публичный статический Метод

Fetch a native language string from the i18n class via a passed locale in the format "XX_xx". In the event a match cannot be found in any framework resource, an empty string is returned.
public static locale_native_name ( string $locale ) : string
$locale string e.g. "pt_BR"
Результат string The native language string for that locale e.g. "português (Brazil)"

locales() публичный статический Метод

Retrieves the list of locales
public static locales ( mixed $domain = null ) : array
$domain mixed Domain to determine the locales for. If null, the global list be returned. If true, then the current domain will be used.
Результат array List of locales

regenerate_routes() публичный статический Метод

Forces regeneration of all locale routes
public static regenerate_routes ( )

search_adapter() публичный статический Метод

Retrieves a search adapter for the current database adapter
public static search_adapter ( ) : FluentSearchAdapter
Результат FluentSearchAdapter

set_force_is_frontend() публичный статический Метод

Sets whether to force "is_frontend" to return true or false. This can be used for situations where the frontend controllers are not involved, e.g. API modules, unit testing or retrieving data programmatically.
public static set_force_is_frontend ( boolean $force = true )
$force boolean

set_persist_locale() публичный статический Метод

Not to be confused with the temporary locale assigned with {@see \Fluent::with_locale} .
public static set_persist_locale ( string $locale, string $key = null )
$locale string Locale to assign
$key string ID to set the locale against. Will automatically detect if omitted. Either Fluent:::config()->persist_id or Fluent::::config()->persist_id_cms.

with_locale() публичный статический Метод

Warning: Existing DataObjects will contain fields in the actual locale if already lazily loaded, or if used within the callback, will populate itself with the overriding locale. The inverse will occur once the callback is complete. The best practice is to consider this a sandbox, and re-requery all objects required, discarding these afterwards.
public static with_locale ( string $locale, callable $callback ) : mixed
$locale string The locale to set
$callback callable The callback
Результат mixed The returned value from the $callback

Описание свойств

$_search_dapter защищенное статическое свойство

Cached search adapter
protected static FluentSearchAdapter $_search_dapter
Результат FluentSearchAdapter

$force_is_frontend защищенное статическое свойство

If set, "is_frontend" can be forced to return a value
protected static bool $force_is_frontend
Результат boolean

$last_set_locale защищенное статическое свойство

Indicates the last locale set via Cookies, in order to prevent excessive Cookie setting
protected static $last_set_locale