示例#1
0
 public function testIfStoreAndRetrive()
 {
     $c = new Config(['a' => 'valueA']);
     $this->assertEquals('valueA', $c->get('a'), 'Not storing config data on instancing.');
     $c->set('b', 'valueB');
     $this->assertEquals('valueB', $c->get('b'), "Isn\\'t storing or retrieving simple values.");
     $exp = ['c' => 'valueC', 'd' => 'valueD'];
     $c->set($exp);
     $this->assertTrue($exp == $c->get(['c', 'd']), "It isn't storing or retrieving arrays.");
     $c->env = 'Staging';
     $this->assertEquals('Staging', $c->get('env'), "It isn't storing using dynamic properties.");
 }
示例#2
0
 protected function loadModule($modCfgArray, $modIdx)
 {
     $cfg = new Config($modCfgArray['default']);
     $ns = $cfg->get('namespace');
     // If this class can't be loaded, enable the autoload using the composer class loader.
     if (!empty($ns)) {
         // Full directory of the module to be initialized.
         $dir = $cfg->get('directory');
         $parentDir = $this->config->get('directory');
         $parentModulesDir = $this->config->get('modulesDir');
         if (preg_match('/^\\//', $dir) > 0) {
         } else {
             if (preg_match('/^\\//', $parentModulesDir) > 0) {
                 $dir = $parentModulesDir . DIRECTORY_SEPARATOR . $dir;
             } else {
                 $dir = $parentDir . DIRECTORY_SEPARATOR . $parentModulesDir . DIRECTORY_SEPARATOR . $dir;
             }
         }
         $dirReal = realpath($dir) . DIRECTORY_SEPARATOR;
         if (!$dirReal) {
             throw new \Exception("The directory {$dir} of the child module does not exists or is not readable.");
         }
         // Override the current module 'directory' value
         $cfg->set('directory', $dir);
         // Add the namespacec to the  composer ClassLoader
         $loader = new ClassLoader();
         $loader->add($ns, $dir);
         $loader->register();
         $loader->setUseIncludePath(true);
     }
     if ($cn = $cfg->get('moduleClassName')) {
         $mClass = $ns . '\\' . $cn;
     } else {
         // Use the default moduleClassName. See the top of this file.
         $mClass = $this->config->get('moduleClassName');
     }
     // Add others options sets, if provided
     foreach ($modCfgArray as $k => $optSet) {
         if ($k == 'default') {
             continue;
         }
         $cfg->set($optSet, null, $k);
     }
     // Instance the module.
     $mod = new $mClass($cfg, $this, $this->injections);
     return $this->children[$modIdx] = $mod;
 }