本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::has方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::has方法的具体用法?PHP ContainerBuilder::has怎么用?PHP ContainerBuilder::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* {@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]);
}
}
}
示例2: process
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')]);
}
}
示例3: process
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!");
}
}
}
示例4: testLoadExtension
/**
* 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'));
}
示例5: restClientConfig
/**
* 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: process
/**
* {@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: testReconnectConfiguration
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');
}
示例8: process
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: process
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: process
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);
}
}
示例11: testLoadExtension
/**
* 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: buildService
/**
* 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: process
/**
* {@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));
}
示例14: testEmptyConfigUsesDefaultValuesAndServicesAreCreated
public function testEmptyConfigUsesDefaultValuesAndServicesAreCreated()
{
$this->container->setParameter('excepciones', array('email_admin_contact' => 'dacasals@uci.cu'));
$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'));
}
示例15: testShouldConfigureCoreSerializer
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'));
}