PHP symfony\component\dependencyinjection ContainerBuilder Examples

PHP symfony\component\dependencyinjection ContainerBuilder - 30 examples found. These are the top rated real world PHP examples of symfony\component\dependencyinjection\ContainerBuilder extracted from open source projects. You can rate examples to help us improve the quality of examples.
Author: Fabien Potencier (fabien@symfony.com)
Inheritance: extends Symfony\Component\DependencyInjection\Container, implements Symfony\Component\DependencyInjection\TaggedContainerInterface
Example #1
0
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $definition = $container->getDefinition('twig');
     foreach ($container->findTaggedServiceIds('twig.token_parser') as $id => $attributes) {
         $definition->addMethodCall('addTokenParser', [new Reference($id)]);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function build(ContainerBuilder $container)
 {
     /** @var  PayumExtension $payumExtension */
     $payumExtension = $container->getExtension('payum');
     $payumExtension->addGatewayFactory(new JmsGatewayFactory());
     $payumExtension->addGatewayFactory(new FooBarGatewayPaymentFactory());
 }
 /**
  * @param string                                                    $name
  * @param array                                                     $config
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder   $container
  *
  * @return \Symfony\Component\DependencyInjection\Reference
  */
 private function getConnectionReference($name, array $config, ContainerBuilder $container)
 {
     if (isset($config['connection_id'])) {
         return new Reference($config['connection_id']);
     }
     $host = $config['host'];
     $port = $config['port'];
     $connClass = '%doctrine_cache.redis.connection.class%';
     $connId = sprintf('doctrine_cache.services.%s_redis.connection', $name);
     $connDef = new Definition($connClass);
     $connParams = array($host, $port);
     if (isset($config['timeout'])) {
         $connParams[] = $config['timeout'];
     }
     $connDef->setPublic(false);
     $connDef->addMethodCall('connect', $connParams);
     if (isset($config['password'])) {
         $password = $config['password'];
         $connDef->addMethodCall('auth', array($password));
     }
     if (isset($config['database'])) {
         $database = (int) $config['database'];
         $connDef->addMethodCall('select', array($database));
     }
     $container->setDefinition($connId, $connDef);
     return new Reference($connId);
 }
 /**
  * Allow an extension to prepend the extension configurations.
  *
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  */
 public function prepend(ContainerBuilder $container)
 {
     $configFile = __DIR__ . '/../Resources/config/templates.yml';
     $config = Yaml::parse(file_get_contents($configFile));
     $container->prependExtensionConfig('ezpublish', $config);
     $container->addResource(new FileResource($configFile));
 }
 /**
  * Processes the ContainerBuilder to resolve parameter placeholders.
  *
  * @param ContainerBuilder $container
  *
  * @throws ParameterNotFoundException
  */
 public function process(ContainerBuilder $container)
 {
     $parameterBag = $container->getParameterBag();
     foreach ($container->getDefinitions() as $id => $definition) {
         try {
             $definition->setClass($parameterBag->resolveValue($definition->getClass()));
             $definition->setFile($parameterBag->resolveValue($definition->getFile()));
             $definition->setArguments($parameterBag->resolveValue($definition->getArguments()));
             if ($definition->getFactoryClass(false)) {
                 $definition->setFactoryClass($parameterBag->resolveValue($definition->getFactoryClass(false)));
             }
             $factory = $definition->getFactory();
             if (is_array($factory) && isset($factory[0])) {
                 $factory[0] = $parameterBag->resolveValue($factory[0]);
                 $definition->setFactory($factory);
             }
             $calls = array();
             foreach ($definition->getMethodCalls() as $name => $arguments) {
                 $calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments);
             }
             $definition->setMethodCalls($calls);
             $definition->setProperties($parameterBag->resolveValue($definition->getProperties()));
         } catch (ParameterNotFoundException $e) {
             $e->setSourceId($id);
             throw $e;
         }
     }
     $aliases = array();
     foreach ($container->getAliases() as $name => $target) {
         $aliases[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($target);
     }
     $container->setAliases($aliases);
     $parameterBag->resolve();
 }
Example #6
0
 /** {@inheritdoc} */
 public function build(ContainerBuilder $container)
 {
     if ($container instanceof ExtendedContainerBuilder) {
         $container->addCompilerPass(new ListenerExcludeSearchConnectionPass());
         $container->moveCompilerPassBefore('Oro\\Bundle\\SearchBundle\\DependencyInjection\\Compiler\\ListenerExcludeSearchConnectionPass', 'Oro\\Bundle\\PlatformBundle\\DependencyInjection\\Compiler\\UpdateDoctrineEventHandlersPass');
     }
 }
 public function process(ContainerBuilder $container)
 {
     // only replace the default router by overwriting the 'router' alias if config tells us to
     if ($container->hasParameter('cmf_routing.replace_symfony_router') && true === $container->getParameter('cmf_routing.replace_symfony_router')) {
         $container->setAlias('router', 'cmf_routing.router');
     }
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function prepend(ContainerBuilder $container)
 {
     if (!$container->hasExtension('sylius_order')) {
         throw new \RuntimeException('Please install and configure SyliusOrderBundle in order to use SyliusCartBundle.');
     }
     $container->prependExtensionConfig('sylius_order', array('resources' => array('order' => array('classes' => array('model' => Cart::class)), 'order_item' => array('classes' => array('model' => CartItem::class)))));
 }
 /**
  * Processes the ContainerBuilder to validate References.
  *
  * @param ContainerBuilder $container
  */
 public function process(ContainerBuilder $container)
 {
     $this->container = $container;
     $children = $this->container->getScopeChildren();
     $ancestors = array();
     $scopes = $this->container->getScopes();
     foreach ($scopes as $name => $parent) {
         $ancestors[$name] = array($parent);
         while (isset($scopes[$parent])) {
             $ancestors[$name][] = $parent = $scopes[$parent];
         }
     }
     foreach ($container->getDefinitions() as $id => $definition) {
         if ($definition->isSynthetic() || $definition->isAbstract()) {
             continue;
         }
         $this->currentId = $id;
         $this->currentDefinition = $definition;
         $this->currentScope = $scope = $definition->getScope();
         if (ContainerInterface::SCOPE_CONTAINER === $scope) {
             $this->currentScopeChildren = array_keys($scopes);
             $this->currentScopeAncestors = array();
         } elseif (ContainerInterface::SCOPE_PROTOTYPE !== $scope) {
             $this->currentScopeChildren = isset($children[$scope]) ? $children[$scope] : array();
             $this->currentScopeAncestors = isset($ancestors[$scope]) ? $ancestors[$scope] : array();
         }
         $this->validateReferences($definition->getArguments());
         $this->validateReferences($definition->getMethodCalls());
         $this->validateReferences($definition->getProperties());
     }
 }
 public function setParameterSection(ContainerBuilder $container, $page, array $captchaConfig)
 {
     $container->setParameter('captcha.config.' . $page, $captchaConfig);
     $container->setParameter('captcha.config.' . $page . '.captcha_id', $captchaConfig['captcha_id']);
     $container->setParameter('captcha.config.' . $page . '.user_input_id', $captchaConfig['user_input_id']);
     $container->setParameter('captcha.config.' . $page . '.captcha_config_file_path', $captchaConfig['captcha_config_file_path']);
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $coordinator = $container->getDefinition('sylius.process.coordinator');
     foreach ($container->findTaggedServiceIds('sylius.process.scenario') as $id => $attributes) {
         $coordinator->addMethodCall('registerScenario', array($attributes[0]['alias'], new Reference($id)));
     }
 }
Example #12
0
 /**
  * Configuration extension loader
  *
  * @param array            $configs   An array of configuration settings
  * @param ContainerBuilder $container A container builder instance
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $config = $this->processConfiguration(new Configuration(), $configs);
     $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('services.xml');
     $container->setParameter('eko_feed.config', $config);
 }
 /**
  * @param ContainerBuilder $container
  * @param string $serviceName
  * @param string $newServiceName
  */
 private function changeService(ContainerBuilder $container, $serviceName, $newServiceName)
 {
     $service = $container->getDefinition($serviceName);
     $newService = $container->getDefinition($newServiceName);
     $container->removeDefinition($serviceName);
     $container->setDefinition($serviceName, $newService);
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $container->getDefinition('sensio_framework_extra.routing.loader.annot_class')->addMethodCall('setSiteContext', array(new Reference('site_context')));
     $container->getDefinition('router.default')->setClass('Alex\\MultisiteBundle\\Router\\MultisiteRouter');
     $container->getDefinition('router.default')->addMethodCall('setSiteContext', array(new Reference('site_context')));
     $container->getDefinition('router.default')->addMethodCall('setSortRoutes', array("%alex_multisite.sort_routes%"));
 }
 private function isIntegrationEnabled(ContainerBuilder $container)
 {
     if (!$container->hasParameter('riemann.integration.monolog')) {
         return false;
     }
     return true === $container->getParameter('riemann.integration.monolog');
 }
 /**
  * {@inheritDoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $configuration = new Configuration();
     $config = $this->processConfiguration($configuration, $configs);
     $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('services.xml');
     if (isset($config['handler_path'])) {
         $container->setParameter('shibboleth.handler_path', $config['handler_path']);
     }
     if (isset($config['secured_handler'])) {
         $container->setParameter('shibboleth.secured_handler', $config['secured_handler']);
     }
     if (isset($config['session_initiator_path'])) {
         $container->setParameter('shibboleth.session_initiator_path', $config['session_initiator_path']);
     }
     if (isset($config['username_attribute'])) {
         $container->setParameter('shibboleth.username_attribute', $config['username_attribute']);
     }
     if (isset($config['attribute_definitions'])) {
         $container->setParameter('shibboleth.attribute_definitions', $config['attribute_definitions']);
     } else {
         $container->setParameter('shibboleth.attribute_definitions', array());
     }
     if (isset($config['use_headers'])) {
         $container->setParameter('shibboleth.use_headers', $config['use_headers']);
     } else {
         $container->setParameter('shibboleth.use_headers', true);
     }
     if (isset($config['logout_target'])) {
         $container->setParameter('shibboleth.logout_target', $config['logout_target']);
     }
 }
 /**
  * @inheritDoc
  */
 public function process(ContainerBuilder $container)
 {
     $executorId = 'thruster_doctrine_actions.doctrine_persist_action.executor';
     $executorDefinition = new Definition('Thruster\\Bundle\\DoctrineActionsBundle\\DoctrinePersistActionExecutor', [new Reference('doctrine')]);
     $executorDefinition->addTag('thruster_action_executor', []);
     $container->setDefinition($executorId, $executorDefinition);
 }
 public function testProcess()
 {
     $container = new ContainerBuilder();
     $container->register('a')->addArgument(new Reference('b'));
     $container->register('b');
     $this->process($container);
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     foreach ($container->findTaggedServiceIds('vlr.model.violation.handler') as $id => $tags) {
         $priority = isset($tags[0]) && isset($tags[0]['priority']) ? $tags[0]['priority'] : null;
         $container->getDefinition('rezzza.violation.handler.manager')->addMethodCall('add', array($container->getDefinition($id), $priority));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function build(ContainerBuilder $container)
 {
     $interfaces = $this->getModelInterfaces();
     if (!empty($interfaces)) {
         $container->addCompilerPass(new ResolveDoctrineTargetEntitiesPass($this->getBundlePrefix(), $interfaces));
     }
     if (null !== $this->getModelNamespace()) {
         $className = get_class($this);
         foreach ($className::getSupportedDrivers() as $driver) {
             list($compilerPassClassName, $compilerPassMethod) = $this->getMappingCompilerPassInfo($driver);
             if (class_exists($compilerPassClassName)) {
                 if (!method_exists($compilerPassClassName, $compilerPassMethod)) {
                     throw new InvalidConfigurationException("The 'mappingFormat' value is invalid, must be 'xml', 'yml' or 'annotation'.");
                 }
                 switch ($this->mappingFormat) {
                     case ResourceBundleInterface::MAPPING_XML:
                     case ResourceBundleInterface::MAPPING_YAML:
                         $container->addCompilerPass($compilerPassClassName::$compilerPassMethod(array($this->getConfigFilesPath() => $this->getModelNamespace()), array(sprintf('%s.object_manager', $this->getBundlePrefix())), sprintf('%s.driver.%s', $this->getBundlePrefix(), $driver)));
                         break;
                     case ResourceBundleInterface::MAPPING_ANNOTATION:
                         $container->addCompilerPass($compilerPassClassName::$compilerPassMethod(array($this->getModelNamespace()), array($this->getConfigFilesPath()), array(sprintf('%s.object_manager', $this->getBundlePrefix())), sprintf('%s.driver.%s', $this->getBundlePrefix(), $driver)));
                         break;
                 }
             }
         }
     }
 }
 /**
  * @param ContainerBuilder $container
  * @param array            $config
  * @param string           $id
  * @param string           $rememberMeServicesId
  *
  * @return array
  */
 protected function getUserProviders(ContainerBuilder $container, $config, $id, $rememberMeServicesId)
 {
     $userProviders = [];
     foreach ($container->findTaggedServiceIds('security.remember_me_aware') as $serviceId => $attributes) {
         foreach ($attributes as $attribute) {
             if (!isset($attribute['id']) || $attribute['id'] !== $id) {
                 continue;
             }
             if (!isset($attribute['provider'])) {
                 throw new \RuntimeException('Each "security.remember_me_aware" tag must have a provider attribute.');
             }
             $userProviders[] = new Reference($attribute['provider']);
             $container->getDefinition($serviceId)->addMethodCall('setRememberMeServices', array(new Reference($rememberMeServicesId)));
         }
     }
     if ($config['user_providers']) {
         $userProviders = array();
         foreach ($config['user_providers'] as $providerName) {
             $userProviders[] = new Reference('security.user.provider.concrete.' . $providerName);
         }
     }
     if (count($userProviders) === 0) {
         throw new \RuntimeException('You must configure at least one remember-me aware listener (such as form-login)
             for each firewall that has organization-remember-me enabled.');
     }
     return $userProviders;
 }
 /**
  * Creates and registers compiler passes for PHPCR-ODM mapping if both the
  * phpcr-odm and the phpcr-bundle are present.
  *
  * @param ContainerBuilder $container
  */
 private function buildPhpcrCompilerPass(ContainerBuilder $container)
 {
     if (!class_exists('Doctrine\\Bundle\\PHPCRBundle\\DependencyInjection\\Compiler\\DoctrinePhpcrMappingsPass') || !class_exists('Doctrine\\ODM\\PHPCR\\Version')) {
         return;
     }
     $container->addCompilerPass(DoctrinePhpcrMappingsPass::createXmlMappingDriver(array(realpath(__DIR__ . '/Resources/config/doctrine-model') => 'Symfony\\Cmf\\Bundle\\RoutingAutoBundle\\Model'), array('cmf_routing_auto.persistence.phpcr.manager_name'), false, array('CmfRoutingAutoBundle' => 'Symfony\\Cmf\\Bundle\\RoutingAutoBundle\\Model')));
 }
 /**
  * @param ContainerBuilder $container
  * @param string           $code
  * @param Definition       $formatter
  * @param array            $extensions
  *
  * @return string
  */
 public function createEnvironment(ContainerBuilder $container, $code, Definition $formatter, array $extensions)
 {
     $loader = new Definition('Twig_Loader_String');
     $loader->setPublic(false);
     $container->setDefinition(sprintf('sonata.formatter.twig.loader.%s', $code), $loader);
     $loaderSelector = new Definition('Sonata\\FormatterBundle\\Twig\\Loader\\LoaderSelector', array(new Reference(sprintf('sonata.formatter.twig.loader.%s', $code)), new Reference('twig.loader')));
     $loaderSelector->setPublic(false);
     $env = new Definition('Twig_Environment', array($loaderSelector, array('debug' => false, 'strict_variables' => false, 'charset' => 'UTF-8')));
     $env->setPublic(false);
     $container->setDefinition(sprintf('sonata.formatter.twig.env.%s', $code), $env);
     $sandboxPolicy = new Definition('Sonata\\FormatterBundle\\Twig\\SecurityPolicyContainerAware', array(new Reference('service_container'), $extensions));
     $sandboxPolicy->setPublic(false);
     $container->setDefinition(sprintf('sonata.formatter.twig.sandbox.%s.policy', $code), $sandboxPolicy);
     $sandbox = new Definition('Twig_Extension_Sandbox', array($sandboxPolicy, true));
     $sandbox->setPublic(false);
     $container->setDefinition(sprintf('sonata.formatter.twig.sandbox.%s', $code), $sandbox);
     $env->addMethodCall('addExtension', array(new Reference(sprintf('sonata.formatter.twig.sandbox.%s', $code))));
     foreach ($extensions as $extension) {
         $env->addMethodCall('addExtension', array(new Reference($extension)));
     }
     $lexer = new Definition('Twig_Lexer', array(new Reference(sprintf('sonata.formatter.twig.env.%s', $code)), array('tag_comment' => array('<#', '#>'), 'tag_block' => array('<%', '%>'), 'tag_variable' => array('<%=', '%>'))));
     $lexer->setPublic(false);
     $container->setDefinition(new Reference(sprintf('sonata.formatter.twig.lexer.%s', $code)), $lexer);
     $env->addMethodCall('setLexer', array(new Reference(sprintf('sonata.formatter.twig.lexer.%s', $code))));
     return sprintf('sonata.formatter.twig.env.%s', $code);
 }
 public function process(ContainerBuilder $container)
 {
     $translationFile = __DIR__ . '/../../Resources/translations/bar.en.yml';
     $translator = $container->findDefinition('translator.default');
     list($domain, $locale, $format) = explode('.', $translationFile, 3);
     $translator->addMethodCall('addResource', array($format, $translationFile, $locale, $domain));
 }
Example #25
0
 public static function getContainerBuilders()
 {
     $builder1 = new ContainerBuilder();
     $builder1->setDefinitions(self::getContainerDefinitions());
     $builder1->setAliases(self::getContainerAliases());
     return array('builder_1' => $builder1);
 }
Example #26
0
 public function load(array $configs, ContainerBuilder $container)
 {
     $configuration = new Configuration();
     $appConfig = $this->processConfiguration($configuration, $configs);
     $dashboardDefinition = $container->register('app.dashboard', 'AppBundle\\Dashboard\\Dashboard');
     $dashboardDefinition->addMethodCall('loadFromConfiguration', array($appConfig));
 }
Example #27
0
 /**
  * Processes a ContainerBuilder object to populate the service reference graph.
  *
  * @param ContainerBuilder $container
  */
 public function process(ContainerBuilder $container)
 {
     $this->container = $container;
     $this->graph = $container->getCompiler()->getServiceReferenceGraph();
     $this->graph->clear();
     foreach ($container->getDefinitions() as $id => $definition) {
         if ($definition->isSynthetic() || $definition->isAbstract()) {
             continue;
         }
         $this->currentId = $id;
         $this->currentDefinition = $definition;
         $this->processArguments($definition->getArguments());
         if ($definition->getFactoryService()) {
             $this->processArguments(array(new Reference($definition->getFactoryService())));
         }
         if (!$this->onlyConstructorArguments) {
             $this->processArguments($definition->getMethodCalls());
             $this->processArguments($definition->getProperties());
             if ($definition->getConfigurator()) {
                 $this->processArguments(array($definition->getConfigurator()));
             }
         }
     }
     foreach ($container->getAliases() as $id => $alias) {
         $this->graph->connect($id, $alias, (string) $alias, $this->getDefinition((string) $alias), null);
     }
 }
 /**
  * Test related method
  */
 public function testLoad()
 {
     $this->extension->load($this->configs, $this->containerBuilder);
     $serviceIds = $this->containerBuilder->getServiceIds();
     $this->assertCount(3, $serviceIds);
     $this->assertTrue(in_array(self::PIM_TRANSLATION_FORM_TYPE, $serviceIds));
 }
 /**
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  * @param string                                                  $name
  *
  * @return string
  */
 private function getModelName(ContainerBuilder $container, $name)
 {
     if ($name[0] == '%') {
         return $container->getParameter(substr($name, 1, -1));
     }
     return $name;
 }
 /**
  * You can modify the container here before it is dumped to PHP code.
  *
  * @param ContainerBuilder $container
  *
  * @api
  */
 public function process(ContainerBuilder $container)
 {
     $config = $container->getParameter(ElastificationPhpClientExtension::PARAMETER_CONFIG_KEY);
     if (true === $config['profiler_enabled']) {
         $clientAlias = $container->getAlias(ElastificationPhpClientExtension::ALIAS_CLIENT);
         $profilerDef = $container->getDefinition(ElastificationPhpClientExtension::SERVICE_CLIENT_PROFILER_KEY);
         $profilerDef->replaceArgument(0, new Reference($clientAlias->__toString()));
         $dataCollectorDef = $container->getDefinition('elastification_php_client.datacollector');
         $dataCollectorDef->addMethodCall('setConfig', array($config));
         $container->setAlias(ElastificationPhpClientExtension::ALIAS_CLIENT, ElastificationPhpClientExtension::SERVICE_CLIENT_PROFILER_KEY);
     } else {
         if ($container->hasDefinition('profiler')) {
             $sfProfilerDef = $container->getDefinition('profiler');
             $sfProfilerMethodCalls = $sfProfilerDef->getMethodCalls();
             foreach ($sfProfilerMethodCalls as $sfProfilerMethodCallsIndex => $sfProfilerMethodCall) {
                 if (isset($sfProfilerMethodCall[1][0]) && 'elastification_php_client.datacollector' == (string) $sfProfilerMethodCall[1][0]) {
                     unset($sfProfilerMethodCalls[$sfProfilerMethodCallsIndex]);
                 }
             }
             $sfProfilerDef->setMethodCalls($sfProfilerMethodCalls);
         }
         $container->removeDefinition(ElastificationPhpClientExtension::SERVICE_CLIENT_PROFILER_KEY);
         $container->removeDefinition('elastification_php_client.datacollector');
     }
 }