Exemplo n.º 1
0
 /**
  * Creates a Wisdom service provider.
  *
  * @param Application $app         The Silex application.
  * @param string      $serviceName The new service name.
  * @param string      $pathName    The new path parameter name.
  * @param string      $optionsName The new options parameter name.
  */
 public static function createService(Application $app, $serviceName, $pathName, $optionsName)
 {
     $app[$optionsName] = array();
     $app[$serviceName] = $app->share(function () use($app, $serviceName, $pathName, $optionsName) {
         $app[$optionsName] = array_merge(array('cache_path' => '', 'debug' => $app['debug'], 'prefix' => $app['debug'] ? 'dev.' : 'prod.'), $app[$optionsName]);
         if (false === isset($app[$optionsName]['loaders'])) {
             $options = $app[$optionsName];
             $options['loaders'] = array('KevinGH\\Wisdom\\Loader\\INI', 'KevinGH\\Wisdom\\Loader\\JSON');
             if (class_exists('Symfony\\Component\\Yaml\\Yaml')) {
                 $options['loaders'][] = 'KevinGH\\Wisdom\\Loader\\YAML';
             }
             $app[$optionsName] = $options;
         }
         $wisdom = new Wisdom($app[$pathName]);
         $wisdom->setCache($app[$optionsName]['cache_path']);
         $wisdom->setDebug($app[$optionsName]['debug']);
         $wisdom->setPrefix($app[$optionsName]['prefix']);
         $wisdom->setValues($app);
         foreach ((array) $app[$optionsName]['loaders'] as $class) {
             $wisdom->addLoader(new $class());
         }
         return $wisdom;
     });
 }
Exemplo n.º 2
0
    /**
     * @expectedException LogicException
     * @expectedExceptionMessage Circular dependency detected for:
     */
    public function testGetCircularDependency()
    {
        unlink($dir = tempnam(sys_get_temp_dir(), 'wis'));
        mkdir($dir);
        file_put_contents($dir . '/a.yml', <<<YAML
imports:
    - b.yml
YAML
);
        file_put_contents($dir . '/b.yml', <<<YAML
imports:
    - a.yml
YAML
);
        $wisdom = new Wisdom($dir);
        $wisdom->addLoader(new YAML());
        $wisdom->setCache($dir);
        $result = $wisdom->get('a.yml');
    }