Exemplo n.º 1
0
 public function testSimple()
 {
     $loader = new Loader();
     $path = $this->configPath("test1.php");
     $data = $loader->loadFile($path, true);
     // echo $this->json($data);
     // echo $this->json($loader->getErrors());
 }
Exemplo n.º 2
0
 /**
  * @param string $filename
  * @param array $classmap
  * @return static
  * @throws Exception\RuntimeException
  */
 public function load($filename, $key = 'form', array $classmap = [])
 {
     if (file_exists($filename)) {
         $loader = new Param\Loader($filename);
         $config = $loader->load();
         if (isset($config[$key])) {
             $this->build($config[$key], $classmap);
         } else {
             throw new Exception\RuntimeException("Key [{$key}] not found in configuration", 2);
         }
     } else {
         throw new Exception\RuntimeException("Config file ({$filename}) not found", 1);
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Loads the application configuration
  *
  * @param string|array|Param\Loader $config
  * @return self
  * @throws Exception\InvalidArgumentException
  */
 public function loadConfig($config)
 {
     if ($config instanceof Param\Loader) {
         $data = $config->load();
     } elseif (is_string($config)) {
         $loader = new Param\Loader($config);
         $data = $loader->load();
     } elseif (is_array($config)) {
         $data = $config;
     } elseif (is_callable($config)) {
         $data = $config();
     } else {
         $type = is_object($config) ? get_class($config) : gettype($config);
         throw new Exception\InvalidArgumentException("Application configuration is of wrong type ({$type})");
     }
     $this->getResources()->setConfig(new Param\Node($data));
     return $this;
 }