MessageSubjectTranslator
extends AbstractTranslator
in package
Base class of route translators: keeps the list of route factories that use a translator.
Table of Contents
Properties
- $idToSubjectCache : array<int, string>
- $messageManager : MessageManager
- $subjectToIdCache : array<string, int>
- $warmedUp : bool
Methods
- __construct() : mixed
- addTargetFactory() : void
- Registers a route factory that uses this translator.
- clearCache() : void
- Clears the cache.
- getTargetFactories() : array<string|int, string>
- Returns the route factories that use this translator.
- idToName() : string|null
- nameToId() : int|null
- warmupCache() : void
- Preloads the cache.
- warmupFromEntities() : void
- Preloads the cache from already loaded entities, without a database query.
- fromCacheWithLanguageFallback() : TValue|null
- Returns a value from a translation cache, falling back to the other languages.
Properties
$idToSubjectCache
private
array<int, string>
$idToSubjectCache
= []
Cache id->subject [messageId] = webSubject
$messageManager read-only
private
MessageManager
$messageManager
$subjectToIdCache
private
array<string, int>
$subjectToIdCache
= []
Cache subject->id [webSubject] = messageId
$warmedUp
private
bool
$warmedUp
= false
whether the cache has been filled
Methods
__construct()
public
__construct(MessageManager $messageManager) : mixed
Parameters
- $messageManager : MessageManager
addTargetFactory()
Registers a route factory that uses this translator.
public
addTargetFactory(string $factoryClass) : void
Called from the factory constructor as addTargetFactory($this::class).
Parameters
- $factoryClass : string
-
fully qualified factory class name
clearCache()
Clears the cache.
public
clearCache() : void
getTargetFactories()
Returns the route factories that use this translator.
public
getTargetFactories() : array<string|int, string>
Return values
array<string|int, string> —factory class names without namespace
idToName()
public
idToName(int $id) : string|null
Parameters
- $id : int
Return values
string|nullnameToId()
public
nameToId(string $name) : int|null
Parameters
- $name : string
Return values
int|nullwarmupCache()
Preloads the cache.
public
warmupCache([array<string|int, int>|null $ids = null ]) : void
Parameters
- $ids : array<string|int, int>|null = null
-
when null, loads all messages; otherwise only the given ones
warmupFromEntities()
Preloads the cache from already loaded entities, without a database query.
public
warmupFromEntities(array<string|int, mixed> $entities) : void
Parameters
- $entities : array<string|int, mixed>
-
Messageentities
fromCacheWithLanguageFallback()
Returns a value from a translation cache, falling back to the other languages.
protected
fromCacheWithLanguageFallback(array<string|int, mixed> $cache, int $languageId, TKey $key) : TValue|null
IMPORTANT: without the fallback a translator returns null when the translation for the
language is missing, and the route cannot build the URL at all ("No route for ..."). One
untranslated category then breaks the whole foreign-language page, not just its own link.
Untranslated content shows in the main language instead of disappearing: the URL carries
the main-language slug under /en/, until someone adds the translation.
Parameters
- $cache : array<string|int, mixed>
- $languageId : int
- $key : TKey