/** * @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 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'])); } }
/** * {@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); } } }
/** * {@inheritdoc} */ public function createDefinition(ContainerBuilder $container, array $config) { $definition = new Definition('Jose\\Object\\JWK'); $definition->setFactory([new Reference('jose.factory.jwk'), 'createFromKeyFile']); $definition->setArguments([$config['path'], $config['password'], $config['additional_values']]); return $definition; }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { $pool = $container->getDefinition('sonata.product.pool'); $calls = $pool->getMethodCalls(); $pool->setMethodCalls(array()); $map = array(); foreach ($calls as $method => $arguments) { if ($arguments[0] !== '__hack') { $pool->addMethodCall($arguments[0], $arguments[1]); continue; } foreach ($arguments[1] as $code => $options) { // define a new ProductDefinition $definition = new Definition('Sonata\\Component\\Product\\ProductDefinition', array(new Reference($options['provider']), new Reference($options['manager']))); $definition->setPublic(false); $container->setDefinition($code, $definition); $container->getDefinition($options['provider'])->addMethodCall('setCode', array($code)); $pool->addMethodCall('addProduct', array($code, new Reference($code))); $map[$code] = $container->getDefinition($options['manager'])->getArgument(0); $container->getDefinition($options['provider'])->addMethodCall('setBasketElementManager', array(new Reference('sonata.basket_element.manager'))); $container->getDefinition($options['provider'])->addMethodCall('setCurrencyPriceCalculator', array(new Reference('sonata.price.currency.calculator'))); $container->getDefinition($options['provider'])->addMethodCall('setProductCategoryManager', array(new Reference('sonata.product_category.product'))); $container->getDefinition($options['provider'])->addMethodCall('setProductCollectionManager', array(new Reference('sonata.product_collection.product'))); $container->getDefinition($options['provider'])->addMethodCall('setOrderElementClassName', array($container->getParameter('sonata.order.order_element.class'))); $container->getDefinition($options['provider'])->addMethodCall('setEventDispatcher', array(new Reference('event_dispatcher'))); if (array_key_exists('variations', $options)) { $container->getDefinition($options['provider'])->addMethodCall('setVariationFields', array($options['variations']['fields'])); } } } $container->getDefinition('sonata.product.subscriber.orm')->replaceArgument(0, $map); }
/** * {@inheritdoc} */ public function load(ContainerBuilder $container, array $config) { $container->setDefinition(self::CLIENT_ID, new Definition('GuzzleHttp\\Client', [$config])); $definition = new Definition('Ingresse\\Behat\\ApiExtension\\Context\\Initializer\\ApiClientInitializer', [new Reference(self::CLIENT_ID), $config]); $definition->addTag(ContextExtension::INITIALIZER_TAG); $container->setDefinition('ingresse_api.context_initializer', $definition); }
/** * @param type $modelName * @return Definition */ private function createDefinition($modelName) { $definition = new Definition(SyliusTrackerListener::class); $definition->addArgument(new Reference('symedit_analytics.tracker')); $definition->addTag('kernel.event_listener', ['event' => sprintf('symedit.%s.%s', $modelName, ResourceActions::SHOW), 'method' => 'track']); return $definition; }
/** * Ensures that the creator returns null if a synthetic service is requested. */ public function testCreatorReturnsNullIfSyntheticServiceIsRequested() { $definition = new Definition(); $definition->setSynthetic(true); $this->container->setDefinition('my.service', $definition); $this->assertNull($this->creator->create('my.service')); }
/** * {@inheritdoc} */ protected function addDefinitions(ContainerBuilder $container, array $config) { $container->setParameter('kherge_uuid.serializer.uuid_handler.class', 'KHerGe\\Bundle\\UuidBundle\\Serializer\\UuidHandler'); $definition = new Definition('%kherge_uuid.serializer.uuid_handler.class%'); $definition->addTag('jms_serializer.subscribing_handler'); $container->setDefinition('kherge_uuid.serializer.uuid_handler', $definition); }
protected function isInlinableDefinition(ContainerBuilder $container, $id, Definition $definition) { if (!$definition->isShared()) { return true; } if ($definition->isPublic()) { return false; } $references = count(array_keys($container->getAliases(), $id, true)); foreach ($container->getDefinitions() as $cDefinition) { if ($references > 1) { break; } if ($this->isReferencedByArgument($id, $cDefinition->getArguments())) { $references += 1; continue; } foreach ($cDefinition->getMethodCalls() as $call) { if ($this->isReferencedByArgument($id, $call[1])) { $references += 1; continue 2; } } } return $references <= 1; }
/** * {@inheritdoc} */ public function createDefinition(ContainerBuilder $container, array $config) { $definition = new Definition('Jose\\Object\\X5UJWKSet'); $definition->setFactory([new Reference('jose.factory.jwk'), 'createFromX5U']); $definition->setArguments([$config['url'], $config['is_secured'], $config['cache'], $config['cache_ttl'], $config['is_https']]); return $definition; }
/** * @param array $configs * @param ContainerBuilder $container */ private function registerPagers(array $configs, ContainerBuilder $container) { $shouldDisableRedirector = true; foreach ($configs as $name => $config) { $serviceId = sprintf("%s.%s", self::PREFIX_PAGER, $name); $definition = $container->register($serviceId, $container->getParameter('kg_pager.class')); // Sets the default items per page for the given pager. if (isset($config['per_page'])) { $definition->addArgument($config['per_page']); } // Changes the strategy, if this pager should merge last two pages // given the following threshold. if (isset($config['merge']) && $config['merge'] > 0) { $strategyDefinition = new Definition($container->getParameter('kg_pager.strategy.last_page_merged.class')); $strategyDefinition->addArgument($config['merge']); $definition->addArgument($strategyDefinition); } // Wraps the pager inside a request decorator to have it automatically // infer the current page from the request. if ($config['key']) { $definition = $container->register($serviceId, $container->getParameter('kg_pager.request_decorator.class'))->setArguments(array($definition, new Reference('request_stack'), $config['key'])); } if ($config['redirect']) { $shouldDisableRedirector = false; $definition = $container->register($serviceId, $container->getParameter('kg_pager.bounds_check_decorator.class'))->setArguments(array($definition)); if ($config['key']) { $definition->addArgument($config['key']); } } } if ($shouldDisableRedirector) { $container->removeDefinition('kg_pager.out_of_bounds_redirector'); } }
/** * @dataProvider processProvider */ public function testProcess($hasWarmer, $configIds) { $warmerId = 'yahoo_japan_config_cache.cache_warmer'; $container = new ContainerBuilder(); foreach ($configIds as $configId) { $definition = new Definition($configId); $definition->addTag(ConfigCache::TAG_CACHE_WARMER); $container->setDefinition($configId, $definition); } if ($hasWarmer) { $definition = new Definition($warmerId); $container->setDefinition($warmerId, $definition); } $pass = new CacheWarmerPass(); $pass->process($container); foreach ($configIds as $index => $configId) { if ($hasWarmer) { $calls = $container->getDefinition($warmerId)->getMethodCalls(); $this->assertTrue(isset($calls[$index][0])); // method name $this->assertSame('addConfig', $calls[$index][0]); $this->assertTrue(isset($calls[$index][1][0])); // argument $this->assertEquals(new Reference($configId), $calls[$index][1][0]); } else { $this->assertFalse($container->hasDefinition($warmerId)); } } }
/** * Load the initializer. * * @param ContainerBuilder $container * @param HttpKernelInterface $app */ private function loadInitializer(ContainerBuilder $container, $app) { $definition = new Definition('Laracasts\\Behat\\Context\\KernelAwareInitializer', [$app]); $definition->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, ['priority' => 0]); $definition->addTag(ContextExtension::INITIALIZER_TAG, ['priority' => 0]); $container->setDefinition('laravel.initializer', $definition); }
/** * @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['client_id'])) { return new Reference($config['client_id']); } $parameters = array('scheme' => $config['scheme'], 'host' => $config['host'], 'port' => $config['port']); if ($config['password']) { $parameters['password'] = $config['password']; } if ($config['timeout']) { $parameters['timeout'] = $config['timeout']; } if ($config['database']) { $parameters['database'] = $config['database']; } $options = null; if (isset($config['options'])) { $options = $config['options']; } $clientClass = '%doctrine_cache.predis.client.class%'; $clientId = sprintf('doctrine_cache.services.%s_predis.client', $name); $clientDef = new Definition($clientClass); $clientDef->addArgument($parameters); $clientDef->addArgument($options); $clientDef->setPublic(false); $container->setDefinition($clientId, $clientDef); return new Reference($clientId); }
public function load(array $configs, ContainerBuilder $container) { $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); $config = array(); foreach ($configs as $subConfig) { $config = array_merge($config, $subConfig); } foreach ($config['email'] as $alias => $options) { $optionId = sprintf('rage_notification.email.%s.message', $alias); $optionDef = new Definition($container->getParameter('rage_notification.email_message.class')); $optionDef->setShared(false); $optionDef->addArgument(new Reference('mailer')); $optionDef->addArgument(new Reference('templating')); if (!empty($options['from'])) { $optionDef->addMethodCall('setFrom', [$options['from']]); } if (!empty($options['reply_to'])) { $optionDef->addMethodCall('setReplyTo', [$options['reply_to']]); } if (!empty($options['embed_images'])) { $optionDef->addMethodCall('setEmbedImages', [$options['embed_images']['url'], $options['embed_images']['path']]); } if (!empty($options['template_path'])) { $optionDef->addMethodCall('setTemplatePath', [$options['template_path']]); } if (!empty($options['css_file'])) { $optionDef->addMethodCall('setCssFile', [$options['css_file']]); } $container->setDefinition($optionId, $optionDef); if ($alias === 'default') { $container->setAlias('rage_notification.email.message', $optionId); } } }
function it_processes_the_configuration_and_registers_services_per_variable(ContainerBuilder $container) { $variantFormType = new Definition('Some\\App\\Product\\Form\\ProductVariantType'); $variantFormType->setArguments(array('Some\\App\\Product\\Entity\\ProductVariant', '%sylius.validation_group.product_variant%', 'product'))->addTag('form.type', array('alias' => 'sylius_product_variant')); $container->setDefinition('sylius.form.type.product_variant', $variantFormType)->shouldBeCalled(); $variantChoiceFormType = new Definition('Sylius\\Bundle\\VariationBundle\\Form\\Type\\VariantChoiceType'); $variantChoiceFormType->setArguments(array('product'))->addTag('form.type', array('alias' => 'sylius_product_variant_choice')); $container->setDefinition('sylius.form.type.product_variant_choice', $variantChoiceFormType)->shouldBeCalled(); $variantMatchFormType = new Definition('Sylius\\Bundle\\VariationBundle\\Form\\Type\\VariantMatchType'); $variantMatchFormType->setArguments(array('product'))->addTag('form.type', array('alias' => 'sylius_product_variant_match')); $container->setDefinition('sylius.form.type.product_variant_match', $variantMatchFormType)->shouldBeCalled(); $optionFormType = new Definition('Some\\App\\Product\\Form\\OptionType'); $optionFormType->setArguments(array('Some\\App\\Product\\Entity\\Option', '%sylius.validation_group.product_option%', 'product'))->addTag('form.type', array('alias' => 'sylius_product_option')); $container->setDefinition('sylius.form.type.product_option', $optionFormType)->shouldBeCalled(); $optionChoiceFormType = new Definition('Sylius\\Bundle\\VariationBundle\\Form\\Type\\OptionEntityChoiceType'); $optionChoiceFormType->setArguments(array('product', 'Some\\App\\Product\\Entity\\Option'))->addTag('form.type', array('alias' => 'sylius_product_option_choice')); $container->setDefinition('sylius.form.type.product_option_choice', $optionChoiceFormType)->shouldBeCalled(); $optionValueFormType = new Definition('Some\\App\\Product\\Form\\OptionValueType'); $optionValueFormType->setArguments(array('Some\\App\\Product\\Entity\\OptionValue', '%sylius.validation_group.product_option_value%', 'product'))->addTag('form.type', array('alias' => 'sylius_product_option_value')); $container->setDefinition('sylius.form.type.product_option_value', $optionValueFormType)->shouldBeCalled(); $optionValueChoiceFormType = new Definition('Sylius\\Bundle\\VariationBundle\\Form\\Type\\OptionValueChoiceType'); $optionValueChoiceFormType->setArguments(array('product'))->addTag('form.type', array('alias' => 'sylius_product_option_value_choice')); $container->setDefinition('sylius.form.type.product_option_value_choice', $optionValueChoiceFormType)->shouldBeCalled(); $optionValueCollectionFormType = new Definition('Sylius\\Bundle\\VariationBundle\\Form\\Type\\OptionValueCollectionType'); $optionValueCollectionFormType->setArguments(array('product'))->addTag('form.type', array('alias' => 'sylius_product_option_value_collection')); $container->setDefinition('sylius.form.type.product_option_value_collection', $optionValueCollectionFormType)->shouldBeCalled(); $variables = array('product' => array('variable' => 'Some\\App\\Product\\Entity\\Product', 'option' => array('model' => 'Some\\App\\Product\\Entity\\Option', 'form' => 'Some\\App\\Product\\Form\\OptionType'), 'option_value' => array('model' => 'Some\\App\\Product\\Entity\\OptionValue', 'form' => 'Some\\App\\Product\\Form\\OptionValueType'), 'variant' => array('model' => 'Some\\App\\Product\\Entity\\ProductVariant', 'form' => 'Some\\App\\Product\\Form\\ProductVariantType'))); $container->setParameter('sylius.variation.variables', $variables)->shouldBeCalled(); $userConfig = array('driver' => SyliusResourceBundle::DRIVER_DOCTRINE_ORM, 'classes' => array('product' => array('variable' => 'Some\\App\\Product\\Entity\\Product', 'option' => array('model' => 'Some\\App\\Product\\Entity\\Option', 'form' => 'Some\\App\\Product\\Form\\OptionType'), 'option_value' => array('model' => 'Some\\App\\Product\\Entity\\OptionValue', 'form' => 'Some\\App\\Product\\Form\\OptionValueType'), 'variant' => array('model' => 'Some\\App\\Product\\Entity\\ProductVariant', 'form' => 'Some\\App\\Product\\Form\\ProductVariantType')))); $processedConfig = array('driver' => SyliusResourceBundle::DRIVER_DOCTRINE_ORM, 'classes' => array('product_option' => array('model' => 'Some\\App\\Product\\Entity\\Option', 'form' => 'Some\\App\\Product\\Form\\OptionType'), 'product_option_value' => array('model' => 'Some\\App\\Product\\Entity\\OptionValue', 'form' => 'Some\\App\\Product\\Form\\OptionValueType'), 'product_variant' => array('model' => 'Some\\App\\Product\\Entity\\ProductVariant', 'form' => 'Some\\App\\Product\\Form\\ProductVariantType')), 'validation_groups' => array('product_variant' => array('sylius'), 'product_option' => array('sylius'), 'product_option_value' => array('sylius'))); $this->process($userConfig, $container)->shouldReturn($processedConfig); }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { $translatableEntityLocaleAssignerDefinition = new Definition(TranslatableEntityLocaleAssigner::class); $translatableEntityLocaleAssignerDefinition->addArgument(new Reference('sylius.context.locale')); $translatableEntityLocaleAssignerDefinition->addArgument(new Reference('sylius.translation_locale_provider')); $container->setDefinition('sylius.translatable_entity_locale_assigner', $translatableEntityLocaleAssignerDefinition); }
/** * {@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'); foreach ($config['actions'] as $key => $value) { if ($value['max_number_by_ip']) { $definition = new Definition('Kunstmaan\\VotingBundle\\EventListener\\Security\\MaxNumberByIpEventListener'); $definition->addArgument(new Reference('kunstmaan_voting.services.repository_resolver')); $definition->addArgument($value['max_number_by_ip']); $definition->addTag('kernel.event_listener', array('event' => 'kunstmaan_voting.' . lcfirst(ContainerBuilder::camelize($key)), 'method' => 'onVote', 'priority' => 100)); $container->setDefinition('kunstmaan_voting.security.' . $key . '.max_number_by_ip_event_listener', $definition); } } $possibleActions = array('up_vote', 'down_vote', 'facebook_like', 'facebook_send', 'linkedin_share'); $votingDefaultValue = $config['voting_default_value']; // If the user overwrites the voting_default_value in paramters file, we use this one if ($container->hasParameter('voting_default_value')) { $votingDefaultValue = $container->getParameter('voting_default_value'); } // When no values are defined, initialize with defaults foreach ($possibleActions as $action) { if (!isset($config['actions'][$action]) || !is_array($config['actions'][$action])) { $config['actions'][$action]['default_value'] = $action == 'down_vote' ? -1 * $votingDefaultValue : $votingDefaultValue; } } $container->setParameter('kuma_voting.actions', $config['actions']); }
/** * Responds to the "white_october_admin" configuration parameter. * * @param array $configs * @param ContainerBuilder $container */ public function load(array $configs, ContainerBuilder $container) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('admin.xml'); $processor = new Processor(); $configuration = new Configuration(); $config = $processor->process($configuration->getConfigTree(), $configs); // data managers if (!empty($config['data_managers']['mandango'])) { $loader->load('data_manager_mandango.xml'); } if (!empty($config['data_managers']['doctrine']['orm'])) { $loader->load('data_manager_doctrine_orm.xml'); } if (!empty($config['data_managers']['doctrine']['odm'])) { $loader->load('data_manager_doctrine_odm.xml'); } // admins $adminIds = array(); foreach ($config['admins'] as $admin) { $definition = new Definition($admin['class']); $definition->addMethodCall('setContainer', array(new Reference('service_container'))); $classId = str_replace('\\', '_', $admin['class']); $adminId = 'white_october_admin.admin.' . $classId; $container->setDefinition($adminId, $definition); $adminIds[] = $adminId; } $container->getDefinition('white_october_admin.admin_factory')->replaceArgument(0, $adminIds); }
/** * @param ContainerBuilder $container * @param Definition $mailerDefinition */ protected function registerOutboundMessageTransformers(ContainerBuilder $container, Definition $mailerDefinition) { $transformerTag = 'everlution.email.outbound.message_transformer'; foreach ($container->findTaggedServiceIds($transformerTag) as $id => $attributes) { $mailerDefinition->addMethodCall('addMessageTransformer', array(new Reference($id))); } }
/** * @param array $config * @param ContainerBuilder $container * @return $this */ protected function parseValidateSchemaConfig(array $config, ContainerBuilder $container) { if ($config['enabled']) { $validateSchemaDefinition = $container->getDefinition('dev.validate_schema'); foreach ($config['paths'] as $path) { $validateSchemaDefinition->addMethodCall('addMappingPath', array($path)); } if ($config['bundles']['enabled']) { if (count($config['bundles']['bundles'])) { $bundles = $config['bundles']['bundles']; } else { $bundles = array_keys($container->getParameter('kernel.bundles')); } foreach ($bundles as $bundleName) { $validateSchemaDefinition->addMethodCall('addMappingBundle', array($bundleName)); } } $validateSchemaDefinition->addMethodCall('setExcludes', array($config['excludes'])); $listener = new Definition('steevanb\\DevBundle\\EventListener\\ValidateSchemaListener'); $listener->addArgument(new Reference('dev.validate_schema')); $listener->addArgument($config['disabled_urls']); $listener->addTag('kernel.event_listener', array('event' => $config['event'] == 'kernel.request' ? 'kernel.request' : 'kernel.response', 'method' => 'validateSchema')); $container->setDefinition('dev.validate_schema.listener', $listener); } return $this; }
/** * {@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'); $container->setParameter('eo_airbrake.api_key', $config['api_key']); $container->setParameter('eo_airbrake.async', $config['async']); $container->setParameter('eo_airbrake.host', $config['host']); $container->setParameter('eo_airbrake.secure', $config['secure']); // Exception Listener if ($config['api_key']) { // Airbreak Configuration $class = $container->getParameter('eo_airbrake.configuration.class'); $definition = new Definition($class, array($config['api_key'], $config['async'], $container->getParameter('kernel.environment'), $config['host'], $config['secure'])); $container->setDefinition('eo_airbrake.configuration', $definition); // Airbreak Client $class = $container->getParameter('eo_airbrake.client.class'); $definition = new Definition($class, array(new Reference('eo_airbrake.configuration'))); $container->setDefinition('eo_airbrake.client', $definition); // Exception Listener $class = $container->getParameter('eo_airbrake.exception_listener.class'); $definition = new Definition($class, array(new Reference('eo_airbrake.client'), $config['ignored_exceptions'])); $definition->addTag('kernel.event_listener', array('event' => 'kernel.exception', 'method' => 'onKernelException')); $container->setDefinition('php_airbrake.exception_listener', $definition); // PHP Shutdown Listener $class = $container->getParameter('eo_airbrake.shutdown_listener.class'); $definition = new Definition($class, array(new Reference('eo_airbrake.client'))); $definition->addTag('kernel.event_listener', array('event' => 'kernel.controller', 'method' => 'register')); $container->setDefinition('php_airbrake.shutdown_listener', $definition); } }
/** * {@inheritdoc} */ protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata) { $reflection = new \ReflectionClass($metadata->getClass('model')); $translatableInterface = 'Sylius\\Component\\Translation\\Model\\TranslatableInterface'; $translatable = interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface); $repositoryClassParameterName = sprintf('%s.repository.%s.class', $metadata->getApplicationName(), $metadata->getName()); $repositoryClass = $translatable ? 'Sylius\\Bundle\\TranslationBundle\\Doctrine\\ORM\\TranslatableResourceRepository' : 'Sylius\\Bundle\\ResourceBundle\\Doctrine\\ORM\\EntityRepository'; if ($container->hasParameter($repositoryClassParameterName)) { $repositoryClass = $container->getParameter($repositoryClassParameterName); } if ($metadata->hasClass('repository')) { $repositoryClass = $metadata->getClass('repository'); } $definition = new Definition($repositoryClass); $definition->setArguments(array(new Reference($metadata->getServiceId('manager')), $this->getClassMetadataDefinition($metadata))); if ($metadata->hasParameter('translation')) { $repositoryReflection = new \ReflectionClass($repositoryClass); $translatableRepositoryInterface = 'Sylius\\Component\\Translation\\Repository\\TranslatableResourceRepositoryInterface'; $translationConfig = $metadata->getParameter('translation'); if (interface_exists($translatableRepositoryInterface) && $repositoryReflection->implementsInterface($translatableRepositoryInterface)) { if (isset($translationConfig['fields'])) { $definition->addMethodCall('setTranslatableFields', array($translationConfig['fields'])); } } } $container->setDefinition($metadata->getServiceId('repository'), $definition); }
/** * @param Definition $definition * @param string $class * @param string $repository */ private function assertDefinition(Definition $definition, $class, $repository) { $this->assertSame($definition->getClass(), $repository); $factory = $definition->getFactory(); $this->assertSame($factory[1], "getRepository"); $this->assertSame($definition->getArgument(0), $class); }
/** * Build the 'lexik_translation.translation_storage' service definition. * * @param ContainerBuilder $container * @param string $storage * @param string $objectManager */ protected function buildTranslationStorageDefinition(ContainerBuilder $container, $storage, $objectManager) { $container->setParameter('lexik_translation.storage.type', $storage); if ('orm' == $storage) { if (isset($objectManager)) { $objectManagerReference = new Reference(sprintf('doctrine.orm.%s_entity_manager', $objectManager)); } else { $objectManagerReference = new Reference('doctrine.orm.entity_manager'); } } else { if ('mongodb' == $storage) { if (isset($objectManager)) { $objectManagerReference = new Reference(sprintf('doctrine_mongodb.odm.%s_document_manager', $objectManager)); } else { $objectManagerReference = new Reference('doctrine.odm.mongodb.document_manager'); } } else { if ('propel' == $storage) { // In the Propel case the object_manager setting is used for the connection name if (isset($objectManager)) { $objectManagerReference = $objectManager; } else { $objectManagerReference = null; } } else { throw new \RuntimeException(sprintf('Unsupported storage "%s".', $storage)); } } } $storageDefinition = new Definition(); $storageDefinition->setClass(new Parameter(sprintf('lexik_translation.%s.translation_storage.class', $storage))); $storageDefinition->setArguments(array($objectManagerReference, array('trans_unit' => new Parameter(sprintf('lexik_translation.%s.trans_unit.class', $storage)), 'translation' => new Parameter(sprintf('lexik_translation.%s.translation.class', $storage)), 'file' => new Parameter(sprintf('lexik_translation.%s.file.class', $storage))))); $container->setDefinition('lexik_translation.translation_storage', $storageDefinition); }
/** * @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 testGetProxyFactoryCode() { $definition = new Definition(__CLASS__); $definition->setLazy(true); $code = $this->dumper->getProxyFactoryCode($definition, 'foo'); $this->assertStringMatchesFormat('%wif ($lazyLoad) {%wreturn $this->services[\'foo\'] = new ' . 'SymfonyBridgeProxyManagerTestsLazyProxyPhpDumperProxyDumperTest_%s(%wfunction ' . '(&$wrappedInstance, \\ProxyManager\\Proxy\\LazyLoadingInterface $proxy) {' . '%w$wrappedInstance = $this->getFooService(false);%w$proxy->setProxyInitializer(null);' . '%wreturn true;%w}%w);%w}%w', $code); }
/** * Configure the sitemap source manager. * * @param array $config * @param ContainerBuilder $container */ protected function configureSitemap(array $config, ContainerBuilder $container) { $source = $container->getDefinition('sonata.seo.sitemap.manager'); if (method_exists($source, 'setShared')) { // Symfony 2.8+ $source->setShared(false); } else { // For Symfony <2.8 compatibility $source->setScope(ContainerInterface::SCOPE_PROTOTYPE); } foreach ($config['doctrine_orm'] as $pos => $sitemap) { // define the connectionIterator $connectionIteratorId = 'sonata.seo.source.doctrine_connection_iterator_' . $pos; $connectionIterator = new Definition('%sonata.seo.exporter.database_source_iterator.class%', array(new Reference($sitemap['connection']), $sitemap['query'])); $connectionIterator->setPublic(false); $container->setDefinition($connectionIteratorId, $connectionIterator); // define the sitemap proxy iterator $sitemapIteratorId = 'sonata.seo.source.doctrine_sitemap_iterator_' . $pos; $sitemapIterator = new Definition('%sonata.seo.exporter.sitemap_source_iterator.class%', array(new Reference($connectionIteratorId), new Reference('router'), $sitemap['route'], $sitemap['parameters'])); $sitemapIterator->setPublic(false); $container->setDefinition($sitemapIteratorId, $sitemapIterator); $source->addMethodCall('addSource', array($sitemap['group'], new Reference($sitemapIteratorId), $sitemap['types'])); } foreach ($config['services'] as $service) { $source->addMethodCall('addSource', array($service['group'], new Reference($service['id']), $service['types'])); } }
public function process(ContainerBuilder $container) { // log $definition = $container->findDefinition('csa_guzzle.subscriber.log'); $logServiceId = $container->getParameter('csa_guzzle.subscriber.log.service'); if ($container->hasDefinition($logServiceId)) { $definition->replaceArgument(0, new Reference($logServiceId)); } $channel = $container->getParameter('csa_guzzle.subscriber.log.channel'); if (!empty($channel)) { $definition->clearTag('monolog.logger'); $definition->addTag('monolog.logger', array('channel' => $channel)); } // Cache $cacheServiceId = $container->getParameter('csa_guzzle.subscriber.cache.service'); if ($container->hasDefinition($cacheServiceId)) { $container->setDefinition('csa_guzzle.cache_storage', new Definition('%csa_guzzle.cache_storage.class%', array(new Reference($cacheServiceId), $container->getParameter('csa_guzzle.subscriber.cache.prefix')))); $cacheSubscriber = new Definition('%csa_guzzle.subscriber.cache.class%', array(new Reference('csa_guzzle.cache_storage'), $container->getParameter('csa_guzzle.subscriber.cache.enable'))); $cacheSubscriber->addTag('csa_guzzle.subscriber'); $container->setDefinition('csa_guzzle.subscriber.cache', $cacheSubscriber); } // get all Guzzle subscribers $subscribers = $container->findTaggedServiceIds('csa_guzzle.subscriber'); if (!count($subscribers)) { return; } // Factory $factory = $container->findDefinition('csa_guzzle.client_factory'); $arg = []; foreach ($subscribers as $subscriber => $options) { $arg[] = new Reference($subscriber); } $factory->replaceArgument(1, $arg); }