vB_Phrase
in package
Uses
vB_Trait_NoSerialize
Phrase Stores a phrasegroup / key pair for deferred rendering.
When a new phrase is created, the phrasegroup and key is cached. Whenever a phrase is rendered to a string, all of the phrasegroups / keys are fetched in a single query and the phrasegroup cache is purged.
Tags
Table of Contents
- $languageid : int
- The languageid to use throughout the session.
- $parameters : array<string|int, mixed>
- Parameters to parse with the phrase.
- $phrase_cache : array<string|int, mixed>
- Local phrase cache.
- $phrasegroup : string
- The phrasegroup of the phrase.
- $phrasekey : string
- The phrasekey of the phrase.
- $phrasekey_cache : array<string|int, mixed>
- Local phrasekey cache.
- $precache : array<string|int, mixed>
- Precached phrases.
- $precached_groups : array<string|int, mixed>
- Groups that were loaded in the precache.
- $uncachable_groups : array<string|int, mixed>
- Phrasegroups that cannot be cached.
- __construct() : mixed
- Constructor.
- __serialize() : mixed
- __sleep() : mixed
- __toString() : string
- Renders the phrase to a string.
- __unserialize() : mixed
- __wakeup() : mixed
- addPhrases() : mixed
- Allows existing phrases to be added.
- cachePhraseKey() : mixed
- Caches a phrasekey.
- clearCache() : mixed
- Clears the phrasekey cache.
- fetchPhrase() : string
- Fetches a rendered phrase.
- fetchSinglePhrase() : string
- Fetches a rendered phrase.
- groupCachable() : bool
- Checks if a phrasegroup is cachable.
- parsePhrase() : string
- Parses the tokens in a string with the given values.
- preCache() : mixed
- Allows prefetched phrases to be assigned to vB_Phrase.
- setLanguage() : mixed
- Sets the language id to use for phrasing.
- setPhraseGroup() : mixed
- Sets a phrasegroup and removes it from the key cache.
- fetchCache() : mixed
- Fetches the phrases for all of the keys in the cache.
- fetchUncachablePhrase() : string
- Fetches a phrase without using any caching.
- replaceVars() : string
- Replaces '{X} with variables
Properties
$languageid
The languageid to use throughout the session.
protected
static int
$languageid
$parameters
Parameters to parse with the phrase.
protected
array<string|int, mixed>
$parameters
$phrase_cache
Local phrase cache.
protected
static array<string|int, mixed>
$phrase_cache
= array()
When the cached phrasegroups are fetched, the phrases are stored here.
$phrasegroup
The phrasegroup of the phrase.
protected
string
$phrasegroup
Used with an instatiated object to reference a specific phrase.
$phrasekey
The phrasekey of the phrase.
protected
string
$phrasekey
Used with an instantiated object to reference a specific phrase
$phrasekey_cache
Local phrasekey cache.
protected
static array<string|int, mixed>
$phrasekey_cache
= array()
The cached phrasegroups.
$precache
Precached phrases.
protected
static array<string|int, mixed>
$precache
= array()
Precached phrases are phrases fetched before initialisation and assigned with vB_Phrase::preCache(). The individual groups that the phrases belong to are unknown, but the groups that are loaded into the precache can also be specified.
Tags
$precached_groups
Groups that were loaded in the precache.
protected
static array<string|int, mixed>
$precached_groups
= array()
Tags
$uncachable_groups
Phrasegroups that cannot be cached.
protected
static array<string|int, mixed>
$uncachable_groups
= array('error', 'frontredirect', 'emailbody', 'emailsubject', 'vbsettings', 'cphelptext', 'faqtitle', 'faqtext', 'hvquestion')
Methods
__construct()
Constructor.
public
__construct(string $phrasegroup, string $phrasekey[, mixed $parameters = null ]) : mixed
When a phrase is constructed, the phrasegroup and phrasekey are cached until the next time a phrase is rendered to a string.
Parameters
- $phrasegroup : string
-
- The phrase group where the phrase is located
- $phrasekey : string
-
- The phrasekey of the phrase
- $parameters : mixed = null
Return values
mixed —__serialize()
public
__serialize() : mixed
Return values
mixed —__sleep()
public
__sleep() : mixed
Return values
mixed —__toString()
Renders the phrase to a string.
public
__toString() : string
Can be used inline.
Return values
string —__unserialize()
public
__unserialize(mixed $serialized) : mixed
Parameters
- $serialized : mixed
Return values
mixed —__wakeup()
public
__wakeup() : mixed
Return values
mixed —addPhrases()
Allows existing phrases to be added.
public
static addPhrases(mixed $phrasegroups) : mixed
$phrases should be in the form array(phrasegroup => array(phrasekey => phrase))
Parameters
- $phrasegroups : mixed
Return values
mixed —cachePhraseKey()
Caches a phrasekey.
public
static cachePhraseKey(string $phrasegroup, string $phrasekey) : mixed
Parameters
- $phrasegroup : string
- $phrasekey : string
Return values
mixed —clearCache()
Clears the phrasekey cache.
public
static clearCache() : mixed
This is useful when it is known that all previously cached phrases are no longer needed; such as when a redirect or user error occurs.
Return values
mixed —fetchPhrase()
Fetches a rendered phrase.
public
static fetchPhrase(string $phrasegroup, string $phrasekey[, mixed $parameters = array() ]) : string
If the phrase is not in the local phrase cache, then the phrasekey cache is loaded and purged.
Parameters
- $phrasegroup : string
-
- The phrase group where the phrase is located. Can be null.
- $phrasekey : string
-
- The phrasekey of the phrase
- $parameters : mixed = array()
Return values
string —- The translated phrase
fetchSinglePhrase()
Fetches a rendered phrase.
public
static fetchSinglePhrase(string $phrasekey[, mixed $parameters = array() ]) : string
If the phrase is not in the local phrase cache, then the phrasekey cache is loaded and purged.
Parameters
- $phrasekey : string
-
- The phrasekey of the phrase
- $parameters : mixed = array()
Return values
string —- The translated phrase
groupCachable()
Checks if a phrasegroup is cachable.
public
static groupCachable(string $phrasegroup) : bool
Some phrasegroups are not cachable, such as error or redirect messages.
Parameters
- $phrasegroup : string
-
- The name of the phrasegroup to check
Return values
bool —parsePhrase()
Parses the tokens in a string with the given values.
public
static parsePhrase(mixed $phrase[, array<string|int, mixed> $parameters = null ]) : string
Parameters
- $phrase : mixed
- $parameters : array<string|int, mixed> = null
Return values
string —- The resulting string
preCache()
Allows prefetched phrases to be assigned to vB_Phrase.
public
static preCache(array<string|int, mixed> $phrases, array<string|int, mixed> $groups) : mixed
Parameters
- $phrases : array<string|int, mixed>
-
- Assoc array of key => phrase
- $groups : array<string|int, mixed>
-
- Array of groups in the precache
Return values
mixed —setLanguage()
Sets the language id to use for phrasing.
public
static setLanguage([mixed $languageid = NULL ]) : mixed
Parameters
- $languageid : mixed = NULL
Return values
mixed —setPhraseGroup()
Sets a phrasegroup and removes it from the key cache.
public
static setPhraseGroup(string $groupname, mixed $phrases) : mixed
Parameters
- $groupname : string
-
- The group to set
- $phrases : mixed
Return values
mixed —fetchCache()
Fetches the phrases for all of the keys in the cache.
protected
static fetchCache() : mixed
Return values
mixed —fetchUncachablePhrase()
Fetches a phrase without using any caching.
protected
static fetchUncachablePhrase(string $phrasegroup, string $phrasekey[, string $languageid = false ]) : string
This is useful for uncachable phrases such as error messages and redirect messages.
Parameters
- $phrasegroup : string
-
- The phrase group where the phrase is located
- $phrasekey : string
-
- The phrasekey of the phrase
- $languageid : string = false
-
- Id of the language to fetch from
Return values
string —- The translated phrase
replaceVars()
Replaces '{X} with variables
protected
static replaceVars(mixed $phrase, mixed $params) : string
Parameters
- $phrase : mixed
- $params : mixed