lithium\g11n\Catalog::read PHP Метод

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

Results are aggregated by querying all requested configurations for the requested locale then repeating this process for all locales down the locale cascade. This allows for sparse data which is complemented by data from other sources or for more generic locales. Aggregation can be controlled by either specifying the configurations or a scope to use. Usage: Catalog::read(true, 'message', 'zh'); Catalog::read('default', 'message', 'zh'); Catalog::read('default', 'validation.postalCode', 'en_US');
public static read ( mixed $name, string $category, string $locale, array $options = [] ) : array
$name mixed Provide a single configuration name as a string or multiple ones as an array which will be used to read from. Pass `true` to use all configurations.
$category string A (dot-delimeted) category.
$locale string A locale identifier.
$options array Valid options are: - `'scope'`: The scope to use. - `'lossy'`: Whether or not to use the compact and lossy format, defaults to `true`.
Результат array If available the requested data, else `null`.
    public static function read($name, $category, $locale, array $options = array())
    {
        $defaults = array('scope' => null, 'lossy' => true);
        $options += $defaults;
        $category = strtok($category, '.');
        $id = strtok('.');
        $names = $name === true ? array_keys(static::$_configurations) : (array) $name;
        $results = array();
        foreach (Locale::cascade($locale) as $cascaded) {
            foreach ($names as $name) {
                $adapter = static::adapter($name);
                if ($result = $adapter->read($category, $cascaded, $options['scope'])) {
                    $results += $result;
                }
            }
        }
        if ($options['lossy']) {
            array_walk($results, function (&$value) {
                $value = $value['translated'];
            });
        }
        if ($id) {
            return isset($results[$id]) ? $results[$id] : null;
        }
        return $results ?: null;
    }

Usage Example

Пример #1
0
	public function testTransliteration() {
		$data = array(
			'transliteration' => array(
				'\$' => 'dollar',
				'&' => 'and'
			)
		);
		Catalog::write('runtime', 'inflection', 'en', $data);

		Inflector::rules(
			'transliteration', Catalog::read('runtime', 'inflection.transliteration', 'en')
		);

		$result = Inflector::slug('this & that');
		$expected = 'this-and-that';
		$this->assertEqual($expected, $result);

		$data = array(
			'transliteration' => array(
				't' => 'd',
				'&' => 'und'
			)
		);
		Catalog::write('runtime', 'inflection', 'de', $data);

		Inflector::rules(
			'transliteration', Catalog::read('runtime', 'inflection.transliteration', 'de')
		);

		$result = Inflector::slug('this & that');
		$expected = 'dhis-und-dhad';
		$this->assertEqual($expected, $result);
	}
All Usage Examples Of lithium\g11n\Catalog::read