function config($key, $value = null) { if ($value !== null) { Config::set($key, $value); return true; } return Config::get($key); }
/** * Set the locale using PHPs built in setlocale(). * * @link http://php.net/setlocale * @link http://php.net/manual/locale.setdefault.php * * @uses Titon\Common\Config * * @param string $key * @return \Titon\G11n\Locale * @throws \Titon\G11n\Exception\MissingLocaleException */ public function useLocale($key) { $key = self::canonicalize($key); if (!isset($this->_locales[$key])) { throw new MissingLocaleException(sprintf('Locale %s does not exist', $key)); } $locale = $this->_locales[$key]; $locales = [$locale]; $options = []; if ($this->getFallback()->getCode() != $locale->getCode()) { $locales[] = $this->getFallback(); } /** @type \Titon\G11n\Locale $loc */ foreach ($locales as $loc) { $config = $loc->allConfig(); $options[] = $config['code'] . '.UTF8'; $options[] = $config['code'] . '.UTF-8'; $options[] = $config['code']; if (!empty($config['iso3'])) { foreach ((array) $config['iso3'] as $iso3) { $options[] = $iso3 . '.UTF8'; $options[] = $iso3 . '.UTF-8'; $options[] = $iso3; } } if (!empty($config['iso2'])) { $options[] = $config['iso2'] . '.UTF8'; $options[] = $config['iso2'] . '.UTF-8'; $options[] = $config['iso2']; } } // Set environment $code = $locale->getCode(); putenv('LC_ALL=' . $code); setlocale(LC_ALL, $options); \Locale::setDefault($code); $this->_current = $locale; Config::set('titon.locale.current', $code); Config::set('titon.locale.cascade', $this->cascade()); $this->emit('g11n.onUse', [$this, $locale]); // Store via cookie if ($this->getConfig('storeCookie')) { $_COOKIE['locale'] = $key; } return $locale; }
/** * @copyright 2010-2014, The Titon Project * @license http://opensource.org/licenses/bsd-license.php * @link http://titon.io */ use Titon\Cache\Storage\FileSystemStorage; use Titon\Common\Config; use Titon\Debug\Debugger; use Titon\Mvc\Application; /** * -------------------------------------------------------------- * Development * -------------------------------------------------------------- * * Configuration pertaining to development environments should * be defined here. It will be bootstrapped automatically. */ $app = Application::getInstance(); /** * Update caching to use the file system. */ $app->get('cache')->addStorage('default', new FileSystemStorage(['directory' => TEMP_DIR . 'cache/'])); /** * Enable error reporting. */ Debugger::enable(true); /** * Define database login credentials. */ Config::set('db.default', ['host' => 'localhost', 'port' => 3306, 'user' => 'root', 'pass' => '', 'database' => '', 'encoding' => 'utf8']);
/** * Test that set() correctly sets values at the correct depths. */ public function testSet() { Config::set('Set.level1', 1); $this->assertEquals(Config::get('Set.level1'), 1); Config::set('Set.level2.level2', 2); $this->assertEquals(Config::get('Set.level2.level2'), 2); Config::set('Set.level3.level3.level3', 3); $this->assertEquals(Config::get('Set.level3.level3.level3'), 3); Config::set('Set.level4.level4.level4.level4', 4); $this->assertEquals(Config::get('Set.level4.level4.level4.level4'), 4); $this->assertTrue(is_array(Config::get('Set.level4.level4.level4'))); $this->assertFalse(Config::get('Set.level4.level4') === 'falsey'); Config::set('Set.level4.array', ['key' => 'value']); $this->assertEquals(Config::get('Set.level4.array'), ['key' => 'value']); $this->assertEquals(Config::get('Set.level4.array.key'), 'value'); Config::set('Set.level4', 'Flattened!'); $this->assertEquals(Config::get('Set.level4'), 'Flattened!'); $this->assertEquals(Config::get('Set.level4.level4.level4.level4'), null); }
* -------------------------------------------------------------- * Error Handling * -------------------------------------------------------------- * * A custom error handler can be defined that can output error * pages for uncaught exceptions. By default, the Application * object handles errors by initializing an ErrorController * and rendering a template with the View. */ Debugger::setHandler([$app, 'handleError']); /** * -------------------------------------------------------------- * Configuration * -------------------------------------------------------------- * * Define the primary configurations used within the application. * These values can be conveniently accessed via methods on * the Config class -- Config::salt(). */ Config::set('app', ['name' => 'Titon', 'salt' => 'AN3sk8ANjsSl1Hwx910APs7lq8nmsP5LQmKC', 'encoding' => 'UTF-8']); /** * -------------------------------------------------------------- * Resource Mapping * -------------------------------------------------------------- * * Define an array lookup paths for specific types of resources. * These paths will automatically be injected into classes that * make use of them -- for example, G11n and View. */ Config::set('titon.path', ['resources' => [RESOURCES_DIR, VENDOR_DIR . 'titon/g11n/src/resources'], 'views' => [VIEWS_DIR]]);