Permalink
Browse files

Changing the signature of `Catalog::read()` and `Catalog::write()`.

Extracting the `name` option and adding it as the parameter.

`Catalog::write()` now doesn't work with multiple configurations
anymore. Instead only a single configuration may be supplied.

`Catalog::read()` will read from all configurations when `true` is being
passed for the `$name` parameter. This is the same behavior as before
when not providing any configuration name through the options array.

Updating all tests.
Adding tests for `read()`.
  • Loading branch information...
davidpersson authored and gwoo committed Jul 16, 2010
1 parent 9226d01 commit d29e3f53b61cec032b1f1a7650ea3d20977eeced
@@ -75,7 +75,7 @@
/**
* Integration with `Inflector`.
*/
-// Inflector::rules('transliteration', Catalog::read('inflection.transliteration', 'en'));
+// Inflector::rules('transliteration', Catalog::read(true, 'inflection.transliteration', 'en'));
/*
* Inflector configuration examples. If your application has custom singular or plural rules, or
@@ -110,7 +110,7 @@
* by specifying them manually or retrieving them with the `Catalog` class.
*/
foreach (array('phone', 'postalCode', 'ssn') as $name) {
- Validator::add($name, Catalog::read("validation.{$name}", 'en_US'));
+ Validator::add($name, Catalog::read(true, "validation.{$name}", 'en_US'));
}
/**
@@ -64,26 +64,28 @@ public static function config($config = null) {
*
* Usage:
* {{{
- * Catalog::read('message', 'zh');
- * Catalog::read('validation.postalCode', 'en_US');
+ * Catalog::read(true, 'message', 'zh');
+ * Catalog::read('default', 'message', 'zh');
+ * Catalog::read('default', 'validation.postalCode', 'en_US');
* }}}
*
+ * @param mixed $name 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.
* @param string $category A (dot-delimeted) category.
* @param string $locale A locale identifier.
* @param array $options Valid options are:
- * - `'name'`: One or multiple configuration names.
* - `'scope'`: The scope to use.
* - `'lossy'`: Whether or not to use the compact and lossy format, defaults to `true`.
* @return array|void If available the requested data, else `null`.
*/
- public static function read($category, $locale, array $options = array()) {
- $defaults = array('name' => null, 'scope' => null, 'lossy' => true);
+ public static function read($name, $category, $locale, array $options = array()) {
+ $defaults = array('scope' => null, 'lossy' => true);
$options += $defaults;
$category = strtok($category, '.');
$id = strtok('.');
- $names = (array) $options['name'] ?: array_keys(static::$_configurations);
+ $names = $name === true ? array_keys(static::$_configurations) : (array) $name;
$results = array();
foreach (Locale::cascade($locale) as $cascaded) {
@@ -115,19 +117,19 @@ public static function read($category, $locale, array $options = array()) {
* $data = array(
* 'color' => '色'
* );
- * Catalog::write('message', 'ja', $data, array('name' => 'runtime'));
+ * Catalog::write('runtime', 'message', 'ja', $data);
* }}}
*
+ * @param string $name Provide a configuration name to use for writing.
* @param string $category A (dot-delimited) category.
* @param string $locale A locale identifier.
* @param mixed $data If method is used without specifying an id must be an array.
* @param array $options Valid options are:
- * - `'name'`: One or multiple configuration names.
* - `'scope'`: The scope to use.
* @return boolean Success.
*/
- public static function write($category, $locale, $data, array $options = array()) {
- $defaults = array('name' => null, 'scope' => null);
+ public static function write($name, $category, $locale, $data, array $options = array()) {
+ $defaults = array('scope' => null);
$options += $defaults;
$category = strtok($category, '.');
@@ -143,13 +145,8 @@ public static function write($category, $locale, $data, array $options = array()
}
});
- $names = (array) $options['name'] ?: array_keys(static::$_configurations);
-
- foreach ($names as $name) {
- $adapter = static::adapter($name);
- return $adapter->write($category, $locale, $options['scope'], $data);
- }
- return false;
+ $adapter = static::adapter($name);
+ return $adapter->write($category, $locale, $options['scope'], $data);
}
}
@@ -191,7 +191,9 @@ protected static function _translated($id, $count, $locale, array $options = arr
extract($params);
if (!isset($cache[$options['scope']][$locale])) {
- $cache[$options['scope']][$locale] = Catalog::read('message', $locale, $options);
+ $cache[$options['scope']][$locale] = Catalog::read(
+ true, 'message', $locale, $options
+ );
}
$page = $cache[$options['scope']][$locale];
Oops, something went wrong.

0 comments on commit d29e3f5

Please sign in to comment.