Definition PHP Class Code Examples

This page contains top rated real world PHP examples of class Definition extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: RezzzaShortyExtension.php Project: shouze/ShortyBundle
0
 /**
  * {@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('shorty.xml');
     foreach ($config['providers'] as $providerName => $providerConfiguration) {
         switch ($providerConfiguration['id']) {
             case 'google':
                 $definition = new Definition($container->getParameter('rezzza.shorty.google.class'), array($providerConfiguration['key']));
                 $definition->addMethodCall('setHttpAdapter', array(new Definition($providerConfiguration['http_adapter'])));
                 $container->setDefinition($this->getShortyProviderName($providerName), $definition);
                 break;
             case 'bitly':
                 $definition = new Definition($container->getParameter('rezzza.shorty.bitly.class'), array($providerConfiguration['access_token']));
                 $definition->addMethodCall('setHttpAdapter', array(new Definition($providerConfiguration['http_adapter'])));
                 $container->setDefinition($this->getShortyProviderName($providerName), $definition);
                 break;
             case 'chain':
                 $definition = new Definition($container->getParameter('rezzza.shorty.chain.class'));
                 foreach ($providerConfiguration['providers'] as $provider) {
                     $definition->addMethodCall('addProvider', array(new Reference($this->getShortyProviderName($provider))));
                 }
                 $container->setDefinition($this->getShortyProviderName($providerName), $definition);
                 break;
             default:
                 $container->setAlias($this->getShortyProviderName($providerName), $providerConfiguration['id']);
                 break;
         }
     }
     if (isset($config['default_provider'])) {
         $container->setAlias('rezzza.shorty', $this->getShortyProviderName($config['default_provider']));
     }
 }
Example #2
Show file File: PrettyFormatterFactory.php Project: OverByThere/Behat
0
 /**
  * Loads printer helpers.
  *
  * @param ContainerBuilder $container
  */
 protected function loadPrinterHelpers(ContainerBuilder $container)
 {
     $definition = new Definition('Behat\\Behat\\Output\\Node\\Printer\\Helper\\WidthCalculator');
     $container->setDefinition('output.node.printer.pretty.width_calculator', $definition);
     $definition = new Definition('Behat\\Behat\\Output\\Node\\Printer\\Helper\\StepTextPainter', array(new Reference(DefinitionExtension::PATTERN_TRANSFORMER_ID), new Reference(self::RESULT_TO_STRING_CONVERTER_ID)));
     $container->setDefinition('output.node.printer.pretty.step_text_painter', $definition);
     $definition = new Definition('Behat\\Behat\\Output\\Node\\Printer\\Helper\\ResultToStringConverter');
     $container->setDefinition(self::RESULT_TO_STRING_CONVERTER_ID, $definition);
 }
Example #3
Show file File: RegisterAttributeFactoryPassSpec.php Project: themarios/Sylius
0
 function it_processes_with_given_container(ContainerBuilder $container, Definition $attributeTypeRegistryDefinition, Definition $oldAttributeFactoryDefinition, Definition $newAttributeFactoryDefinition)
 {
     $container->hasDefinition('sylius.registry.attribute_type')->willReturn(true);
     $container->getDefinition('sylius.registry.attribute_type')->willReturn($attributeTypeRegistryDefinition);
     $container->getDefinition('sylius.factory.product_attribute')->willReturn($oldAttributeFactoryDefinition);
     $container->setDefinition('sylius.factory.product_attribute', Argument::type('Symfony\\Component\\DependencyInjection\\Definition'))->willReturn($newAttributeFactoryDefinition);
     $newAttributeFactoryDefinition->addArgument($oldAttributeFactoryDefinition)->shouldBeCalled();
     $newAttributeFactoryDefinition->addArgument($attributeTypeRegistryDefinition)->shouldBeCalled();
     $this->process($container);
 }
Example #4
Show file File: HttpClientWithCookiesCompiler.php Project: ci-tron/ci-tron
0
 public function process(ContainerBuilder $container)
 {
     // Adding the array cookie jar as service because we need to get it later.
     $cookieJarDefinition = new Definition('Guzzle\\Plugin\\Cookie\\CookieJar\\ArrayCookieJar');
     $container->setDefinition('citron.guzzle.array_cookie_jar', $cookieJarDefinition);
     $cookiePluginDefinition = new Definition('Guzzle\\Plugin\\Cookie\\CookiePlugin', [new Reference('citron.guzzle.array_cookie_jar')]);
     $container->setDefinition('citron.guzzle.cookie_plugin', $cookiePluginDefinition);
     $definition = $container->getDefinition('friendly.http_client');
     $definition->addMethodCall('addSubscriber', [new Reference('citron.guzzle.cookie_plugin')]);
 }
Example #5
Show file File: CheckTagCompilerPassTest.php Project: helios-ag/LiipMonitorBundle
0
 public function testProcess()
 {
     $runner = new Definition();
     $this->setDefinition('liip_monitor.runner', $runner);
     $check = new Definition();
     $check->addTag('liip_monitor.check');
     $this->setDefinition('example_check', $check);
     $this->compile();
     $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('liip_monitor.runner', 'addCheck', array(new Reference('example_check'), 'example_check'));
 }
Example #6
Show file File: ImageCommandCompilerPassTest.php Project: Silwereth/sulu
0
 /**
  * @test
  */
 public function if_compiler_pass_collects_services_by_adding_method_calls_these_will_exist()
 {
     $commandManager = new Definition();
     $this->setDefinition('sulu_media.image.command_manager', $commandManager);
     $command = new Definition();
     $command->addTag('sulu_media.image.command', ['alias' => 'resize']);
     $this->setDefinition('sulu_media.image.command.resize', $command);
     $this->compile();
     $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('sulu_media.image.command_manager', 'add', [new Reference('sulu_media.image.command.resize'), 'resize']);
 }
Example #7
Show file File: AdditionalReporterCompilerPassTest.php Project: helios-ag/LiipMonitorBundle
0
 public function testProcessWithoutAlias()
 {
     $runner = new Definition();
     $this->setDefinition('liip_monitor.runner', $runner);
     $reporter = new Definition();
     $reporter->addTag('liip_monitor.additional_reporter');
     $this->setDefinition('foo_reporter', $reporter);
     $this->compile();
     $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('liip_monitor.runner', 'addAdditionalReporter', array('foo_reporter', new Reference('foo_reporter')));
 }
Example #8
Show file File: GeolocatorPassTest.php Project: Silwereth/sulu
0
 public function testRegisterGeolocators()
 {
     $managerDef = new Definition();
     $this->setDefinition('sulu_location.geolocator.manager', $managerDef);
     $geolocatorDef = new Definition();
     $geolocatorDef->addTag('sulu_location.geolocator', ['alias' => 'my_alias']);
     $this->setDefinition('geolocator_id', $geolocatorDef);
     $this->compile();
     $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('sulu_location.geolocator.manager', 'register', ['my_alias', 'geolocator_id']);
 }
Example #9
Show file File: LiuggioStatsDClientExtension.php Project: dainis/StatsDClientBundle
0
 /**
  * Loads the Monolog configuration.
  *
  * @param array            $config    A configuration array
  * @param ContainerBuilder $container A ContainerBuilder instance
  */
 protected function loadMonologHandler(array $config, ContainerBuilder $container)
 {
     $def2 = new Definition($config['monolog']['formatter']['class'], array($config['monolog']['formatter']['format'], $config['monolog']['formatter']['context_logging'], $config['monolog']['formatter']['extra_logging'], $config['monolog']['formatter']['words']));
     $container->setDefinition('monolog.formatter.statsd', $def2);
     $def = new Definition($container->getParameter('liuggio_stats_d_client.monolog_handler.class'), array(new Reference('liuggio_stats_d_client.service'), new Reference('liuggio_stats_d_client.factory'), $config['monolog']['prefix'], $this->convertLevelToConstant($config['monolog']['level'])));
     $def->setPublic(false);
     $def->addMethodCall('setFormatter', array(new Reference('monolog.formatter.statsd')));
     $container->setDefinition('monolog.handler.statsd', $def);
 }
Example #10
Show file File: OrderingExtension.php Project: OverByThere/Behat
0
 /**
  * Defines default orderers
  *
  * @param ContainerBuilder $container
  */
 private function loadDefaultOrderers(ContainerBuilder $container)
 {
     $definition = new Definition('Behat\\Testwork\\Ordering\\Orderer\\ReverseOrderer');
     $definition->addTag(self::ORDERER_TAG, array('priority' => -9999));
     $container->setDefinition(TesterExtension::EXERCISE_WRAPPER_TAG . '.ordering.reverse', $definition);
     $definition = new Definition('Behat\\Testwork\\Ordering\\Orderer\\RandomOrderer');
     $definition->addTag(self::ORDERER_TAG, array('priority' => -9999));
     $container->setDefinition(TesterExtension::EXERCISE_WRAPPER_TAG . '.ordering.random', $definition);
 }
Example #11
Show file File: ArgumentExtension.php Project: OverByThere/Behat
0
 /**
  * {@inheritdoc}
  */
 public function load(ContainerBuilder $container, array $config)
 {
     $definition = new Definition('Behat\\Testwork\\Argument\\MixedArgumentOrganiser');
     $container->setDefinition(self::MIXED_ARGUMENT_ORGANISER_ID, $definition);
     $definition = new Definition('Behat\\Testwork\\Argument\\PregMatchArgumentOrganiser', array(new Reference(self::MIXED_ARGUMENT_ORGANISER_ID)));
     $container->setDefinition(self::PREG_MATCH_ARGUMENT_ORGANISER_ID, $definition);
     $definition = new Definition('Behat\\Testwork\\Argument\\ConstructorArgumentOrganiser', array(new Reference(self::MIXED_ARGUMENT_ORGANISER_ID)));
     $container->setDefinition(self::CONSTRUCTOR_ARGUMENT_ORGANISER_ID, $definition);
 }
Example #12
Show file File: JUnitFormatterFactory.php Project: OverByThere/Behat
0
 /**
  * Loads formatter itself.
  *
  * @param ContainerBuilder $container
  */
 private function loadFormatter(ContainerBuilder $container)
 {
     $definition = new Definition('Behat\\Behat\\Output\\Statistics\\PhaseStatistics');
     $container->setDefinition('output.junit.statistics', $definition);
     $definition = new Definition('Behat\\Testwork\\Output\\NodeEventListeningFormatter', array('junit', 'Outputs the failures in JUnit compatible files.', array('timer' => true), $this->createOutputPrinterDefinition(), new Definition('Behat\\Testwork\\Output\\Node\\EventListener\\ChainEventListener', array(array(new Reference(self::ROOT_LISTENER_ID), new Definition('Behat\\Behat\\Output\\Node\\EventListener\\Statistics\\ScenarioStatsListener', array(new Reference('output.junit.statistics'))), new Definition('Behat\\Behat\\Output\\Node\\EventListener\\Statistics\\StepStatsListener', array(new Reference('output.junit.statistics'), new Reference(ExceptionExtension::PRESENTER_ID))), new Definition('Behat\\Behat\\Output\\Node\\EventListener\\Statistics\\HookStatsListener', array(new Reference('output.junit.statistics'), new Reference(ExceptionExtension::PRESENTER_ID))))))));
     $definition->addTag(OutputExtension::FORMATTER_TAG, array('priority' => 100));
     $container->setDefinition(OutputExtension::FORMATTER_TAG . '.junit', $definition);
 }
Example #13
Show file File: AddCommandHandlersPassTest.php Project: ruslan-polutsygan/common-bundle
0
 public function test_known_dependencies_injected_injected_into_handlers()
 {
     $container = new ContainerBuilder();
     $container->setDefinition('rp.command_bus', $bus = new Definition('CommandBus'));
     $handler1 = new Definition('\\AppBundle\\Company\\CommandHandler\\CreatePlanItemsCommandHandler');
     $handler1->addTag('command_bus.handler');
     $handler2 = new Definition('\\AppBundle\\SupportMessage\\CommandHandler\\PrepareAndSendToAdminCommandHandler');
     $handler2->addTag('command_bus.handler');
     $handler3 = new Definition('\\AppBundle\\SupportMessage\\CommandHandler\\SendToUserCommandHandler');
     $handler3->addTag('command_bus.handler');
     $container->setDefinition('handler_1', $handler1);
     $container->setDefinition('handler_2', $handler2);
     $container->setDefinition('handler_3', $handler3);
     $compiler = new AddCommandHandlersPass();
     $compiler->process($container);
     $calls1 = $handler1->getMethodCalls();
     $this->assertCount(1, $calls1);
     $this->assertEquals('setEntityManager', $calls1[0][0]);
     $this->assertEquals('doctrine.orm.default_entity_manager', $calls1[0][1][0]);
     $calls2 = $handler2->getMethodCalls();
     $this->assertCount(1, $calls2);
     $this->assertEquals('setCommandBus', $calls2[0][0]);
     $this->assertEquals('rp.command_bus', $calls2[0][1][0]);
     $calls3 = $handler3->getMethodCalls();
     $this->assertCount(2, $calls3);
     $this->assertEquals('setEntityManager', $calls3[0][0]);
     $this->assertEquals('doctrine.orm.default_entity_manager', $calls3[0][1][0]);
     $this->assertEquals('setEventDispatcher', $calls3[1][0]);
     $this->assertEquals('event_dispatcher', $calls3[1][1][0]);
 }
Example #14
Show file File: ProgressFormatterFactory.php Project: OverByThere/Behat
0
 /**
  * Loads formatter itself.
  *
  * @param ContainerBuilder $container
  */
 protected function loadFormatter(ContainerBuilder $container)
 {
     $definition = new Definition('Behat\\Behat\\Output\\Statistics\\TotalStatistics');
     $container->setDefinition('output.progress.statistics', $definition);
     $definition = new Definition('Behat\\Testwork\\Output\\NodeEventListeningFormatter', array('progress', 'Prints one character per step.', array('timer' => true), $this->createOutputPrinterDefinition(), new Definition('Behat\\Testwork\\Output\\Node\\EventListener\\ChainEventListener', array(array(new Reference(self::ROOT_LISTENER_ID), new Definition('Behat\\Behat\\Output\\Node\\EventListener\\Statistics\\StatisticsListener', array(new Reference('output.progress.statistics'), new Reference('output.node.printer.progress.statistics'))), new Definition('Behat\\Behat\\Output\\Node\\EventListener\\Statistics\\ScenarioStatsListener', array(new Reference('output.progress.statistics'))), new Definition('Behat\\Behat\\Output\\Node\\EventListener\\Statistics\\StepStatsListener', array(new Reference('output.progress.statistics'), new Reference(ExceptionExtension::PRESENTER_ID))), new Definition('Behat\\Behat\\Output\\Node\\EventListener\\Statistics\\HookStatsListener', array(new Reference('output.progress.statistics'), new Reference(ExceptionExtension::PRESENTER_ID))))))));
     $definition->addTag(OutputExtension::FORMATTER_TAG, array('priority' => 100));
     $container->setDefinition(OutputExtension::FORMATTER_TAG . '.progress', $definition);
 }
Example #15
Show file File: SonataFormatterExtension.php Project: devcodixis/SonataFormatterBundle
0
 /**
  * @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);
 }
Example #16
Show file File: MappingPass.php Project: emgiezet/ElasticsearchBundle
0
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $analysis = $container->getParameter('es.analysis');
     $connections = $container->getParameter('es.connections');
     $managers = $container->getParameter('es.managers');
     $collector = $container->get('es.metadata_collector');
     foreach ($managers as $managerName => $manager) {
         if (!isset($connections[$manager['connection']])) {
             throw new InvalidConfigurationException('There is no ES connection with the name: ' . $manager['connection']);
         }
         $managerName = strtolower($managerName);
         $connection = $connections[$manager['connection']];
         $managerDefinition = new Definition($container->getParameter('es.manager.class'), [$managerName, $connection, $analysis, $manager]);
         $managerDefinition->setFactory([new Reference('es.manager_factory'), 'createManager']);
         $container->setDefinition(sprintf('es.manager.%s', $managerName), $managerDefinition);
         // Make es.manager.default as es.manager service.
         if ($managerName === 'default') {
             $container->setAlias('es.manager', 'es.manager.default');
         }
         $mappings = $collector->getMappings($manager['mappings']);
         // Building repository services.
         foreach ($mappings as $repositoryType => $repositoryDetails) {
             $repositoryDefinition = new Definition($container->getParameter('es.repository.class'), [$repositoryDetails['bundle'] . ':' . $repositoryDetails['class']]);
             $repositoryDefinition->setFactory([new Reference(sprintf('es.manager.%s', $managerName)), 'getRepository']);
             $repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType);
             if (strtolower(substr($repositoryType, -8)) === 'document') {
                 $container->setAlias(sprintf('es.manager.%s.%s', $managerName, substr($repositoryType, 0, strlen($repositoryType) - 8)), $repositoryId);
             }
             $container->setDefinition($repositoryId, $repositoryDefinition);
         }
     }
 }
Example #17
Show file File: RepositoryCompilerPassTest.php Project: larriereguichet/DoctrineRepositoryBundle
0
 public function testProcess()
 {
     // TEST 1
     // must work with no tagged services
     $containerBuilder = new ContainerBuilder();
     $compilerPass = new RepositoryCompilerPass();
     $compilerPass->process($containerBuilder);
     // TEST 2
     // must add repository tagged service into the repository pool
     $containerBuilder = new ContainerBuilder();
     $containerBuilder->setDefinition('lag.repository.repository_pool', new Definition());
     $repository = new Definition();
     $repository->addTag('doctrine.repository');
     $containerBuilder->setDefinition('repository1', $repository);
     $repository = new Definition();
     $repository->addTag('doctrine.repository');
     $containerBuilder->setDefinition('repository2', $repository);
     $compilerPass = new RepositoryCompilerPass();
     $compilerPass->process($containerBuilder);
     $methodCalls = $containerBuilder->getDefinition('lag.repository.repository_pool')->getMethodCalls();
     $this->assertCount(2, $methodCalls);
     foreach ($methodCalls as $call) {
         /** @var Reference $reference */
         $reference = $call[1][0];
         // test reference assignment
         $this->assertEquals('add', $call[0]);
         $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $reference);
         $this->assertTrue(in_array($reference->__toString(), ['repository1', 'repository2']));
     }
 }
Example #18
Show file File: IntegratedChannelExtension.php Project: integratedfordevelopers/integrated-channel-bundle
0
 /**
  * Process the adaptor config configuration.
  *
  * @param array $config
  * @param ContainerBuilder $container
  */
 protected function loadConfigs(array $config, ContainerBuilder $container)
 {
     foreach ($config['configs'] as $name => $arguments) {
         if (!$arguments['enabled']) {
             continue;
         }
         $id = 'integrated_channel.config.memory.' . $name;
         if ($container->hasDefinition($id)) {
             continue;
         }
         // first create the options and for that we need a unique service id
         do {
             $id_options = $id . '.options.' . uniqid();
         } while ($container->hasDefinition($id_options));
         $definition = new Definition('%integrated_channel.config.options.class%');
         $definition->setPublic(false);
         $definition->setArguments([$arguments['options']]);
         $container->setDefinition($id_options, $definition);
         // create the config it self
         $definition = new Definition('%integrated_channel.config.class%');
         $definition->setArguments([$name, $arguments['adaptor'], new Reference($id_options)]);
         if ($arguments['channel']) {
             foreach ($arguments['channel'] as $channel) {
                 $definition->addTag('integrated_channel.config', ['channel' => $channel]);
             }
         } else {
             $definition->addTag('integrated_channel.config');
         }
         $container->setDefinition($id, $definition);
     }
 }
Example #19
Show file File: DoctrineExtension.php Project: artz20/Tv-shows-zone
0
 /**
  * Gets an entity manager cache driver definition for metadata, query and result caches.
  *
  * @param array            $entityManager The array configuring an entity manager.
  * @param array            $cacheDriver   The cache driver configuration.
  * @param ContainerBuilder $container
  * @return Definition $cacheDef
  */
 protected function getEntityManagerCacheDefinition(array $entityManager, $cacheDriver, ContainerBuilder $container)
 {
     switch ($cacheDriver['type']) {
         case 'memcache':
             $memcacheClass = !empty($cacheDriver['class']) ? $cacheDriver['class'] : '%doctrine.orm.cache.memcache.class%';
             $memcacheInstanceClass = !empty($cacheDriver['instance_class']) ? $cacheDriver['instance_class'] : '%doctrine.orm.cache.memcache_instance.class%';
             $memcacheHost = !empty($cacheDriver['host']) ? $cacheDriver['host'] : '%doctrine.orm.cache.memcache_host%';
             $memcachePort = !empty($cacheDriver['port']) ? $cacheDriver['port'] : '%doctrine.orm.cache.memcache_port%';
             $cacheDef = new Definition($memcacheClass);
             $memcacheInstance = new Definition($memcacheInstanceClass);
             $memcacheInstance->addMethodCall('connect', array($memcacheHost, $memcachePort));
             $container->setDefinition(sprintf('doctrine.orm.%s_memcache_instance', $entityManager['name']), $memcacheInstance);
             $cacheDef->addMethodCall('setMemcache', array(new Reference(sprintf('doctrine.orm.%s_memcache_instance', $entityManager['name']))));
             break;
         case 'apc':
         case 'array':
         case 'xcache':
             $cacheDef = new Definition('%' . sprintf('doctrine.orm.cache.%s.class', $cacheDriver['type']) . '%');
             break;
         default:
             throw new \InvalidArgumentException(sprintf('"%s" is an unrecognized Doctrine cache driver.', $cacheDriver['type']));
     }
     $cacheDef->setPublic(false);
     // generate a unique namespace for the given application
     $namespace = 'sf2orm_' . $entityManager['name'] . '_' . md5($container->getParameter('kernel.root_dir') . $container->getParameter('kernel.environment'));
     $cacheDef->addMethodCall('setNamespace', array($namespace));
     return $cacheDef;
 }
Example #20
Show file File: LswGuzzleExtension.php Project: xGouley/LswGuzzleBundle
0
 /**
  * Creates a new Guzzle client definition
  *
  * @param string           $name      Client name
  * @param array            $config    Client configuration
  * @param ContainerBuilder $container Service container
  *
  * @throws \LogicException
  */
 private function newGuzzleClient($name, array $config, ContainerBuilder $container)
 {
     $client = new Definition('Guzzle\\Service\\Description\\ServiceDescription');
     $client->setFactory(['Guzzle\\Service\\Description\\ServiceDescription', 'factory']);
     if (!isset($config['description']['name'])) {
         $config['description']['name'] = $name;
     }
     $client->addArgument($config['description']);
     // Add the service to the container
     $serviceName = sprintf('lsw_guzzle.%s', $name);
     $container->setDefinition($serviceName, $client);
     $client = new Definition('Guzzle\\Service\\Client');
     $client->setFactory(['Guzzle\\Service\\Client', 'factory']);
     $client->addArgument($config['config']);
     $client->addMethodCall('setDescription', array(new Reference($serviceName)));
     $client->addMethodCall('addSubscriber', array(new Reference('lsw_guzzle.log_plugin')));
     if (isset($config['config']['json_objects']) && $config['config']['json_objects']) {
         $client->addMethodCall('addSubscriber', array(new Reference('lsw_guzzle.json_objects_plugin')));
     }
     if ($container->hasDefinition('lsw_guzzle.command_history_plugin')) {
         $client->addMethodCall('addSubscriber', array(new Reference('lsw_guzzle.command_history_plugin')));
     }
     // Add the service to the container
     $serviceName = sprintf('guzzle.%s', $name);
     $container->setDefinition($serviceName, $client);
 }
Example #21
Show file File: OptimizeTwigLoaderPassTest.php Project: sonatra/SonatraMailerBundle
0
 public function testProcessWithAddTemplates()
 {
     $container = $this->getContainer();
     $layoutLoaderDef = new Definition(TwigLayoutLoader::class);
     $mailLoaderDef = new Definition(TwigLayoutLoader::class);
     $layoutLoaderDef->setArguments(array(array()));
     $mailLoaderDef->setArguments(array(array()));
     $container->setDefinition('sonatra_mailer.loader.layout_twig', $layoutLoaderDef);
     $container->setDefinition('sonatra_mailer.loader.mail_twig', $mailLoaderDef);
     $this->assertCount(0, $layoutLoaderDef->getArgument(0));
     $this->assertCount(0, $mailLoaderDef->getArgument(0));
     // array loader
     $layoutArrayLoaderDef = new Definition(ArrayLayoutLoader::class);
     $mailArrayLoaderDef = new Definition(ArrayLayoutLoader::class);
     $layoutArrayLoaderDef->setArguments(array(array()));
     $mailArrayLoaderDef->setArguments(array(array()));
     $container->setDefinition('sonatra_mailer.loader.layout_array', $layoutArrayLoaderDef);
     $container->setDefinition('sonatra_mailer.loader.mail_array', $mailArrayLoaderDef);
     $this->assertCount(0, $layoutArrayLoaderDef->getArgument(0));
     $this->assertCount(0, $mailArrayLoaderDef->getArgument(0));
     // add mocks
     $layoutLoaderDef->replaceArgument(0, array(array('name' => 'layout-test', 'file' => __DIR__ . '/../../Fixtures/loaders/layout.html.twig', 'translations' => array(array('locale' => 'fr', 'file' => __DIR__ . '/../../Fixtures/loaders/layout.fr.html.twig')))));
     $mailLoaderDef->replaceArgument(0, array(array('name' => 'mail-test', 'file' => __DIR__ . '/../../Fixtures/loaders/mail.html.twig', 'layout' => 'layout-test', 'translations' => array(array('locale' => 'fr', 'file' => __DIR__ . '/../../Fixtures/loaders/mail.fr.html.twig')))));
     // test
     $this->pass->process($container);
     $this->assertFalse($container->has('sonatra_mailer.loader.layout_twig'));
     $this->assertFalse($container->has('sonatra_mailer.loader.mail_twig'));
 }
Example #22
Show file File: OptimizeYamlLoaderPassTest.php Project: sonatra/SonatraMailerBundle
0
 public function testProcessWithAddTemplates()
 {
     $container = $this->getContainer();
     $layoutLoaderDef = new Definition(YamlLayoutLoader::class);
     $mailLoaderDef = new Definition(YamlLayoutLoader::class);
     $layoutLoaderDef->setArguments(array(array()));
     $mailLoaderDef->setArguments(array(array()));
     $container->setDefinition('sonatra_mailer.loader.layout_yaml', $layoutLoaderDef);
     $container->setDefinition('sonatra_mailer.loader.mail_yaml', $mailLoaderDef);
     $this->assertCount(0, $layoutLoaderDef->getArgument(0));
     $this->assertCount(0, $mailLoaderDef->getArgument(0));
     // array loader
     $layoutArrayLoaderDef = new Definition(ArrayLayoutLoader::class);
     $mailArrayLoaderDef = new Definition(ArrayLayoutLoader::class);
     $layoutArrayLoaderDef->setArguments(array(array()));
     $mailArrayLoaderDef->setArguments(array(array()));
     $container->setDefinition('sonatra_mailer.loader.layout_array', $layoutArrayLoaderDef);
     $container->setDefinition('sonatra_mailer.loader.mail_array', $mailArrayLoaderDef);
     $this->assertCount(0, $layoutArrayLoaderDef->getArgument(0));
     $this->assertCount(0, $mailArrayLoaderDef->getArgument(0));
     // add mocks
     $layoutLoaderDef->replaceArgument(0, array(array('name' => 'layout-test', 'file' => __DIR__ . '/../../Fixtures/loaders/layout.yml')));
     $mailLoaderDef->replaceArgument(0, array(array('name' => 'mail-test', 'file' => __DIR__ . '/../../Fixtures/loaders/mail.yml')));
     // test
     $this->pass->process($container);
     $this->assertFalse($container->has('sonatra_mailer.loader.layout_yaml'));
     $this->assertFalse($container->has('sonatra_mailer.loader.mail_yaml'));
 }
Example #23
Show file File: MappingPass.php Project: ndinh215/ElasticsearchBundle
0
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $analysis = $container->getParameter('es.analysis');
     $connections = $container->getParameter('es.connections');
     $managers = $container->getParameter('es.managers');
     $collector = $container->get('es.metadata_collector');
     foreach ($managers as $managerName => $manager) {
         if (!isset($connections[$manager['connection']])) {
             throw new InvalidConfigurationException('There is no ES connection with the name: ' . $manager['connection']);
         }
         $managerName = strtolower($managerName);
         $connection = $connections[$manager['connection']];
         $managerDefinition = new Definition('ONGR\\ElasticsearchBundle\\Service\\Manager', [$managerName, $connection, $analysis, $manager]);
         $managerDefinition->setFactory([new Reference('es.manager_factory'), 'createManager']);
         $container->setDefinition(sprintf('es.manager.%s', $managerName), $managerDefinition);
         // Make es.manager.default as es.manager service.
         if ($managerName === 'default') {
             $container->setAlias('es.manager', 'es.manager.default');
         }
         $mappings = $collector->getMappings($manager['mappings']);
         // Building repository services.
         foreach ($mappings as $repositoryType => $repositoryDetails) {
             $repositoryDefinition = new Definition('ONGR\\ElasticsearchBundle\\Service\\Repository', [$repositoryDetails['namespace']]);
             $repositoryDefinition->setFactory([new Reference(sprintf('es.manager.%s', $managerName)), 'getRepository']);
             $repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType);
             if (strtolower(substr($repositoryType, -8)) === 'document') {
                 $container->setAlias(sprintf('es.manager.%s.%s', $managerName, substr($repositoryType, 0, strlen($repositoryType) - 8)), $repositoryId);
             }
             $container->setDefinition($repositoryId, $repositoryDefinition);
         }
     }
 }
Example #24
Show file File: RegisterAttributeFactoryPassSpec.php Project: ReissClothing/Sylius
0
 function it_processes_with_given_container(ContainerBuilder $container, Definition $attributeTypeRegistryDefinition, Definition $oldAttributeFactoryDefinition, Definition $newAttributeFactoryDefinition)
 {
     $container->hasDefinition('sylius.registry.attribute_type')->willReturn(true);
     $container->getDefinition('sylius.registry.attribute_type')->willReturn($attributeTypeRegistryDefinition);
     $container->getParameter('sylius.attribute.subjects')->willReturn(['product' => []]);
     $container->getDefinition('sylius.factory.product_attribute')->willReturn($oldAttributeFactoryDefinition);
     $container->setDefinition('sylius.factory.product_attribute', Argument::type('Symfony\\Component\\DependencyInjection\\Definition'))->willReturn($newAttributeFactoryDefinition);
     $newAttributeFactoryDefinition->addArgument($oldAttributeFactoryDefinition)->shouldBeCalled();
     $newAttributeFactoryDefinition->addArgument($attributeTypeRegistryDefinition)->shouldBeCalled();
     $this->process($container);
 }