config() public static method

Sets configurations for this Adaptable implementation.
public static config ( array $config = null ) : array
$config array Configurations, indexed by name.
return array `Collection` of configurations or void if setting configurations.
Beispiel #1
0
    public function testDefaultConfiguration()
    {
        $file = "{$this->_path}/source/a.html.php";
        $data = <<<EOD
<h2>Flowers</h2>
<?=\$t('Apples are green.'); ?>
EOD;
        file_put_contents($file, $data);
        $configs = Catalog::config();
        $configKey1 = key($configs);
        next($configs);
        $configKey2 = key($configs);
        $this->_writeInput(array($configKey1, $configKey2, '', 'y'));
        $result = $this->command->run();
        $expected = 0;
        $this->assertIdentical($expected, $result);
        $expected = '/.*Yielded 1 item.*/';
        $result = $this->command->response->output;
        $this->assertPattern($expected, $result);
        $file = "{$this->_path}/destination/message_default.pot";
        $result = file_exists($file);
        $this->assertTrue($result);
        $result = file_get_contents($file);
        $expected = '/msgid "Apples are green\\."/';
        $this->assertPattern($expected, $result);
        $expected = '#/resources/tmp/tests/source(/|\\\\)a.html.php:2#';
        $this->assertPattern($expected, $result);
        $result = $this->command->response->error;
        $this->assertFalse($result);
    }
 public function testTranslateFail()
 {
     $result = Message::translate('catalog', array('locale' => 'de'));
     $this->assertNull($result);
     Catalog::reset();
     Catalog::config(array('runtime' => array('adapter' => new Memory())));
     $data = array('catalog' => 'Katalog');
     Catalog::write('message', 'de', $data, array('name' => 'runtime'));
     $result = Message::translate('catalog', array('locale' => 'de'));
     $this->assertNull($result);
     $data = 'not a valid pluralization function';
     Catalog::write('message.plural', 'root', $data, array('name' => 'runtime'));
     $result = Message::translate('catalog', array('locale' => 'de'));
     $this->assertNull($result);
 }
Beispiel #3
0
 * Globalization (g11n) catalog configuration.  The catalog allows for obtaining and
 * writing globalized data. Each configuration can be adjusted through the following settings:
 *
 *   - `'adapter' The name of a supported adapter. The builtin adapters are _memory_ (a
 *     simple adapter good for runtime data and testing), _gettext_, _cldr_ (for
 *     interfacing with Unicode's common locale data repository) and _code_ (used mainly for
 *     extracting message templates from source code).
 *
 *   - `'path'` All adapters with the exception of the _memory_ adapter require a directory
 *     which holds the data.
 *
 *   - `'scope'` If you plan on using scoping i.e. for accessing plugin data separately you
 *     need to specify a scope for each configuration, except for those using the _memory_,
 *     _php_ or _gettext_ adapter which handle this internally.
 */
Catalog::config(array('runtime' => array('adapter' => 'Memory'), 'lithium' => array('adapter' => 'Php', 'path' => LITHIUM_LIBRARY_PATH . '/lithium/g11n/resources/php')) + Catalog::config());
/**
 * Integration with `Inflector`.
 */
// Inflector::rules('transliteration', Catalog::read(true, 'inflection.transliteration', 'en'));
/*
 * Inflector configuration examples.  If your application has custom singular or plural rules, or
 * extra non-ASCII characters to transliterate, you can configure that by uncommenting the lines
 * below.
 */
// Inflector::rules('singular', array('rules' => array('/rata/' => '\1ratus')));
// Inflector::rules('singular', array('irregular' => array('foo' => 'bar')));
//
// Inflector::rules('plural', array('rules' => array('/rata/' => '\1ratum')));
// Inflector::rules('plural', array('irregular' => array('bar' => 'foo')));
//
Beispiel #4
0
 /**
  * Helps in selecting or - if required - adding a new `Catalog` collection
  * used for extracting or writing the template. A special configuration
  * with the name `temporary` may be created. Should a configuration with
  * that same name exist prior to entering this method it will be unset.
  *
  * @param array $options Options paired with defaults to prompt for.
  * @return string The name of the selected or newly created configuration.
  */
 protected function _configuration(array $options = array())
 {
     $configs = (array) Catalog::config();
     if (isset($configs['temporary'])) {
         unset($configs['temporary']);
     }
     if ($configs) {
         $this->out('Available `Catalog` Configurations:');
         $prompt = 'Please choose a configuration or hit enter to add a new one:';
         foreach ($configs as $name => $config) {
             $this->out(" - {$name}");
         }
     } else {
         $this->out(' - No configuration found. -');
         $prompt = 'Please hit enter to add a temporary configuration:';
     }
     $this->out();
     $name = $this->in($prompt, array('choices' => array_keys($configs), 'default' => 'temporary'));
     if ($name == 'temporary') {
         foreach ($options as $option => $default) {
             $configs[$name][$option] = $this->in(ucfirst($option) . ':', compact('default'));
         }
         Catalog::config($configs);
     }
     return $name;
 }
Beispiel #5
0
 /**
  * Prompts for data source and writes template.
  *
  * @param array $data Data to save.
  * @return void
  */
 protected function _writeTemplate($data)
 {
     $message[] = 'In order to proceed you need to choose a `Catalog` configuration';
     $message[] = 'which is used for writing the template. The adapter for the configuration';
     $message[] = 'should be capable of handling write requests for the `messageTemplate`';
     $message[] = 'category.';
     $this->out($message);
     $this->out();
     $configs = (array) Catalog::config();
     $this->out('Available `Catalog` Configurations:');
     foreach ($configs as $name => $config) {
         $this->out(" - {$name}");
     }
     $this->out();
     $name = $this->in('Please choose a configuration or hit [enter] to add one:', array('choices' => array_keys($configs)));
     if (!$name) {
         $adapter = $this->in('Adapter:', array('default' => 'Gettext'));
         $path = $this->in('Path:', array('default' => $this->destination));
         $scope = $this->in('Scope:', array('default' => $this->scope));
         $name = 'runtime' . uniqid();
         $configs[$name] = compact('adapter', 'path', 'scope');
         Catalog::config($configs);
     } else {
         $scope = $this->in('Scope:', array('default' => $this->scope));
     }
     $message = array();
     $message[] = 'The template is now ready to be saved.';
     $message[] = 'Please note that an existing template will be overwritten.';
     $this->out($message);
     $this->out();
     if ($this->in('Save?', array('choices' => array('y', 'n'), 'default' => 'y')) != 'y') {
         $this->out('Aborting upon user request.');
         $this->stop(1);
     }
     try {
         return Catalog::write($name, 'messageTemplate', 'root', $data, compact('scope'));
     } catch (Exception $e) {
         return false;
     }
 }
 public function tearDown()
 {
     Catalog::reset();
     Catalog::config($this->_backups['catalogConfig']);
 }
 *     need to specify a scope for each configuration, except for those using the `Memory`,
 *     `Php` or `Gettext` adapter which handle this internally.
 */
Catalog::config(array(
	'runtime' => array(
		'adapter' => 'Memory'
	),
	// 'app' => array(
	// 	'adapter' => 'Gettext',
	// 	'path' => Libraries::get(true, 'resources') . '/g11n'
	// ),
	'lithium' => array(
		'adapter' => 'Php',
		'path' => LITHIUM_LIBRARY_PATH . '/lithium/g11n/resources/php'
	)
) + Catalog::config());

/**
 * Integration with `Inflector`.
 */
// Inflector::rules('transliteration', Catalog::read(true, 'inflection.transliteration', 'en'));

/**
 * Inflector configuration examples.  If your application has custom singular or plural rules, or
 * extra non-ASCII characters to transliterate, you can configure that by uncommenting the lines
 * below.
 */
// Inflector::rules('singular', array('rules' => array('/rata/' => '\1ratus')));
// Inflector::rules('singular', array('irregular' => array('foo' => 'bar')));
//
// Inflector::rules('plural', array('rules' => array('/rata/' => '\1ratum')));
Beispiel #8
0
    public function testContextsNested()
    {
        $file = "{$this->_path}/source/a.html.php";
        $data = <<<EOD
<?=\$t('Robin, {:a}', array('a' => \$t('Michael, {:b}', array('b' => \$t('Bruce', array('context' => 'Lee')), 'context' => 'Jackson')), 'context' => 'Hood')); ?>
EOD;
        file_put_contents($file, $data);
        $configs = Catalog::config();
        $configKey1 = key($configs);
        next($configs);
        $configKey2 = key($configs);
        $this->_writeInput(array($configKey1, $configKey2, '', 'y'));
        $result = $this->command->run();
        $expected = 0;
        $this->assertIdentical($expected, $result);
        $expected = '/.*Yielded 3 item.*/';
        $result = $this->command->response->output;
        $this->assertPattern($expected, $result);
        $file = "{$this->_path}/destination/message_default.pot";
        $this->assertFileExists($file);
        $result = file_get_contents($file);
        $expected = '#/tmp/tests/source(/|\\\\)a.html.php:1';
        $expected .= "\n";
        $expected .= 'msgctxt "Hood"';
        $expected .= "\n";
        $expected .= 'msgid "Robin, {:a}"#';
        $this->assertPattern($expected, $result);
        $expected = '#/tmp/tests/source(/|\\\\)a.html.php:1';
        $expected .= "\n";
        $expected .= 'msgctxt "Jackson"';
        $expected .= "\n";
        $expected .= 'msgid "Michael, {:b}"#';
        $this->assertPattern($expected, $result);
        $expected = '#/tmp/tests/source(/|\\\\)a.html.php:1';
        $expected .= "\n";
        $expected .= 'msgctxt "Lee"';
        $expected .= "\n";
        $expected .= 'msgid "Bruce"#';
        $this->assertPattern($expected, $result);
        $result = $this->command->response->error;
        $this->assertEmpty($result);
    }
 /**
  * Tests reading from multiple configured stores with fallbacks.
  *
  * @return void
  */
 public function testWriteReadMergeConfigurations()
 {
     Catalog::reset();
     Catalog::config(array('runtime0' => array('adapter' => new Memory()), 'runtime1' => array('adapter' => new Memory())));
     $data = '/postalCode en0/';
     Catalog::write('validation.postalCode', 'en', $data, array('name' => 'runtime0'));
     $data = '/postalCode en_US1/';
     Catalog::write('validation.postalCode', 'en_US', $data, array('name' => 'runtime1'));
     $data = '/postalCode en1/';
     Catalog::write('validation.postalCode', 'en', $data, array('name' => 'runtime1'));
     $result = Catalog::read('validation.postalCode', 'en_US');
     $expected = '/postalCode en_US1/';
     $this->assertEqual($expected, $result);
     Catalog::reset();
     Catalog::config(array('runtime0' => array('adapter' => new Memory()), 'runtime1' => array('adapter' => new Memory())));
     $data = array('GRD' => 'de0 Griechische Drachme', 'DKK' => 'de0 Dänische Krone');
     Catalog::write('currency', 'de', $data, array('name' => 'runtime0'));
     $data = array('GRD' => 'de1 Griechische Drachme');
     Catalog::write('currency', 'de', $data, array('name' => 'runtime1'));
     $data = array('GRD' => 'de_CH1 Griechische Drachme');
     Catalog::write('currency', 'de_CH', $data, array('name' => 'runtime1'));
     $result = Catalog::read('currency', 'de_CH');
     $expected = array('GRD' => 'de_CH1 Griechische Drachme', 'DKK' => 'de0 Dänische Krone');
     $this->assertEqual($expected, $result);
 }
Beispiel #10
0
 /**
  * Tests reading from selected multiple configured stores.
  */
 public function testReadMergeSelectedConfigurations()
 {
     Catalog::reset();
     Catalog::config(array('runtime0' => array('adapter' => new Memory()), 'runtime1' => array('adapter' => new Memory()), 'runtime2' => array('adapter' => new Memory())));
     $data = '/postalCode en0/';
     Catalog::write('runtime0', 'validation.postalCode', 'en', $data);
     $data = '/postalCode en1/';
     Catalog::write('runtime1', 'validation.postalCode', 'en', $data);
     $data = '/postalCode en2/';
     Catalog::write('runtime2', 'validation.postalCode', 'en', $data);
     $data = '/ssn en2/';
     Catalog::write('runtime2', 'validation.ssn', 'en', $data);
     $result = Catalog::read('runtime0', 'validation.postalCode', 'en');
     $expected = '/postalCode en0/';
     $this->assertEqual($expected, $result);
     $result = Catalog::read('runtime2', 'validation.postalCode', 'en');
     $expected = '/postalCode en2/';
     $this->assertEqual($expected, $result);
     $result = Catalog::read('runtime2', 'validation.postalCode', 'en');
     $expected = '/postalCode en2/';
     $this->assertEqual($expected, $result);
     $result = Catalog::read(array('runtime0', 'runtime2'), 'validation', 'en');
     $expected = array('postalCode' => '/postalCode en0/', 'ssn' => '/ssn en2/');
     $this->assertEqual($expected, $result);
     $resultA = Catalog::read(array('runtime0', 'runtime2'), 'validation', 'en');
     $resultB = Catalog::read(true, 'validation', 'en');
     $this->assertEqual($resultA, $resultB);
 }
Beispiel #11
0
<?php

use lithium\g11n\Catalog;
/**
 * Register the g11n resources with `Catalog` while maintaining existing
 * configurations. This makes the resources contained in this plugin available
 * to the application this plugin is contained in. `Message::translate()` calls
 * will utilize these resources automatically as long as no or the `li3_lldr`
 * named configuration is selected.
 */
Catalog::config(array('li3_lldr' => array('adapter' => 'Php', 'path' => dirname(__DIR__) . '/resources/g11n/php')) + Catalog::config());
Beispiel #12
0
<?php

/**
 * Register g11n resource.
 */
use lithium\g11n\Catalog;
$catalog = array('li3_docs' => array('adapter' => 'Gettext', 'path' => dirname(__DIR__) . '/resources/g11n'));
Catalog::config($catalog + Catalog::config());
if (file_exists(LITHIUM_APP_PATH . '/config/bootstrap/g11n.php')) {
    require_once LITHIUM_APP_PATH . '/config/bootstrap/g11n.php';
}
/**
 * Initialize code index.
 */
use lithium\core\Libraries;
use lithium\action\Dispatcher;
use lithium\console\Dispatcher as ConsoleDispatcher;
use li3_docs\extensions\docs\Code;
$filter = function ($self, $params, $chain) {
    $indexPath = Libraries::get(true, 'path') . '/resources/docs.index.json';
    if (file_exists($indexPath) && is_readable($indexPath)) {
        Code::index((array) json_decode(file_get_contents($indexPath), true));
    }
    $result = $chain->next($self, $params, $chain);
    if (($index = Code::index()) && is_array($index) && is_writable(dirname($indexPath))) {
        file_put_contents($indexPath, json_encode($index));
    }
    return $result;
};
Dispatcher::applyFilter('run', $filter);
ConsoleDispatcher::applyFilter('run', $filter);
Beispiel #13
0
<?php

/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2010, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */
namespace li3_cldr\config;

use ConfigException;
use lithium\g11n\Catalog;
$insideLibrary = dirname(__DIR__) . '/resources/g11n';
$insideApp = LITHIUM_APP_PATH . '/resources/g11n/cldr';
if (is_dir($insideLibrary . '/main')) {
    $path = $insideLibrary;
} elseif (is_dir($insideApp . '/main')) {
    $path = $insideApp;
} else {
    $message = "CLDR resources could not be found at either `{$insideLibrary}` or `{$insideApp}`.";
    throw new ConfigException($message);
}
/**
 * Add the configuration for the cldr resource to the existing
 * `Catalog` configurations.
 */
Catalog::config(array('cldr' => array('adapter' => 'Cldr', 'path' => $path)) + Catalog::config());
Beispiel #14
0
 *     simple adapter good for runtime data and testing), `Php`, `Gettext`, `Cldr` (for
 *     interfacing with Unicode's common locale data repository) and `Code` (used mainly for
 *     extracting message templates from source code).
 *
 *   - `'path'` All adapters with the exception of the `Memory` adapter require a directory
 *     which holds the data.
 *
 *   - `'scope'` If you plan on using scoping i.e. for accessing plugin data separately you
 *     need to specify a scope for each configuration, except for those using the `Memory`,
 *     `Php` or `Gettext` adapter which handle this internally.
 *
 * @see lithium\g11n\Catalog
 * @link https://github.com/UnionOfRAD/li3_lldr
 * @link https://github.com/UnionOfRAD/li3_cldr
 */
Catalog::config(array('runtime' => array('adapter' => 'Memory'), 'default' => array('adapter' => 'Gettext', 'path' => LITHIUM_APP_PATH . '/resources/g11n'), 'lithium' => array('adapter' => 'Php', 'path' => LITHIUM_LIBRARY_PATH . '/lithium/g11n/resources/php'), 'code' => array('adapter' => 'Code', 'path' => LITHIUM_APP_PATH)) + Catalog::config());
/**
 * Multibyte Strings
 *
 * Configuration for the `Multibyte` class which allows to work with UTF-8
 * encoded strings. At least one configuration named `'default'` must be
 * present. Available adapters are `Intl`, `Mbstring` and `Iconv`. Please keep
 * in mind that each adapter may act differently upon input containing bad
 * UTF-8 sequences. These differences aren't currently equalized or abstracted
 * away.
 *
 * @see lithium\g11n\Multibyte
 */
Multibyte::config(array('default' => array('adapter' => 'Mbstring')) + Multibyte::config());
/**
 * Transliteration