hasAlias() public method

Returns true if an alias exists under the given identifier.
public hasAlias ( string $id ) : boolean
$id string The service identifier
return boolean true if the alias exists, false otherwise
Example #1
0
 /**
  * @param string $id
  * @return string
  */
 public function definitionClass(string $id) : string
 {
     if ($this->builder->hasAlias($id)) {
         return $this->builder->getDefinition((string) $this->builder->getAlias($id))->getClass()->getClass();
     }
     return $this->builder->getDefinition($id)->getClass();
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     if ($container->hasParameter('default_backend')) {
         $default_backend = $container->getParameter('default_backend');
         // Opt out from the default backend.
         if (!$default_backend) {
             return;
         }
     } else {
         try {
             $default_backend = $container->get('database')->driver();
             $container->set('database', NULL);
         } catch (\Exception $e) {
             // If Drupal is not installed or a test doesn't define database there
             // is nothing to override.
             return;
         }
     }
     foreach ($container->findTaggedServiceIds('backend_overridable') as $id => $attributes) {
         // If the service is already an alias it is not the original backend, so
         // we don't want to fallback to other storages any longer.
         if ($container->hasAlias($id)) {
             continue;
         }
         if ($container->hasDefinition("{$default_backend}.{$id}") || $container->hasAlias("{$default_backend}.{$id}")) {
             $container->setAlias($id, new Alias("{$default_backend}.{$id}"));
         }
     }
 }
 public function process(ContainerBuilder $container)
 {
     // Cache warmer does more harm than good with Drupal.
     if ($container->hasDefinition('cache_warmer')) {
         $container->removeDefinition('cache_warmer');
     }
     if ($container->hasAlias('cache_warmer')) {
         $container->removeAlias('cache_warmer');
     }
     // When not working with symfony, we need to provide a file locator
     // service of our own instead of the symfony's one
     if (!$container->hasDefinition('file_locator') && !$container->hasAlias('file_locator')) {
         $container->addDefinitions(['file_locator' => (new Definition())->setClass(CustomFileLocator::class)->addArgument(new Reference('kernel'))]);
     } else {
         // We are working with fullstack, and our users might have changed
         // the global resource directory to somewhere safer than Drupal's
         // sites/SITE folder, case in which we must honnor the user's
         // configuration
         $definition = $container->getDefinition('file_locator');
         $definition->setArguments([new Reference('kernel'), $container->getParameter('kernel.root_dir') . '/Resources']);
     }
     // By registering the framework bundle, we also inherit from Symfony
     // default URL generator, which will cause us great pain because of
     // Drupal routes will not be known by the framework and throw a few
     // exceptions.
     if ($container->has('router.default')) {
         $container->getDefinition('router.default')->setClass('MakinaCorpus\\Drupal\\Sf\\Routing\\Router');
     }
     // When NOT in fullstack mode, we need to provide a null implementation
     // for the controller resolver service, else the container will be
     // unable to spawn the http kernel service
     if (!$container->has('controller_resolver')) {
         $container->addDefinitions(['controller_resolver' => (new Definition())->setClass('controller_resolver')]);
     }
 }
    public function process( ContainerBuilder $container )
    {
        if ( !$container->hasAlias( 'session.storage' ) )
        {
            return;
        }

        $sessionStorageAlias = $container->getAlias( 'session.storage' );
        $sessionStorageProxyDef = $container->findDefinition( 'ezpublish_legacy.session_storage_proxy' );
        $sessionStorageProxyDef->replaceArgument( 1, new Reference( (string)$sessionStorageAlias ) );
        $container->setAlias( 'session.storage', 'ezpublish_legacy.session_storage_proxy' );

        if ( $container->hasAlias( 'session.handler' ) )
        {
            $sessionHandlerAlias = $container->getAlias( 'session.handler' );
            $interfaces = class_implements( $container->findDefinition( (string)$sessionHandlerAlias ) );
            // Only swap session handler if it implements appropriate interface.
            if ( isset( $interfaces['SessionHandlerInterface'] ) )
            {
                $sessionHandlerProxyDef = $container->findDefinition( 'ezpublish_legacy.session_handler_proxy' );
                $sessionHandlerProxyDef->replaceArgument( 1, new Reference( (string)$sessionHandlerAlias ) );
                $container->setAlias( 'session.handler', 'ezpublish_legacy.session_handler_proxy' );
            }
        }
    }
 public function testNoDefaultPheanstalk()
 {
     $config = ['leezy_pheanstalk' => ['pheanstalks' => ['primary' => ['server' => 'beanstalkd.domain.tld', 'port' => 11300, 'timeout' => 60]]]];
     $this->extension->load($config, $this->container);
     $this->container->compile();
     $this->assertTrue($this->container->hasDefinition('leezy.pheanstalk.primary'));
     $this->assertFalse($this->container->hasAlias('leezy.pheanstalk'));
 }
 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     $handlers = $container->getParameter('monolog.swift_mailer.handlers');
     foreach ($handlers as $id) {
         $definition = $container->getDefinition($id);
         if ($container->hasAlias('swiftmailer.transport.real') || $container->hasDefinition('swiftmailer.transport.real')) {
             $definition->addMethodCall('setTransport', array(new Reference('swiftmailer.transport.real')));
         } elseif ($container->hasAlias('swiftmailer.transport') || $container->hasDefinition('swiftmailer.transport')) {
             $definition->addMethodCall('setTransport', array(new Reference('swiftmailer.transport')));
         }
     }
 }
 public function testCreateClients()
 {
     $config = array('zeichen32_git_lab_api' => array('clients' => array('firstclient' => array('token' => '12345', 'url' => 'http://example.org/api/v3/'), 'secondclient' => array('token' => '12345', 'url' => 'http://example.com/api/v3/'))));
     $this->extension->load($config, $this->container);
     $this->assertTrue($this->container->hasAlias('zeichen32_gitlabapi.client.default'));
     $this->assertTrue($this->container->has('gitlab_api'));
     $this->assertTrue($this->container->has('zeichen32_gitlabapi.client.firstclient'));
     $this->assertTrue($this->container->has('zeichen32_gitlabapi.client.secondclient'));
     $this->assertInstanceOf('Gitlab\\Client', $this->container->get('zeichen32_gitlabapi.client.default'));
     $this->assertInstanceOf('Gitlab\\Client', $this->container->get('zeichen32_gitlabapi.client.firstclient'));
     $this->assertInstanceOf('Gitlab\\Client', $this->container->get('zeichen32_gitlabapi.client.secondclient'));
     $this->assertNotSame($this->container->get('zeichen32_gitlabapi.client.firstclient'), $this->container->get('zeichen32_gitlabapi.client.secondclient'));
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!($container->hasDefinition($this->queueEngineService) || !$container->hasAlias($this->queueEngineService)) && !($container->hasDefinition($this->dispatcherService) || $container->hasAlias($this->dispatcherService))) {
         return;
     }
     $dispatcher = $container->getDefinition($this->dispatcherService);
     foreach ($container->findTaggedServiceIds($this->jobTag) as $id => $tags) {
         foreach ($tags as $tag) {
             // workaround
             $dispatcher->addMethodCall('addListenerService', array($tag['type'], array($this->queueEngineService, 'process')));
         }
     }
 }
Example #9
0
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasAlias('logger') || !$container->hasAlias('translator')) {
         return;
     }
     if ($container->hasParameter('translator.logging') && $container->getParameter('translator.logging')) {
         $translatorAlias = $container->getAlias('translator');
         $definition = $container->getDefinition((string) $translatorAlias);
         $class = $container->getParameterBag()->resolveValue($definition->getClass());
         if (is_subclass_of($class, 'Symfony\\Component\\Translation\\TranslatorInterface') && is_subclass_of($class, 'Symfony\\Component\\Translation\\TranslatorBagInterface')) {
             $container->getDefinition('translator.logging')->setDecoratedService('translator');
             $container->getDefinition('translation.warmer')->replaceArgument(0, new Reference('translator.logging.inner'));
         }
     }
 }
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasAlias('logger') || !$container->hasAlias('translator')) {
         return;
     }
     if ($container->getParameter('translator.logging')) {
         $translatorAlias = $container->getAlias('translator');
         $definition = $container->getDefinition((string) $translatorAlias);
         $class = $container->getParameterBag()->resolveValue($definition->getClass());
         $refClass = new \ReflectionClass($class);
         if ($refClass->implementsInterface('Symfony\\Component\\Translation\\TranslatorInterface') && $refClass->implementsInterface('Symfony\\Component\\Translation\\TranslatorBagInterface')) {
             $container->getDefinition('translator.logging')->setDecoratedService('translator');
         }
     }
 }
 /**
  * @param ContainerBuilder $container
  * @param $serviceName
  * @param $className
  * @return $this
  */
 protected function setDefinition(ContainerBuilder $container, $serviceName, $className)
 {
     if (!$container->hasDefinition($serviceName) && !$container->hasAlias($serviceName)) {
         $container->setDefinition($serviceName, new Definition($className));
     }
     return $this;
 }
Example #12
0
 public function process(ContainerBuilder $container)
 {
     $clearSpoolsId = 'long_running.swift_mailer.clear_spools';
     if (!$container->has($clearSpoolsId)) {
         return;
     }
     if (!$container->hasAlias('swiftmailer.mailer') || $container->getParameter('swiftmailer.mailers') === []) {
         return;
     }
     $spoolServiceReferences = [];
     $realTransportServiceReferences = [];
     $mailers = $container->getParameter('swiftmailer.mailers');
     foreach ($mailers as $name => $mailer) {
         if ($container->getParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name))) {
             $transport = sprintf('swiftmailer.mailer.%s.transport', $name);
             $transportDefinition = $container->findDefinition($transport);
             if (is_a($transportDefinition->getClass(), 'Swift_Transport_SpoolTransport', true)) {
                 $spool = sprintf('swiftmailer.mailer.%s.spool', $name);
                 $spoolDefinition = $container->findDefinition($spool);
                 if (is_a($spoolDefinition->getClass(), 'Swift_MemorySpool', true)) {
                     $realTransport = sprintf('swiftmailer.mailer.%s.transport.real', $name);
                     $spoolServiceReferences[$name] = new Reference($spool);
                     $realTransportServiceReferences[$name] = new Reference($realTransport);
                 }
             }
         }
     }
     $definition = $container->getDefinition($clearSpoolsId);
     $definition->replaceArgument(0, $spoolServiceReferences);
     $definition->replaceArgument(1, $realTransportServiceReferences);
 }
 public function process(ContainerBuilder $container)
 {
     // "query.max_query_count" is an array, it is only accessible
     // through "query" node and getting the "max_query_count" array
     // key with PHP.
     $query = $container->getParameter('liip_functional_test.query');
     if (null === $query['max_query_count']) {
         $container->removeDefinition('liip_functional_test.query.count_client');
         return;
     }
     if ($container->hasDefinition('test.client')) {
         // test.client is a definition.
         // Register it again as a private service to inject it as the parent
         $definition = $container->getDefinition('test.client');
         $definition->setPublic(false);
         $container->setDefinition('liip_functional_test.query.count_client.parent', $definition);
     } elseif ($container->hasAlias('test.client')) {
         // test.client is an alias.
         // Register a private alias for this service to inject it as the parent
         $container->setAlias('liip_functional_test.query.count_client.parent', new Alias((string) $container->getAlias('test.client'), false));
     } else {
         throw new \Exception('The LiipFunctionalTestBundle\'s Query Counter can only be used in the test environment.' . PHP_EOL . 'See https://github.com/liip/LiipFunctionalTestBundle#only-in-test-environment');
     }
     $container->setAlias('test.client', 'liip_functional_test.query.count_client');
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $tags = $container->findTaggedServiceIds($this->tagName);
     foreach ($tags as $id => $tag) {
         /** @var Definition $serviceLinkDef */
         $serviceLinkDef = $container->getDefinition($id);
         if (!isset($tag[0]['service'])) {
             throw new InvalidArgumentException(sprintf('Tag "%s" for service "%s" does not have required param "service"', $this->tagName, $id));
         }
         $serviceId = $tag[0]['service'];
         $isOptional = false;
         if (strpos($serviceId, '?') === 0) {
             $serviceId = substr($serviceId, 1);
             $isOptional = true;
         }
         if ($container->hasDefinition($serviceId)) {
             // the service we are referring to must be public
             $serviceDef = $container->getDefinition($serviceId);
             if (!$serviceDef->isPublic()) {
                 $serviceDef->setPublic(true);
             }
         } elseif ($container->hasAlias($serviceId)) {
             // the service alias we are referring to must be public
             $serviceAlias = $container->getAlias($serviceId);
             if (!$serviceAlias->isPublic()) {
                 $serviceAlias->setPublic(true);
             }
         } elseif (!$isOptional) {
             throw new InvalidArgumentException(sprintf('Target service "%s" is undefined. The service link "%s" with tag "%s" and tag-service "%s"', $serviceId, $id, $this->tagName, $serviceId));
         }
         $serviceLinkDef->setClass($this->decoratorClass)->setPublic(false)->setArguments([new Reference('service_container'), $serviceId, $isOptional]);
     }
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $tags = $container->findTaggedServiceIds(self::TAG_NAME);
     foreach ($tags as $id => $tag) {
         /** @var Definition $serviceLinkDef */
         $serviceLinkDef = $container->getDefinition($id);
         if (!isset($tag[0]['service'])) {
             throw new RuntimeException(sprintf('Tag "%s" for service "%s" does not have required param "service"', self::TAG_NAME, $id));
         }
         $serviceId = $tag[0]['service'];
         $isOptional = false;
         if (strpos($serviceId, '?') === 0) {
             $serviceId = substr($serviceId, 1);
             $isOptional = true;
         }
         if ($container->hasDefinition($serviceId)) {
             // the service we are referring to must be public
             $serviceDef = $container->getDefinition($serviceId);
             if (!$serviceDef->isPublic()) {
                 $serviceDef->setPublic(true);
             }
         } elseif ($container->hasAlias($serviceId)) {
             // the service alias we are referring to must be public
             $serviceAlias = $container->getAlias($serviceId);
             if (!$serviceAlias->isPublic()) {
                 $serviceAlias->setPublic(true);
             }
         } elseif (!$isOptional) {
             throw new RuntimeException(sprintf('Target service "%s" is undefined. The service link "%s" with tag "%s" and tag-service "%s"', $serviceId, $id, self::TAG_NAME, $serviceId));
         }
         $serviceLinkDef->setClass('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->setPublic(false)->setArguments([new Reference('service_container'), $serviceId, $isOptional]);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasDefinition($this->registryService) && !$container->hasAlias($this->registryService)) {
         return;
     }
     $customLogLevels = $container->getParameter('abc.job.logging.level');
     $registry = $container->findDefinition('abc.job.registry');
     foreach ($container->findTaggedServiceIds($this->jobTag) as $id => $tags) {
         $def = $container->getDefinition($id);
         if (!$def->isPublic()) {
             throw new \InvalidArgumentException(sprintf('The service "%s" must be public as jobs are lazy-loaded.', $id));
         }
         foreach ($tags as $tag) {
             if (!isset($tag['type'])) {
                 throw new \InvalidArgumentException(sprintf('Service "%s" must define the "type" attribute on "%s" tags.', $id, $this->jobTag));
             }
             if (!isset($tag['method'])) {
                 throw new \InvalidArgumentException(sprintf('Service "%s" must define the "method" attribute on "%s" tags.', $id, $this->jobTag));
             }
             $logLevel = isset($customLogLevels[$tag['type']]) ? $this->levelToMonologConst($customLogLevels[$tag['type']]) : null;
             $jobTypeId = 'abc.job.type.' . $tag['type'];
             $definition = $this->createType($id, $tag['type'], array(new Reference($id), $tag['method']), $logLevel);
             $container->setDefinition($jobTypeId, $definition);
             $registry->addMethodCall('register', array(new Reference($jobTypeId), true));
         }
     }
     // there as a reason this listener was registered here, what was it?
     if ($container->hasParameter('abc.job.adapter') && $container->getParameter('abc.job.adapter') == 'sonata') {
         $pass = new RegisterSonataListenersPass();
         $pass->process($container);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $configuration = $container->getParameter('knp_rad_auto_registration.configuration');
     $enable = $configuration['enable'];
     $generator = $container->get('knp_rad_auto_registration.service_name_generator.bundle_service_name_generator');
     foreach ($container->findTaggedServiceIds('knp_rad_auto_registration.definition_builder') as $id => $tags) {
         $builder = $container->get($id);
         if (false === $builder->isActive()) {
             continue;
         }
         if (false === in_array($builder->getName(), $this->sections)) {
             continue;
         }
         if (false === array_key_exists($builder->getName(), $enable)) {
             continue;
         }
         $definitions = $builder->buildDefinitions($enable[$builder->getName()]);
         foreach ($definitions as $class => $definition) {
             $serviceId = $generator->generateFromClassname($class);
             if (true === $container->hasDefinition($serviceId)) {
                 continue;
             }
             if (true === $container->hasAlias($serviceId)) {
                 continue;
             }
             $container->setDefinition($serviceId, $definition);
         }
     }
 }
 public function process(ContainerBuilder $container)
 {
     $definitions = new \SplPriorityQueue();
     $order = PHP_INT_MAX;
     foreach ($container->getDefinitions() as $id => $definition) {
         if (!($decorated = $definition->getDecoratedService())) {
             continue;
         }
         $definitions->insert(array($id, $definition), array($decorated[2], --$order));
     }
     foreach ($definitions as list($id, $definition)) {
         list($inner, $renamedId) = $definition->getDecoratedService();
         $definition->setDecoratedService(null);
         if (!$renamedId) {
             $renamedId = $id . '.inner';
         }
         // we create a new alias/service for the service we are replacing
         // to be able to reference it in the new one
         if ($container->hasAlias($inner)) {
             $alias = $container->getAlias($inner);
             $public = $alias->isPublic();
             $container->setAlias($renamedId, new Alias((string) $alias, false));
         } else {
             $definition = $container->getDefinition($inner);
             $public = $definition->isPublic();
             $definition->setPublic(false);
             $container->setDefinition($renamedId, $definition);
         }
         $container->setAlias($inner, new Alias($id, $public));
     }
 }
 /**
  * Populate the listener service ids
  *
  * @param ContainerBuilder $container
  */
 public function process(ContainerBuilder $container)
 {
     // use main symfony dispatcher
     if (!$container->hasDefinition('event_dispatcher') && !$container->hasAlias('event_dispatcher')) {
         return;
     }
     $definition = $container->findDefinition('event_dispatcher');
     foreach ($container->findTaggedServiceIds('knp_paginator.subscriber') as $id => $attributes) {
         // We must assume that the class value has been correctly filled, even if the service is created by a factory
         $class = $container->getDefinition($id)->getClass();
         $refClass = new \ReflectionClass($class);
         $interface = 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface';
         if (!$refClass->implementsInterface($interface)) {
             throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
         }
         foreach ($class::getSubscribedEvents() as $event => $options) {
             if (!is_array($options)) {
                 $options = array($options, 0);
             }
             $definition->addMethodCall('addListenerService', array($event, array($id, $options[0]), $options[1]));
         }
         // sf 2.1.x only
         //$definition->addMethodCall('addSubscriberService', array($id, $class));
     }
 }
 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$this->integrationExtension->isTransactionalAutoGenerateProxy()) {
         // Transactional system or auto generate proxy is disabled
         return;
     }
     $transactionalId = $this->integrationExtension->getTransactionalService();
     // Validate transactional service
     $transactionalDefinition = $container->getDefinition($transactionalId);
     $class = $transactionalDefinition->getClass();
     try {
         $class = $container->getParameterBag()->resolveValue($class);
         $refClass = new \ReflectionClass($class);
         $requiredInterface = 'FivePercent\\Component\\Transactional\\TransactionalInterface';
         if (!$refClass->implementsInterface($requiredInterface)) {
             throw new \RuntimeException(sprintf('The transactional service with class "%s" should implement %s.', $class, $requiredInterface));
         }
     } catch (\Exception $e) {
         throw new \RuntimeException(sprintf('The transactional service with id "%s" is invalid.', $transactionalId), 0, $e);
     }
     // Get all services
     $serviceIds = $container->getServiceIds();
     $directory = $container->getParameter('kernel.cache_dir') . '/transactional';
     foreach ($serviceIds as $serviceId) {
         if ($container->hasAlias($serviceId)) {
             // Not check in alias.
             continue;
         }
         $serviceDefinition = $container->getDefinition($serviceId);
         if ($serviceDefinition->isAbstract()) {
             // Not check in abstract service.
             continue;
         }
         $class = $serviceDefinition->getClass();
         $class = $container->getParameterBag()->resolveValue($class);
         if (!$class) {
             continue;
         }
         try {
             $proxyCodeGenerator = new ProxyFileGenerator($directory, $class);
         } catch (\ReflectionException $e) {
             $container->getCompiler()->addLogMessage(sprintf('%s Error with create proxy code generator for class "%s". Maybe class not found?', get_class($this), $class));
             continue;
         }
         if ($proxyCodeGenerator->needGenerate()) {
             // Generate proxy file
             $filePath = $proxyCodeGenerator->generate();
             $serviceDefinition->setClass($proxyCodeGenerator->getProxyClassName());
             // Add "__setTransactional" method call for set transactional layer
             $methodCalls = $serviceDefinition->getMethodCalls();
             array_unshift($methodCalls, ['___setTransactional', [new Reference($transactionalId)]]);
             $serviceDefinition->setMethodCalls($methodCalls);
             // Add resource for control cache
             $container->addResource(new FileResource($filePath));
             $realClassReflection = new \ReflectionClass($class);
             $container->addResource(new FileResource($realClassReflection->getFileName()));
         }
     }
 }
Example #21
0
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition($this->dispatcherService) && !$container->hasAlias($this->dispatcherService)) {
return;
}

$definition = $container->findDefinition($this->dispatcherService);

foreach ($container->findTaggedServiceIds($this->listenerTag) as $id => $events) {
$def = $container->getDefinition($id);
if (!$def->isPublic()) {
throw new \InvalidArgumentException(sprintf('The service "%s" must be public as event listeners are lazy-loaded.', $id));
}

if ($def->isAbstract()) {
throw new \InvalidArgumentException(sprintf('The service "%s" must not be abstract as event listeners are lazy-loaded.', $id));
}

foreach ($events as $event) {
$priority = isset($event['priority']) ? $event['priority'] : 0;

if (!isset($event['event'])) {
throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $id, $this->listenerTag));
}

if (!isset($event['method'])) {
$event['method'] = 'on'.preg_replace_callback(array(
'/(?<=\b)[a-z]/i',
'/[^a-z0-9]/i',
), function ($matches) { return strtoupper($matches[0]); }, $event['event']);
$event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
}

$definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority));
}
}

foreach ($container->findTaggedServiceIds($this->subscriberTag) as $id => $attributes) {
$def = $container->getDefinition($id);
if (!$def->isPublic()) {
throw new \InvalidArgumentException(sprintf('The service "%s" must be public as event subscribers are lazy-loaded.', $id));
}

if ($def->isAbstract()) {
throw new \InvalidArgumentException(sprintf('The service "%s" must not be abstract as event subscribers are lazy-loaded.', $id));
}


 $class = $container->getParameterBag()->resolveValue($def->getClass());

$refClass = new \ReflectionClass($class);
$interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
if (!$refClass->implementsInterface($interface)) {
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
}

$definition->addMethodCall('addSubscriberService', array($id, $class));
}
}
 public function process(ContainerBuilder $container)
 {
     if (false === $container->hasDefinition('sms.sender') || false === $container->hasAlias('sms.pool')) {
         return;
     }
     $delayedDefinition = new Definition($container->getParameter('sms.delayed_sender.class'), array($container->getDefinition('sms.sender'), new Reference('sms.pool')));
     $container->setDefinition('sms.sender', $delayedDefinition);
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasAlias('oauth2_server.refresh_token.manager')) {
         return;
     }
     $definition = $container->getDefinition('oauth2_server.token_endpoint');
     $definition->addMethodCall('enabledRefreshTokenSupport', [new Reference('oauth2_server.refresh_token.manager')]);
 }
 public function testProcess()
 {
     $builder = new ContainerBuilder();
     $builder->setParameter(ModeraBackendSecurityExtension::CONFIG_KEY, array('mail_service' => 'some_service_id'));
     $this->assertFalse($builder->hasAlias('modera_backend_security.service.mail_service'));
     $cp = new ServiceAliasCompilerPass();
     $cp->process($builder);
     $this->assertEquals('some_service_id', $builder->getAlias('modera_backend_security.service.mail_service'));
 }
 public function testProcess()
 {
     $builder = new ContainerBuilder();
     $builder->setParameter(ModeraActivityLoggerExtension::CONFIG_KEY, array('activity_manager' => 'some_service_id'));
     $this->assertFalse($builder->hasAlias('modera_activity_logger.manager.activity_manager'));
     $cp = new ServiceAliasCompilerPass();
     $cp->process($builder);
     $this->assertEquals('some_service_id', $builder->getAlias('modera_activity_logger.manager.activity_manager'));
 }
Example #26
0
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasAlias('security.acl.provider') && !$container->hasDefinition('security.acl.provider')) {
         $container->removeDefinition('security.acl.permission_evaluator');
     }
     if ($container->hasDefinition('security.role_hierarchy')) {
         $container->getDefinition('security.role_hierarchy')->setPublic(true);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $default_backend = $container->hasParameter('default_backend') ? $container->getParameter('default_backend') : NULL;
     // No default backend was configured, so continue as normal.
     if (!isset($default_backend)) {
         return;
     }
     foreach ($container->findTaggedServiceIds('backend_overridable') as $id => $attributes) {
         // If the service is already an alias it is not the original backend, so
         // we don't want to fallback to other storages any longer.
         if ($container->hasAlias($id)) {
             continue;
         }
         if ($container->hasDefinition("{$default_backend}.{$id}") || $container->hasAlias("{$default_backend}.{$id}")) {
             $container->setAlias($id, new Alias("{$default_backend}.{$id}"));
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasDefinition($this->enrichingStreamDecoratorServiceId) && !$container->hasAlias($this->enrichingStreamDecoratorServiceId)) {
         throw new RuntimeException(sprintf('Unknown Stream Decorator service known as %s', $this->enrichingStreamDecoratorServiceId));
     }
     $definition = $container->findDefinition($this->enrichingStreamDecoratorServiceId);
     foreach ($container->findTaggedServiceIds($this->enricherTag) as $id => $attributes) {
         $definition->addMethodCall('registerEnricher', array(new Reference($id)));
     }
 }
 /**
  * Returns the definition of the provided service.
  *
  * This method also resolves aliases.
  *
  * @param ContainerBuilder $container
  * @param string $id
  * @return \Symfony\Component\DependencyInjection\Definition|null
  */
 protected function getDefinition(ContainerBuilder $container, $id)
 {
     while ($container->hasAlias($id)) {
         $id = (string) $container->getAlias($id);
     }
     if (!$container->hasDefinition($id)) {
         return null;
     }
     return $container->getDefinition($id);
 }
 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasDefinition($this->eventDispatcherId) && !$container->hasAlias($this->eventDispatcherId)) {
         throw new RuntimeException(sprintf('Unknown Event Dispatcher service known as %s', $this->eventDispatcherId));
     }
     $definition = $container->findDefinition($this->eventDispatcherId);
     foreach ($container->findTaggedServiceIds($this->serviceTag) as $id => $attributes) {
         $this->processListenerDefinition($container, $definition, $id);
     }
 }