parseServices() public static method

Deprecation:
public static parseServices ( ContainerBuilder $builder, array $config, $namespace = NULL )
$builder ContainerBuilder
$config array
Ejemplo n.º 1
0
 public function load(Nette\DI\Compiler $compiler, Nette\DI\ContainerBuilder $containerBuilder)
 {
     $aspects = [];
     foreach ($this->aspectsList as $def) {
         if (!is_array($def)) {
             if (!is_string($def) && (!$def instanceof \stdClass || empty($def->value)) && !$def instanceof Nette\DI\Statement) {
                 $serialised = Nette\Utils\Json::encode($def);
                 throw new Kdyby\Aop\UnexpectedValueException("The service definition {$serialised} is expected to be an array or Neon entity.");
             }
             $def = ['factory' => $def];
         }
         $def['tags'][] = AspectsExtension::ASPECT_TAG;
         $aspects[] = $def;
     }
     $compiler->parseServices($containerBuilder, ['services' => $aspects], $this->prefix ? substr($this->extension->prefix('self'), 0, -5) : NULL);
 }
Ejemplo n.º 2
0
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->validateConfig($this->defaults);
     // Add themes
     $params = [];
     $neon = new NeonAdapter();
     foreach (Finder::findFiles('theme.neon')->limitDepth(2)->from($config['themes']) as $file => $splfile) {
         // Parse config
         $expandConfig = ['themeDir' => dirname($splfile->getRealPath())];
         $themeConfig = Helpers::expand($neon->load($file), $expandConfig, TRUE);
         // Validate theme configs
         $this->validateConfig($this->themeDefaults, $themeConfig, 'themes');
         $this->validateConfig($this->themeDefaults['theme'], $themeConfig['theme'], 'theme');
         // Parse theme name
         $themeName = strtolower($themeConfig['theme']['name']);
         // Check duplicity
         if (array_key_exists($themeName, $params)) {
             throw new InvalidStateException('Theme "' . $themeName . '" is already defined.');
         }
         // Add to array
         $params[$themeName] = $themeConfig;
     }
     // Check if selected template is not null
     Validators::assertField($params, $config['theme'], NULL, 'template "%s"');
     $theme = $params[$config['theme']];
     // Add parameters to global parameters
     $builder->parameters['themes'] = [];
     $builder->parameters['themes']['theme'] = $theme['theme'];
     $builder->parameters['themes']['vars'] = $config['template'];
     $builder->parameters['themes']['output'] = $config['output'];
     // Add template model to container
     Compiler::parseServices($builder, ['services' => $theme['model']], $this->prefix('model'));
     // Add command manager (fake presenter)
     $builder->addDefinition($this->prefix('ui.manager'))->setClass('Generator\\UI\\CommandManager');
     // Add template factory
     $builder->addDefinition($this->prefix('latte.templateFactory'))->setClass('Generator\\Latte\\TemplateFactory')->setAutowired();
     // Add commands
     $builder->addDefinition($this->prefix('commands.info'))->setClass('Generator\\Commands\\InfoCommand')->setInject();
     $builder->addDefinition($this->prefix('commands.generate'))->setClass('Generator\\Commands\\GenerateCommand', [$builder->parameters['themes']])->setInject();
     $builder->addDefinition($this->prefix('commands.deploy'))->setClass('Generator\\Commands\\DeployCommand')->setInject();
     $builder->addDefinition($this->prefix('commands.error'))->setClass('Generator\\Commands\\ErrorCommand')->setInject();
 }