本文整理汇总了PHP中Drupal\Core\DependencyInjection\ContainerBuilder::has方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::has方法的具体用法?PHP ContainerBuilder::has怎么用?PHP ContainerBuilder::has使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::has方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
if ($container->has('file.usage')) {
// Override the class used for the file.usage service.
$definition = $container->getDefinition('file.usage');
$definition->setClass('Drupal\\service_provider_test\\TestFileUsage');
}
}
示例2: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
if ($container->has('file.usage')) {
// Override the class used for the file.usage service.
$definition = $container->getDefinition('file.usage');
$definition->setClass('Drupal\\service_provider_test\\TestFileUsage');
}
if ($indicator = Settings::get('deployment_identifier')) {
$container->setParameter('container_rebuild_indicator', $indicator);
}
}
示例3: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
if ($container->has('config.factory')) {
// The configuration factory depends on the cache factory, but that
// depends on the 'cache_default_bin_backends' parameter that has not yet
// been set by \Drupal\Core\Cache\ListCacheBinsPass::process() at this
// point.
$parameter_name = 'cache_default_bin_backends';
if (!$container->hasParameter($parameter_name)) {
$container->setParameter($parameter_name, []);
}
/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory = $container->get('config.factory');
$config = $config_factory->get('libraries.settings');
if (!$config->isNew()) {
// Set the local definition path.
$container->getDefinition('libraries.definition.discovery.local')->replaceArgument(1, $config->get('definition.local.path'));
// Set the remote definition URL. Note that this is set even if
// the remote discovery is not enabled below in case the
// 'libraries.definition.discovery.remote' service is used explicitly.
$container->getDefinition('libraries.definition.discovery.remote')->replaceArgument(2, $config->get('definition.remote.url'));
// Because it is less convenient to remove a method call than to add
// one, the remote discovery is not registered in libraries.services.yml
// and instead added here, even though the 'definition.remote.enable'
// configuration value is TRUE by default.
if ($config->get('definition.remote.enable')) {
// Add the remote discovery to the list of chained discoveries.
$container->getDefinition('libraries.definition.discovery')->addMethodCall('addDiscovery', [new Reference('libraries.definition.discovery.remote')]);
}
}
// At this point the event dispatcher has not yet been populated with
// event subscribers by RegisterEventSubscribersPass::process() but has
// already bin injected in the configuration factory. Reset those services
// accordingly.
$container->set('event_dispatcher', NULL);
$container->set('config.factory', NULL);
}
}
示例4: containerBuild
/**
* Sets up the base service container for this test.
*
* Extend this method in your test to register additional service overrides
* that need to persist a DrupalKernel reboot. This method is called whenever
* the kernel is rebuilt.
*
* @see \Drupal\simpletest\KernelTestBase::setUp()
* @see \Drupal\simpletest\KernelTestBase::enableModules()
* @see \Drupal\simpletest\KernelTestBase::disableModules()
*/
public function containerBuild(ContainerBuilder $container)
{
// Keep the container object around for tests.
$this->container = $container;
// Set the default language on the minimal container.
$this->container->setParameter('language.default_values', $this->defaultLanguageData());
$container->register('lock', 'Drupal\\Core\\Lock\\NullLockBackend');
$container->register('cache_factory', 'Drupal\\Core\\Cache\\MemoryBackendFactory');
$container->register('config.storage', 'Drupal\\Core\\Config\\DatabaseStorage')->addArgument(Database::getConnection())->addArgument('config');
if ($this->strictConfigSchema) {
$container->register('simpletest.config_schema_checker', 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker')->addArgument(new Reference('config.typed'))->addArgument($this->getConfigSchemaExclusions())->addTag('event_subscriber');
}
$keyvalue_options = $container->getParameter('factory.keyvalue') ?: array();
$keyvalue_options['default'] = 'keyvalue.memory';
$container->setParameter('factory.keyvalue', $keyvalue_options);
$container->set('keyvalue.memory', $this->keyValueFactory);
if (!$container->has('keyvalue')) {
// TestBase::setUp puts a completely empty container in
// $this->container which is somewhat the mirror of the empty
// environment being set up. Unit tests need not to waste time with
// getting a container set up for them. Drupal Unit Tests might just get
// away with a simple container holding the absolute bare minimum. When
// a kernel is overridden then there's no need to re-register the keyvalue
// service but when a test is happy with the superminimal container put
// together here, it still might a keyvalue storage for anything using
// \Drupal::state() -- that's why a memory service was added in the first
// place.
$container->register('settings', 'Drupal\\Core\\Site\\Settings')->setFactoryClass('Drupal\\Core\\Site\\Settings')->setFactoryMethod('getInstance');
$container->register('keyvalue', 'Drupal\\Core\\KeyValueStore\\KeyValueFactory')->addArgument(new Reference('service_container'))->addArgument(new Parameter('factory.keyvalue'));
$container->register('state', 'Drupal\\Core\\State\\State')->addArgument(new Reference('keyvalue'));
}
if ($container->hasDefinition('path_processor_alias')) {
// Prevent the alias-based path processor, which requires a url_alias db
// table, from being registered to the path processor manager. We do this
// by removing the tags that the compiler pass looks for. This means the
// url generator can safely be used within tests.
$definition = $container->getDefinition('path_processor_alias');
$definition->clearTag('path_processor_inbound')->clearTag('path_processor_outbound');
}
if ($container->hasDefinition('password')) {
$container->getDefinition('password')->setArguments(array(1));
}
// Register the stream wrapper manager.
$container->register('stream_wrapper_manager', 'Drupal\\Core\\StreamWrapper\\StreamWrapperManager')->addArgument(new Reference('module_handler'))->addMethodCall('setContainer', array(new Reference('service_container')));
$request = Request::create('/');
$container->get('request_stack')->push($request);
}
示例5: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
if ($container->has('http_middleware.negotiation') && is_a($container->getDefinition('http_middleware.negotiation')->getClass(), '\\Drupal\\Core\\StackMiddleware\\NegotiationMiddleware', TRUE)) {
$container->getDefinition('http_middleware.negotiation')->addMethodCall('registerFormat', ['hal_json', ['application/hal+json']]);
}
}
示例6: alter
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container)
{
if ($container->has('http_middleware.negotiation')) {
$container->getDefinition('http_middleware.negotiation')->addMethodCall('registerFormat', ['hal_json', ['application/hal+json']]);
}
}