当前位置: 首页>>代码示例>>PHP>>正文


PHP ContainerBuilder::addDefinitions方法代码示例

本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::addDefinitions方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::addDefinitions方法的具体用法?PHP ContainerBuilder::addDefinitions怎么用?PHP ContainerBuilder::addDefinitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\DependencyInjection\ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder::addDefinitions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: realpath

 /**
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  * @param \Doctrine\Common\Annotations\AnnotationReader $annotationReader
  * @param \FSi\Bundle\AdminBundle\Finder\AdminClassFinder $adminClassFinder
  */
 function it_registers_annotated_admin_classes_as_services($container, $annotationReader, $adminClassFinder)
 {
     $container->getParameter('kernel.bundles')->willReturn(array('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\MyBundle', 'FSi\\Bundle\\AdminBundle\\FSiAdminBundle', 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'));
     $baseDir = __DIR__ . '/../../../../../..';
     $adminClassFinder->findClasses(array(realpath($baseDir . '/spec/fixtures/Admin'), realpath($baseDir . '/Admin')))->willReturn(array('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\CRUDElement'));
     $annotationReader->getClassAnnotation(Argument::allOf(Argument::type('ReflectionClass'), Argument::which('getName', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\CRUDElement')), 'FSi\\Bundle\\AdminBundle\\Annotation\\Element')->willReturn(null);
     $annotationReader->getClassAnnotation(Argument::allOf(Argument::type('ReflectionClass'), Argument::which('getName', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement')), 'FSi\\Bundle\\AdminBundle\\Annotation\\Element')->willReturn(new Element(array()));
     $container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'), Argument::which('getResource', realpath($baseDir . '/spec/fixtures/Admin')), Argument::which('getPattern', '/\\.php$/')))->shouldBeCalled();
     $container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'), Argument::which('getResource', realpath($baseDir . '/Admin')), Argument::which('getPattern', '/\\.php$/')))->shouldBeCalled();
     $container->addDefinitions(Argument::that(function ($definitions) {
         if (count($definitions) !== 1) {
             return false;
         }
         /** @var \Symfony\Component\DependencyInjection\Definition $definition */
         $definition = $definitions[0];
         if ($definition->getClass() !== 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement') {
             return false;
         }
         if (!$definition->hasTag('admin.element')) {
             return false;
         }
         return true;
     }))->shouldBeCalled();
     $this->process($container);
 }
开发者ID:kbedn,项目名称:admin-bundle,代码行数:30,代码来源:AdminAnnotatedElementPassSpec.php

示例2: process

 public function process(ContainerBuilder $container)
 {
     // Cache warmer does more harm than good with Drupal.
     if ($container->hasDefinition('cache_warmer')) {
         $container->removeDefinition('cache_warmer');
     }
     if ($container->hasAlias('cache_warmer')) {
         $container->removeAlias('cache_warmer');
     }
     // When not working with symfony, we need to provide a file locator
     // service of our own instead of the symfony's one
     if (!$container->hasDefinition('file_locator') && !$container->hasAlias('file_locator')) {
         $container->addDefinitions(['file_locator' => (new Definition())->setClass(CustomFileLocator::class)->addArgument(new Reference('kernel'))]);
     } else {
         // We are working with fullstack, and our users might have changed
         // the global resource directory to somewhere safer than Drupal's
         // sites/SITE folder, case in which we must honnor the user's
         // configuration
         $definition = $container->getDefinition('file_locator');
         $definition->setArguments([new Reference('kernel'), $container->getParameter('kernel.root_dir') . '/Resources']);
     }
     // By registering the framework bundle, we also inherit from Symfony
     // default URL generator, which will cause us great pain because of
     // Drupal routes will not be known by the framework and throw a few
     // exceptions.
     if ($container->has('router.default')) {
         $container->getDefinition('router.default')->setClass('MakinaCorpus\\Drupal\\Sf\\Routing\\Router');
     }
     // When NOT in fullstack mode, we need to provide a null implementation
     // for the controller resolver service, else the container will be
     // unable to spawn the http kernel service
     if (!$container->has('controller_resolver')) {
         $container->addDefinitions(['controller_resolver' => (new Definition())->setClass('controller_resolver')]);
     }
 }
开发者ID:makinacorpus,项目名称:drupal-sf-dic,代码行数:35,代码来源:FrameworkBundleIntegrationPass.php

示例3: load

 /**
  * @param  array            $configs
  * @param  ContainerBuilder $container
  * @return void
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $config = $this->processConfiguration(new Configuration(), $configs);
     $container->addDefinitions(array('rabbitmq.connection' => $this->getConnectionService($config), 'rabbitmq.channel' => $this->getChannelService(), 'rabbitmq.manager' => $this->getManagerService($config)));
     $container->addDefinitions($this->getExchangeServices($config['exchanges']));
     $container->addDefinitions($this->getQueueServices($config['queues']));
     $container->addDefinitions($this->getConsumerServices($config['consumers']));
     $container->addDefinitions($this->getProducerServices($config['producers']));
 }
开发者ID:bcncommerce,项目名称:rabbitmq-extension,代码行数:14,代码来源:RabbitMqExtension.php

示例4: notify

 public function notify(\Exception $exception)
 {
     if (!$exception instanceof ServiceNotFoundException) {
         return;
     }
     $serviceId = $exception->getId();
     $guessedFqcn = $this->guessFqcn($serviceId);
     $definition = new Definition();
     $definition->setClass($guessedFqcn);
     $containerBuilder = new ContainerBuilder();
     $containerBuilder->addDefinitions([$serviceId => $definition]);
     $dumper = new YamlDumper($containerBuilder);
     $result = $dumper->dump();
     $message = sprintf('Service `%s` missing. Define it in your services.yml:', $serviceId);
     $this->output->writeln('--- ' . $message . PHP_EOL);
     $this->output->write($result, true);
     $errorMessages = ['Service ' . $serviceId . ' was not found.'];
     $formatter = new FormatterHelper();
     $formattedBlock = $formatter->formatBlock($errorMessages, 'error', true);
     $this->output->writeln('');
     $this->output->writeln($formattedBlock);
     $this->output->writeln('');
     $question = sprintf('<question>Do you want to create a specification for %s? (Y/n)</question>', $guessedFqcn);
     $dialog = new DialogHelper();
     if ($dialog->askConfirmation($this->output, $question, true)) {
         $this->specRunner->runDescCommand($guessedFqcn);
     }
 }
开发者ID:kix,项目名称:behat-sf2-service-generator,代码行数:28,代码来源:NonExistentServiceObserver.php

示例5: testDefinitions

    /**
     * @covers Symfony\Component\DependencyInjection\ContainerBuilder::setDefinitions
     * @covers Symfony\Component\DependencyInjection\ContainerBuilder::getDefinitions
     * @covers Symfony\Component\DependencyInjection\ContainerBuilder::setDefinition
     * @covers Symfony\Component\DependencyInjection\ContainerBuilder::getDefinition
     */
    public function testDefinitions()
    {
        $builder = new ContainerBuilder();
        $definitions = array(
            'foo' => new Definition('FooClass'),
            'bar' => new Definition('BarClass'),
        );
        $builder->setDefinitions($definitions);
        $this->assertEquals($definitions, $builder->getDefinitions(), '->setDefinitions() sets the service definitions');
        $this->assertTrue($builder->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
        $this->assertFalse($builder->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');

        $builder->setDefinition('foobar', $foo = new Definition('FooBarClass'));
        $this->assertEquals($foo, $builder->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
        $this->assertTrue($builder->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fluid interface by returning the service reference');

        $builder->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
        $this->assertEquals(array_merge($definitions, $defs), $builder->getDefinitions(), '->addDefinitions() adds the service definitions');

        try {
            $builder->getDefinition('baz');
            $this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
        } catch (\InvalidArgumentException $e) {
            $this->assertEquals('The service definition "baz" does not exist.', $e->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
        }
    }
开发者ID:nacef,项目名称:symfony,代码行数:32,代码来源:ContainerBuilderTest.php

示例6: load

 public function load(array $configs, ContainerBuilder $container)
 {
     $configuration = new Configuration();
     $config = $this->processConfiguration($configuration, $configs);
     foreach ($config as $key => $value) {
         $container->setParameter('migrations' . '.' . $key, $value);
     }
     $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('services.yml');
     $service = $container->getDefinition('migrations.migrator');
     $migrationServices = [];
     foreach (new \DirectoryIterator($config['dir_name']) as $item) {
         if (!$item->isFile()) {
             continue;
         }
         $className = basename($item->getFilename(), '.php');
         $migrationDefinition = new Definition($config['namespace'] . '\\' . $className);
         $migrationDefinition->setPublic(false);
         $migrationServices['migrations.migrations.' . strtolower($className)] = $migrationDefinition;
     }
     $container->addDefinitions($migrationServices);
     foreach (array_keys($migrationServices) as $id) {
         $service->addMethodCall('addMigration', [new Reference($id)]);
     }
 }
开发者ID:mosch,项目名称:php-migration-bundle,代码行数:25,代码来源:MigrationExtension.php

示例7: testProcess

 public function testProcess()
 {
     $container = new ContainerBuilder();
     $simpleFactory = new Definition();
     $simpleProcessor = new Definition('Test\\SimpleProcessor');
     $simpleProcessor->addTag('processor');
     $abstractProcessor = new Definition();
     $abstractProcessor->setAbstract(true);
     $abstractProcessor->addTag('processor');
     $lazyProcessor = new Definition('Test\\LazyProcessor');
     $lazyProcessor->setLazy(true);
     $lazyProcessor->addTag('processor');
     $withArgumentsProcessor = new Definition('Test\\WithArgumentsProcessor', ['test']);
     $withArgumentsProcessor->addTag('processor');
     $container->addDefinitions(['simple_factory' => $simpleFactory, 'simple_processor' => $simpleProcessor, 'abstract_processor' => $abstractProcessor, 'lazy_processor' => $lazyProcessor, 'with_arguments_processor' => $withArgumentsProcessor]);
     $compilerPass = new CleanUpProcessorsCompilerPass('simple_factory', 'processor');
     $compilerPass->process($container);
     $this->assertFalse($container->hasDefinition('simple_processor'));
     $this->assertTrue($container->hasDefinition('abstract_processor'));
     $this->assertTrue($container->hasDefinition('lazy_processor'));
     $this->assertTrue($container->hasDefinition('with_arguments_processor'));
     $methodCalls = $simpleFactory->getMethodCalls();
     $this->assertCount(1, $methodCalls);
     $this->assertEquals(['addProcessor', ['simple_processor', 'Test\\SimpleProcessor']], $methodCalls[0]);
 }
开发者ID:ramunasd,项目名称:platform,代码行数:25,代码来源:CleanUpProcessorsCompilerPassTest.php

示例8: process

 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $config = $container->getParameter(ModeraMjrIntegrationExtension::CONFIG_KEY);
     $def = new Definition(ConfigMenuItemsProvider::clazz(), array($config));
     $def->addTag('modera_mjr_integration.menu.menu_items_provider');
     $container->addDefinitions(array('modera_mjr_integration.contributions.menu_items_provider' => $def));
 }
开发者ID:modera,项目名称:foundation,代码行数:10,代码来源:MenuItemContributorCompilerPass.php

示例9: process

 public function process(ContainerBuilder $container)
 {
     if (!$container->hasDefinition('fm_bbcode.decoda_manager')) {
         return;
     }
     $filters = $container->getParameter('fm_bbcode.config.filters');
     $definitions = array();
     foreach ($filters as $id => $class) {
         $definition = new Definition($class);
         $definition->addTag('fm_bbcode.decoda.filter', array('id' => $id));
         $definitions['fm_bbcode.decoda.filter.from_config.' . $id] = $definition;
     }
     $container->addDefinitions($definitions);
     $definition = $container->getDefinition('fm_bbcode.decoda_manager');
     $filters = array();
     foreach ($container->findTaggedServiceIds('fm_bbcode.decoda.filter') as $id => $attributes) {
         // We must assume that the class value has been correctly filled, even if the service is created by a factory
         $class = $container->getDefinition($id)->getClass();
         $refClass = new \ReflectionClass($class);
         $interface = 'Decoda\\Filter';
         if (!$refClass->implementsInterface($interface)) {
             throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
         }
         $name = isset($attributes[0]['id']) ? $attributes[0]['id'] : $id;
         $name = strtolower($name);
         if (isset($filters[$name])) {
             throw new \InvalidArgumentException(sprintf('The hook identifier "%s" must be uniq, is already set on "%s" service.', $name, $filters[$name]));
         }
         $filters[$name] = $id;
         $definition->addMethodCall('setFilter', array($name, new Reference($id)));
     }
 }
开发者ID:gkawka,项目名称:FMBbCodeBundle,代码行数:32,代码来源:RegisterFiltersPass.php

示例10: process

 /**
  * @inheritdoc
  */
 public function process(ContainerBuilder $container)
 {
     $definitions = array();
     $servicesIds = $container->findTaggedServiceIds('pmd_state_machine.token_configurable');
     foreach ($servicesIds as $serviceId => $tag) {
         $group = isset($tag[0]['group']) ? $tag[0]['group'] : null;
         $type = isset($tag[0]['type']) ? $tag[0]['type'] : null;
         if (!isset($group) || !isset($type)) {
             throw new \InvalidArgumentException(sprintf('Services tagged %s must have group and type defined', 'pmd_state_machine.token_configurable'));
         }
         $serviceDefinition = $container->getDefinition($serviceId);
         $optionsId = sprintf('pmd_state_machine.behavior.%s_%s_options', $group, $type);
         $optionsReference = new Reference($optionsId, ContainerInterface::NULL_ON_INVALID_REFERENCE);
         // Configure options resolver
         $resolverId = sprintf('pmd_state_machine.behavior.%s_%s_resolver', $group, $type);
         $resolverReference = new Reference($resolverId);
         $resolverDefinition = new DefinitionDecorator('pmd_state_machine.behavior_resolver.token_options_resolver');
         $resolverDefinition->replaceArgument(0, $optionsReference);
         // Configure configurable decorator
         $configId = sprintf('pmd_state_machine.behavior.%s_%s_configurator', $group, $type);
         $configDefinition = new DefinitionDecorator('pmd_state_machine.behavior.token_configurable_configurator');
         $configDefinition->replaceArgument(0, $resolverReference);
         $serviceDefinition->setConfigurator(array(new Reference($configId, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false), 'configure'));
         $definitions[$resolverId] = $resolverDefinition;
         $definitions[$configId] = $configDefinition;
     }
     $container->addDefinitions($definitions);
 }
开发者ID:piotrminkina,项目名称:pmd,代码行数:31,代码来源:TokenConfigurablePass.php

示例11: testProviderIsAdded

 public function testProviderIsAdded()
 {
     $targetService = new Definition();
     $targetService->setClass('Faker\\Generator');
     $provider = $this->getMock('Acme\\Faker\\Provider\\CustomFakeDataProvider');
     $providerService = new Definition();
     $providerService->setClass(get_class($provider));
     $providerService->addTag('bazinga_faker.provider');
     $builder = new ContainerBuilder();
     $builder->addDefinitions(array('faker.generator' => $targetService, 'acme.faker.provider.custom' => $providerService));
     $builder->addCompilerPass(new AddProvidersPass());
     $builder->compile();
     $this->assertNotEmpty($builder->getServiceIds(), 'The services have been injected.');
     $this->assertNotEmpty($builder->get('faker.generator'), 'The faker.generator service has been injected.');
     $this->assertNotEmpty($builder->get('acme.faker.provider.custom'), 'The provider service has been injected.');
     /*
      * Schema:
      *
      * [0] The list of methods.
      *   [0] The name of the method to call.
      *   [1] The arguments to pass into the method call.
      *     [0] First argument to pass into the method call.
      *     ...
      */
     $targetMethodCalls = $builder->getDefinition('faker.generator')->getMethodCalls();
     $this->assertNotEmpty($targetMethodCalls, 'The faker.generator service got method calls added.');
     $this->assertEquals('addProvider', $targetMethodCalls[0][0], 'The faker.generator service got a provider added.');
     $this->assertEquals('acme.faker.provider.custom', $targetMethodCalls[0][1][0], 'The faker.generator service got the correct provider added.');
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:29,代码来源:AddProvidersPassTest.php

示例12: process

 /**
  * You can modify the container here before it is dumped to PHP code.
  *
  * @param ContainerBuilder $container
  *
  * @api
  */
 public function process(ContainerBuilder $container)
 {
     if ($container->has('thelia.parser')) {
         return;
     }
     $container->addDefinitions(['thelia.parser' => new Definition("Thelia\\Core\\Template\\Parser\\ParserFallback"), 'thelia.parser.helper' => new Definition("Thelia\\Core\\Template\\Parser\\ParserHelperFallback"), 'thelia.parser.asset.resolver' => new Definition("Thelia\\Core\\Template\\Parser\\ParserHelperFallback")]);
 }
开发者ID:NandoKstroNet,项目名称:thelia,代码行数:14,代码来源:FallbackParserPass.php

示例13: createModelEvents

 private function createModelEvents(array $models, ContainerBuilder $container)
 {
     $definitions = [];
     foreach ($models as $modelName => $class) {
         $definitions[] = $this->createDefinition($modelName);
     }
     $container->addDefinitions($definitions);
 }
开发者ID:symedit,项目名称:symedit,代码行数:8,代码来源:SymEditAnalyticsExtension.php

示例14: load

 /**
  * {@inheritdoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $configuration = new Configuration();
     $config = $this->processConfiguration($configuration, $configs);
     $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('services.yml');
     $container->addDefinitions(array('seven_onesky_client' => $this->getClientDefinition($config), 'seven_onesky_downloader' => $this->getDownloaderDefinition($config)));
 }
开发者ID:skolodyazhnyy,项目名称:onesky-bundle,代码行数:11,代码来源:SevenOneskyExtension.php

示例15: configureContainer

 protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
 {
     $parser = new \Symfony\Component\Yaml\Parser();
     $parametersFile = file_get_contents($this->getRootDir() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'parameters.yml');
     $parameters = $parser->parse($parametersFile);
     $c->loadFromExtension('framework', ['secret' => 'none']);
     $c->addDefinitions(['git_automation.jira_api' => $this->createJiraApiService($parameters['parameters'])]);
 }
开发者ID:coyl,项目名称:git-automation,代码行数:8,代码来源:AppKernel.php


注:本文中的Symfony\Component\DependencyInjection\ContainerBuilder::addDefinitions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。