Example #1
0
 /**
  * @param $jsonString
  * @return Config
  * @throws Exception
  */
 public static function fromJson($jsonString)
 {
     $data = @json_decode($jsonString, true);
     if (!is_array($data)) {
         throw new Exception('bad format');
     }
     return Config::fromArray($data);
 }
Example #2
0
 public function testFromArray()
 {
     $expected = array('nome' => 'andre', 'sobrenome' => 'nascimento');
     $config = new Config();
     $config->fromArray($expected);
     $this->AssertEquals($expected['nome'], $config->get('nome'));
     $this->AssertEquals($expected['sobrenome'], $config->get('sobrenome'));
 }
Example #3
0
 /**
  * Parses the global configuration file and that of each
  * application.
  */
 protected function parseconf()
 {
     // Loading the main configuration file first so we can get the paths.
     $this->conf = Config::fromArray(array('prefix' => '', 'apps_path' => 'apps', 'models_path' => 'models', 'helpers_path' => 'helpers', 'exceptions_path' => 'exceptions', 'modules_path' => 'lib/modules', 'apps' => array(), 'modules' => array()));
     // Defaults
     $this->conf->loadFile($this->conf_path);
     if ($this->conf->get('prefix')) {
         $this->server->setPrefix($this->prefix);
     }
     // Alright. Now let's load the apps config. We'll merge the apps routes as we go along.
     foreach ($this->conf->get('apps', array()) as $appname) {
         $path = Utils::joinPaths($this->conf->get('apps_path'), $appname, 'conf.php');
         try {
             $this->apps_conf[$appname] = Config::fromFile($path, 'app');
         } catch (\Exception $e) {
             continue;
         }
         // Little shortcut to help readability
         $app = $this->apps_conf[$appname];
         $this->router->setRoutes($appname, $app->get('route'));
         // Let's merge in the modules, they'll be common to all apps.
         $modules = $this->conf->get('modules', array());
         if ($app->get('modules')) {
             foreach ($app->get('modules') as $module) {
                 if (!in_array($module, $modules)) {
                     $modules[] = $module;
                     if ($app->get($module)) {
                         // Module-specific options.
                         $this->conf->set($module, $app->get($module));
                     }
                 }
             }
         }
     }
     $this->server->setMainConf($this->conf);
 }
Example #4
0
 public function testGetRawData()
 {
     $data = ['a' => 1, 'b' => ['x' => 'y']];
     $conf = Config::fromArray($data);
     $this->assertEquals($data, $conf->rawData());
     $this->assertEquals(['x' => 'y'], $conf->sub('b')->rawData());
 }
Example #5
0
 private function parseConfig()
 {
     $config = new Config();
     $config->fromArray($this->readConfig());
     return $config;
 }