class BundleEntryReader implements BundleEntryReaderInterface

Default implementation of {@link BundleEntryReaderInterface}.

Methods

__construct(BundleReaderInterface $reader)

Creates an entry reader based on the given resource bundle reader.

setLocaleAliases(array $localeAliases)

Stores a mapping of locale aliases to locales.

mixed
read(string $path, string $locale)

Reads a resource bundle.

mixed
readEntry(string $path, string $locale, array $indices, bool $fallback = true)

Reads an entry from a resource bundle.

Details

at line 41
__construct(BundleReaderInterface $reader)

Creates an entry reader based on the given resource bundle reader.

Parameters

BundleReaderInterface $reader

at line 56
setLocaleAliases(array $localeAliases)

Stores a mapping of locale aliases to locales.

This mapping is used when reading entries and merging them with their fallback locales. If an entry is read for a locale alias (e.g. "mo") that points to a locale with a fallback locale ("ro_MD"), the reader can continue at the correct fallback locale ("ro").

Parameters

array $localeAliases A mapping of locale aliases to locales

at line 64
mixed read(string $path, string $locale)

Reads a resource bundle.

Parameters

string $path The path to the resource bundle
string $locale The locale to read

Return Value

mixed returns an array or {@link \ArrayAccess} instance for complex data, a scalar value otherwise

at line 72
mixed readEntry(string $path, string $locale, array $indices, bool $fallback = true)

Reads an entry from a resource bundle.

An entry can be selected from the resource bundle by passing the path to that entry in the bundle. For example, if the bundle is structured like this:

TopLevel
    NestedLevel
        Entry: Value

Then the value can be read by calling:

$reader->readEntry('...', 'en', ['TopLevel', 'NestedLevel', 'Entry']);

Parameters

string $path The path to the resource bundle
string $locale The locale to read
array $indices The indices to read from the bundle
bool $fallback Whether to merge the value with the value from the fallback locale (e.g. "en" for "en_GB"). Only applicable if the result is multivalued (i.e. array or \ArrayAccess) or cannot be found in the requested locale.

Return Value

mixed returns an array or {@link \ArrayAccess} instance for complex data and a scalar value for simple data

Exceptions

MissingResourceException If the indices cannot be accessed