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
Methods
- __construct() : mixed
- Constructor.
- __serialize() : array<string|int, mixed>
- __sleep() : array<string|int, mixed>
- __toString() : string
- Renders the phrase to a string.
- __unserialize() : void
- __wakeup() : void
- 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.
Methods
__construct()
Constructor.
public
__construct(string $phrasegroup, string $phrasekey, mixed ...$parameters) : 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
__serialize()
public
__serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>__sleep()
public
__sleep() : array<string|int, mixed>
Return values
array<string|int, mixed>__toString()
Renders the phrase to a string.
public
__toString() : string
Can be used inline.
Return values
string__unserialize()
public
__unserialize(array<string|int, mixed> $serialized) : void
Parameters
- $serialized : array<string|int, mixed>
__wakeup()
public
__wakeup() : void
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
cachePhraseKey()
Caches a phrasekey.
public
static cachePhraseKey(string $phrasegroup, string $phrasekey) : mixed
Parameters
- $phrasegroup : string
- $phrasekey : string
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.
fetchPhrase()
Fetches a rendered phrase.
public
static fetchPhrase(string $phrasegroup, string $phrasekey[, mixed $parameters = [] ]) : 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 = []
Return values
string —- The translated phrase
fetchSinglePhrase()
Fetches a rendered phrase.
public
static fetchSinglePhrase(string $phrasekey[, mixed $parameters = [] ]) : 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 = []
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
boolparsePhrase()
Parses the tokens in a string with the given values.
public
static parsePhrase(mixed $phrase[, array<string|int, mixed> $parameters = [] ]) : string
Parameters
- $phrase : mixed
- $parameters : array<string|int, mixed> = []
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
setLanguage()
Sets the language id to use for phrasing.
public
static setLanguage([mixed $languageid = NULL ]) : mixed
Parameters
- $languageid : mixed = NULL
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