Ejemplo n.º 1
0
 public function testConfig()
 {
     $arr = ['a' => ['b' => ['c' => ['d' => 'e']]], 'f' => 'h'];
     $config = new \Phalcon\Config($arr);
     $this->assertInstanceOf(\Phalcon\Config::class, Stingray::get($config, 'a'));
     $this->assertEquals($arr['a'], Stingray::get($config, 'a')->toArray());
     $this->assertInstanceOf(\Phalcon\Config::class, Stingray::get($config, 'a.b'));
     $this->assertEquals($arr['a']['b'], Stingray::get($config, 'a.b')->toArray());
     $this->assertInstanceOf(\Phalcon\Config::class, Stingray::get($config, 'a.b.c'));
     $this->assertEquals($arr['a']['b']['c'], Stingray::get($config, 'a.b.c')->toArray());
     $this->assertEquals($arr['a']['b']['c']['d'], Stingray::get($config, 'a.b.c.d'));
     $this->assertEquals($arr['f'], Stingray::get($config, 'f'));
     $this->assertNull(Stingray::get($config, 'a.b.d'));
     $this->assertNull(Stingray::get($config, 'a.b.c.d.e.f.g'));
     $this->assertEquals($arr, $config->toArray());
 }
 /**
  * replace ServiceConstants::TYPE_CONFIG_PARAMETER stubs to its values
  * @param Config $config
  * @throws \Anthill\Phalcon\KernelModule\DependencyInjection\Exceptions\ConfigParseException
  */
 private function replaceConfigParameter(Config $config)
 {
     foreach ($config as $item) {
         if ($item instanceof Config) {
             if (!$item->offsetExists('type')) {
                 $this->replaceConfigParameter($item);
                 continue;
             }
             if ($item->get('type') !== ServiceConstants::TYPE_CONFIG_PARAMETER) {
                 $this->replaceConfigParameter($item);
                 continue;
             }
             $value = $item->get('value');
             $newValue = Stingray::get($this->getConfig(), $value);
             if ($newValue === null) {
                 throw new ConfigParseException(sprintf('You must specify parameter "%s" in config', str_replace('.', ' => ', $value)));
             }
             $item->offsetSet('type', ServiceConstants::TYPE_PARAMETER);
             $item->offsetSet('value', $newValue);
         }
     }
 }
Ejemplo n.º 3
0
 public function registerRoutes()
 {
     /* @var $resolver RouterResolver */
     $resolver = $this->getDI()->get('route_resolver');
     $routesConfig = Stingray::get($this->getConfig()->toArray(), 'framework.routes');
     $resolver->resolve($routesConfig);
 }