has() публичный Метод

Returns true if the given service is defined.
public has ( string $id ) : boolean
$id string The service identifier
Результат boolean true if the service is defined, false otherwise
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $container->getParameterBag()->remove('cache.prefix.seed');
     foreach ($container->findTaggedServiceIds('cache.pool') as $id => $attributes) {
         foreach (array_reverse($attributes) as $attr) {
             if (isset($attr['clearer'])) {
                 $clearer = $container->getDefinition($attr['clearer']);
                 $clearer->addMethodCall('addPool', array(new Reference($id)));
             }
             if (array_key_exists('clearer', $attr)) {
                 break;
             }
         }
     }
     if (!$container->has('cache.annotations')) {
         return;
     }
     $factory = array(AbstractAdapter::class, 'createSystemCache');
     $annotationsPool = $container->getDefinition('cache.annotations');
     if ($factory !== $annotationsPool->getFactory() || 4 !== count($annotationsPool->getArguments())) {
         return;
     }
     if ($container->has('monolog.logger.cache')) {
         $annotationsPool->addArgument(new Reference('monolog.logger.cache'));
     } elseif ($container->has('cache.system')) {
         $systemPool = $container->getDefinition('cache.system');
         if ($factory === $systemPool->getFactory() && 5 <= count($systemArgs = $systemPool->getArguments())) {
             $annotationsPool->addArgument($systemArgs[4]);
         }
     }
 }
 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->hasDefinition('json_schema.registry') || !$container->has('annotation_reader') || !$container->has('json_schema.reflection_factory')) {
         return;
     }
     $registry = $container->getDefinition('json_schema.registry');
     $reader = $container->get('annotation_reader');
     $factory = $container->get('json_schema.reflection_factory');
     $mappings = $container->getParameter('json_schema.mappings');
     foreach ($mappings as $mapping) {
         if (isset($mapping['dir']) && isset($mapping['prefix'])) {
             /** @var \ReflectionClass[] $refClasses */
             $refClasses = $factory->createFromDirectory($mapping['dir'], $mapping['prefix']);
             foreach ($refClasses as $refClass) {
                 foreach ($reader->getClassAnnotations($refClass) as $annotation) {
                     if ($annotation instanceof \Knp\JsonSchemaBundle\Annotations\Schema) {
                         $alias = $annotation->name ?: strtolower($refClass->getShortName());
                         $registry->addMethodCall('register', [$alias, $refClass->getName()]);
                     }
                 }
             }
         } elseif (isset($mapping['class'])) {
             $refClass = new \ReflectionClass($mapping['class']);
             foreach ($reader->getClassAnnotations($refClass) as $annotation) {
                 if ($annotation instanceof \Knp\JsonSchemaBundle\Annotations\Schema) {
                     $alias = $annotation->name ?: strtolower($refClass->getShortName());
                     $registry->addMethodCall('register', [$alias, $refClass->getName()]);
                 }
             }
         } else {
             throw new \RuntimeException("Invalid mapping configuration!");
         }
     }
 }
 /**
  * Test load extension
  * @throws \LogicException
  * @throws \Symfony\Component\DependencyInjection\Exception\BadMethodCallException
  */
 public function testLoadExtension()
 {
     $this->container->loadFromExtension($this->extension->getAlias());
     $this->container->compile();
     // Check that services have been loaded
     static::assertTrue($this->container->has('timestamp.type'));
 }
 /**
  * Tests the rest client configuration
  *
  * @test
  *
  * @covers Ci\RestClientBundle\DependencyInjection\CiRestClientExtension::load
  * @covers Ci\RestClientBundle\DependencyInjection\Configuration::getConfigTreeBuilder
  */
 public function restClientConfig()
 {
     $this->loadConfiguration($this->container);
     $this->container->compile();
     $this->assertTrue($this->container->has('ci.restclient'));
     $this->assertInstanceOf('Ci\\RestClientBundle\\Services\\RestClient', $this->container->get('ci.restclient'));
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     if ($container->has(self::ROUTING_LOADER_SERVICE) && $container->has(self::REST_ROUTING_LOADER_SERVICE)) {
         $this->replaceAnnotationReader($container, self::ROUTING_LOADER_SERVICE, 0);
         $this->replaceAnnotationReader($container, self::REST_ROUTING_LOADER_SERVICE, 0);
     }
 }
Пример #7
0
 public function testReconnectConfiguration()
 {
     $this->initContainer();
     $this->loadConfiguration($this->container, 'reconnect_config');
     $this->container->compile();
     $this->assert->boolean($this->container->has('m6_redis'))->isIdenticalTo(true)->and()->object($serviceRedis = $this->container->get('m6_redis'))->isInstanceOf('M6Web\\Bundle\\RedisBundle\\Redis\\Redis');
 }
 public function process(ContainerBuilder $container)
 {
     if ($container->has('fos_rest.serializer')) {
         $class = $container->getParameterBag()->resolveValue($container->findDefinition('fos_rest.serializer')->getClass());
         if (!is_subclass_of($class, 'FOS\\RestBundle\\Serializer\\Serializer')) {
             throw new \InvalidArgumentException(sprintf('"fos_rest.serializer" must implement FOS\\RestBundle\\Serializer\\Serializer (instance of "%s" given).', $class));
         }
         return;
     }
     if (!$container->has('serializer') && !$container->has('jms_serializer.serializer')) {
         throw new \InvalidArgumentException('Neither a service called "jms_serializer.serializer" nor "serializer" is available and no serializer is explicitly configured. You must either enable the JMSSerializerBundle, enable the FrameworkBundle serializer or configure a custom serializer.');
     }
     if ($container->has('serializer')) {
         $class = $container->getParameterBag()->resolveValue($container->findDefinition('serializer')->getClass());
         if (is_subclass_of($class, 'Symfony\\Component\\Serializer\\SerializerInterface')) {
             $container->setAlias('fos_rest.serializer', 'fos_rest.serializer.symfony');
             $container->removeDefinition('fos_rest.serializer.exception_wrapper_serialize_handler');
         } elseif (is_subclass_of($class, 'JMS\\Serializer\\SerializerInterface')) {
             $container->setAlias('fos_rest.serializer', 'fos_rest.serializer.jms');
         } elseif (is_subclass_of($class, 'FOS\\RestBundle\\Serializer\\Serializer')) {
             $container->setAlias('fos_rest.serializer', 'serializer');
         } else {
             throw new \InvalidArgumentException(sprintf('"fos_rest.serializer" must implement FOS\\RestBundle\\Serializer\\Serializer (instance of "%s" given).', $class));
         }
         return;
     } else {
         $container->removeDefinition('fos_rest.serializer.exception_wrapper_normalizer');
     }
     if ($container->has('jms_serializer.serializer')) {
         $container->setAlias('fos_rest.serializer', 'fos_rest.serializer.jms');
     } else {
         $container->removeDefinition('fos_rest.serializer.exception_wrapper_serialize_handler');
     }
 }
Пример #9
0
 public function process(ContainerBuilder $container)
 {
     $tags = $container->findTaggedServiceIds('cmf_media.upload_editor_helper');
     if (count($tags) > 0) {
         if ($container->has('cmf_media.upload_file_helper')) {
             $manager = $container->findDefinition('cmf_media.upload_file_helper');
             foreach ($tags as $id => $tag) {
                 $manager->addMethodCall('addEditorHelper', array($tag[0]['alias'], new Reference($id)));
             }
         }
         if ($container->has('cmf_media.upload_image_helper')) {
             $manager = $container->findDefinition('cmf_media.upload_image_helper');
             foreach ($tags as $id => $tag) {
                 $manager->addMethodCall('addEditorHelper', array($tag[0]['alias'], new Reference($id)));
             }
         }
     }
     $tags = $container->findTaggedServiceIds('cmf_media.browser_file_helper');
     if (count($tags) > 0) {
         if ($container->has('cmf_media.browser_file_helper')) {
             $manager = $container->findDefinition('cmf_media.browser_file_helper');
             foreach ($tags as $id => $tag) {
                 $manager->addMethodCall('addEditorHelper', array($tag[0]['editor'], $tag[0]['browser'], new Reference($id)));
             }
         }
     }
 }
Пример #10
0
 public function process(ContainerBuilder $container)
 {
     $fingersCrossedHandlersId = 'long_running.monolog.clear_fingers_crossed_handlers';
     if ($container->has($fingersCrossedHandlersId)) {
         $fingersCrossedServiceReferences = [];
         foreach ($container->getDefinitions() as $serviceId => $definition) {
             if (strpos($serviceId, 'monolog.handler.') === 0) {
                 $class = $container->getParameterBag()->resolveValue($definition->getClass());
                 if (is_a($class, 'Monolog\\Handler\\FingersCrossedHandler', true)) {
                     $fingersCrossedServiceReferences[] = new Reference($serviceId);
                 }
             }
         }
         $definition = $container->getDefinition($fingersCrossedHandlersId);
         $definition->replaceArgument(0, $fingersCrossedServiceReferences);
     }
     $bufferHandlersId = 'long_running.monolog.close_buffer_handlers';
     if ($container->has($bufferHandlersId)) {
         $bufferHandlerServiceReferences = [];
         foreach ($container->getDefinitions() as $serviceId => $definition) {
             if (strpos($serviceId, 'monolog.handler.') === 0) {
                 $class = $container->getParameterBag()->resolveValue($definition->getClass());
                 if (is_a($class, 'Monolog\\Handler\\BufferHandler', true)) {
                     $bufferHandlerServiceReferences[] = new Reference($serviceId);
                 }
             }
         }
         $definition = $container->getDefinition($bufferHandlersId);
         $definition->replaceArgument(0, $bufferHandlerServiceReferences);
     }
 }
 /**
  * Test load extension
  */
 public function testLoadExtension()
 {
     $this->container->prependExtensionConfig($this->extension->getAlias(), ['login' => 'XXX']);
     $this->container->loadFromExtension($this->extension->getAlias());
     $this->container->compile();
     // Check that services have been loaded
     $this->assertTrue($this->container->has('hellosign.client'));
 }
Пример #12
0
 /**
  * Build service.
  *
  * Builds event servicehandlers.  If the service does not exist, it creates it
  * and adds it to the DI container.
  *
  * @param string $id
  * @param string $className
  * @param string $method
  *
  * @return array array($id, $method)
  */
 public function buildService($id, $className, $method)
 {
     if (!$this->container->has($id)) {
         $definition = new Definition($className, array(new Reference($this->serviceId)));
         $this->container->setDefinition($id, $definition);
     }
     return array($id, $method);
 }
Пример #13
0
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$container->has('logger') || !$container->has('fos_http_cache.event_listener.log')) {
         return;
     }
     $subscriber = $container->getDefinition('fos_http_cache.event_listener.log')->setAbstract(false);
     $container->getDefinition('fos_http_cache.cache_manager')->addMethodCall('addSubscriber', array($subscriber));
 }
 public function testEmptyConfigUsesDefaultValuesAndServicesAreCreated()
 {
     $this->container->setParameter('excepciones', array('email_admin_contact' => '*****@*****.**'));
     $this->extension->load(array(), $this->container);
     $this->assertTrue($this->container->hasParameter('excp_excepciones_bundle'));
     $this->assertTrue(array_key_exists('excepciones', $this->container->getParameter('excp_excepciones_bundle')));
     $this->assertTrue($this->container->has('kernel.excepciones.listener'));
 }
 public function testShouldConfigureCoreSerializer()
 {
     $this->container->register('serializer', 'Symfony\\Component\\Serializer\\Serializer');
     $this->container->register('fos_rest.serializer.exception_wrapper_serialize_handler');
     $compiler = new SerializerConfigurationPass();
     $compiler->process($this->container);
     $this->assertSame('fos_rest.serializer.symfony', (string) $this->container->getAlias('fos_rest.serializer'));
     $this->assertTrue(!$this->container->has('fos_rest.serializer.exception_wrapper_serialize_handler'));
 }
 public function process(ContainerBuilder $container)
 {
     if ($container->has('sensio_framework_extra.view.listener') && $container->has('fos_rest.view_response_listener')) {
         throw new \RuntimeException('You need to disable the view annotations in SensioFrameworkExtraBundle when using the FOSRestBundle View Response listener. Add "view: { annotations: false }" to the sensio_framework_extra: section of your config.yml');
     }
     if ($container->has('fos_rest.converter.request_body') && !$container->has('sensio_framework_extra.converter.listener')) {
         throw new \RuntimeException('You need to enable the parameter converter listeners in SensioFrameworkExtraBundle when using the FOSRestBundle RequestBodyParamConverter');
     }
 }
Пример #17
0
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $definition = $container->getDefinition('liip.translation.security');
     if ($container->has('security.authorization_checker')) {
         $definition->addArgument(new Reference('security.authorization_checker'));
     } elseif ($container->has('security.context')) {
         $definition->addArgument(new Reference('security.context'));
     }
 }
 /**
  * Override the default LiipThemeBundle services by the ones in this bundle
  *
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     if ($container->has('liip_theme.theme_controller') && $container->has('liip_theme_provider.theme_controller')) {
         $container->setDefinition('liip_theme.theme_controller', $container->getDefinition('liip_theme_provider.theme_controller'));
     }
     if ($container->has('liip_theme.active_theme') && $container->has('liip_theme_provider.active_theme')) {
         $container->setDefinition('liip_theme.active_theme', $container->getDefinition('liip_theme_provider.active_theme'));
     }
 }
Пример #19
0
 public function process(ContainerBuilder $container)
 {
     if ($container->has('fos_rest.exception_listener') && $container->has('twig.exception_listener')) {
         $container->removeDefinition('twig.exception_listener');
     }
     if (!$container->has('templating.engine.twig')) {
         $container->removeDefinition('fos_rest.exception.twig_controller');
     }
 }
Пример #20
0
 public function testProcessMissingPriorityTag()
 {
     $this->setExpectedException(\InvalidArgumentException::class);
     $pass = new DecorateRouterPass();
     $this->container->setParameter('iltar_http.router.enabled', true);
     $this->container->register('app.henk')->setClass('stdClass')->addTag('router.parameter_resolver');
     $pass->process($this->container);
     self::assertTrue($this->container->has('iltar_http.parameter_resolving_router'));
     self::assertTrue($this->container->has('iltar_http.parameter_resolver.app.henk'));
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$container->has(self::ROLE_PROVIDER_SERVICE)) {
         return;
     }
     if (!$container->has('security.token_storage') && $container->has('security.context')) {
         $definition = $container->getDefinition(self::ROLE_PROVIDER_SERVICE);
         $definition->replaceArgument(0, new Reference('security.context'));
     }
 }
 public function process(ContainerBuilder $container)
 {
     // DoctrineBundle
     if (!$container->has('doctrine')) {
         throw new \RuntimeException('You need to enable the DoctrineBundle');
     }
     // AbcSchedulerBundle
     if (!$container->has('abc.scheduler.scheduler')) {
         throw new \RuntimeException('You need to enable the AbcSchedulerBundle');
     }
 }
 private function decorateService($serviceId, $lockId)
 {
     $synchronizedServiceId = sprintf('synchronized.%s', $serviceId);
     if ($this->container->has($synchronizedServiceId)) {
         $definition = $this->container->findDefinition($synchronizedServiceId);
     } else {
         $definition = $this->container->register($synchronizedServiceId, 'Sms\\SynchronizedBundle\\Decorator');
         $definition->addArgument(new Reference(sprintf('%s.inner', $synchronizedServiceId)))->addArgument($serviceId)->setPublic(false)->setDecoratedService($serviceId);
     }
     $definition->addMethodCall('addLock', array(new Reference($lockId)));
 }
Пример #24
0
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     if ($container->has('fos_http_cache.event_listener.tag')
         && !$container->has('sensio_framework_extra.controller.listener')
     ) {
         throw new \RuntimeException(
             'Tag support requires SensioFrameworkExtraBundle’s ControllerListener for the annotations. '
             . 'Please install sensio/framework-extra-bundle and add it to your AppKernel.'
         );
     }
 }
Пример #25
0
 public function testServicesSetUp()
 {
     $this->assertTrue($this->container->has('finite.factory'));
     $this->assertTrue($this->container->has('finite.state_machine'));
     $this->assertSame('prototype', $this->container->getDefinition('finite.state_machine')->getScope());
     $this->assertFalse($this->container->hasDefinition('finite.array_loader'));
     $this->assertTrue($this->container->hasDefinition('finite.loader.workflow1'));
     $this->assertTrue($this->container->hasDefinition('finite.context'));
     $this->assertTrue($this->container->hasDefinition('finite.twig_extension'));
     $this->assertTrue($this->container->getDefinition('finite.loader.workflow1')->isLazy());
     $this->assertEquals($this->getExpectedConfig(), $this->container->getDefinition('finite.loader.workflow1')->getArgument(0));
 }
Пример #26
0
 /**
  * @test
  */
 public function solrListensToOdmAndOrmEvents()
 {
     $config = $this->commonConfig();
     $this->enableOdmConfig();
     $this->enableOrmConfig();
     $extension = new FSSolrExtension();
     $extension->load($config, $this->container);
     $this->assertTrue($this->container->has('solr.document.odm.subscriber'), 'odm subscriber');
     $this->assertDefinitionHasTag('solr.document.odm.subscriber', 'doctrine_mongodb.odm.event_subscriber');
     $this->assertTrue($this->container->has('solr.document.orm.subscriber'), 'orm subscriber');
     $this->assertDefinitionHasTag('solr.document.orm.subscriber', 'doctrine.event_subscriber');
 }
 /**
  * @test PrestaDeploymentExtension::load()
  */
 public function testLoadWithYamlConfiguration()
 {
     $loader = new YamlFileLoader($this->container, new FileLocator(__DIR__ . '/Fixtures/'));
     $loader->load('config.yml');
     $this->container->compile();
     $this->assertTrue($this->container->has('presta_deployment.manager.configuration'));
     $configurationManager = $this->container->get('presta_deployment.manager.configuration');
     $this->assertTrue($configurationManager->isOrmEnabled());
     $this->assertTrue($configurationManager->isPhpcrEnabled());
     $this->assertTrue($configurationManager->isMigrationEnabled());
     $this->assertTrue($configurationManager->isDeployRebuildEnabled());
 }
 /**
  * Define the default Method Name Inflector.
  * This will fail silently if the command_handler service does not exist
  *
  * @param array $mergedConfig
  * @param ContainerBuilder $container
  * @throws \Exception
  */
 private function injectMethodNameInflector(array $mergedConfig, ContainerBuilder $container)
 {
     if (!$container->has('tactician.middleware.command_handler')) {
         return;
     }
     if (!$container->has($mergedConfig['method_inflector'])) {
         throw new \Exception('Unable to find requested method_inflector service definition: ' . $mergedConfig['method_inflector']);
     }
     $inflectorReference = new Reference($mergedConfig['method_inflector']);
     $handlerLocator = $container->findDefinition('tactician.middleware.command_handler');
     $handlerLocator->replaceArgument(2, $inflectorReference);
 }
 public function testClientAlias()
 {
     $config = array('zeichen32_git_lab_api' => array('clients' => array('firstclient' => array('token' => '12345', 'url' => 'http://example.org/api/v3/', 'alias' => 'test.client'))));
     $this->extension->load($config, $this->container);
     $this->assertTrue($this->container->has('zeichen32_gitlabapi.client.default'));
     $this->assertTrue($this->container->has('zeichen32_gitlabapi.client.firstclient'));
     $this->assertTrue($this->container->has('gitlab_api'));
     $this->assertTrue($this->container->has('test.client'));
     $this->assertSame($this->container->get('zeichen32_gitlabapi.client.firstclient'), $this->container->get('zeichen32_gitlabapi.client.default'));
     $this->assertSame($this->container->get('zeichen32_gitlabapi.client.firstclient'), $this->container->get('gitlab_api'));
     $this->assertSame($this->container->get('zeichen32_gitlabapi.client.firstclient'), $this->container->get('test.client'));
 }
 public function process(ContainerBuilder $container)
 {
     if ($container->has('security.token_storage')) {
         $argument = new Reference('security.token_storage');
     } elseif ($container->has('security.context')) {
         $argument = new Reference('service_container');
     } else {
         return;
         // SecurityBundle is not configured
     }
     $definition = $container->findDefinition('hexanet_monolog_extra.logger.provider.user.symfony');
     $definition->addArgument($argument);
 }