当前位置: 首页>>代码示例>>PHP>>正文


PHP ContainerBuilder::setParameter方法代码示例

本文整理汇总了PHP中Drupal\Core\DependencyInjection\ContainerBuilder::setParameter方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::setParameter方法的具体用法?PHP ContainerBuilder::setParameter怎么用?PHP ContainerBuilder::setParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\DependencyInjection\ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder::setParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 /**
  * Loads a Yaml file.
  *
  * @param mixed  $file The resource
  */
 public function load($file)
 {
     // Load from the file cache, fall back to loading the file.
     // @todo Refactor this to cache parsed definition objects in
     //   https://www.drupal.org/node/2464053
     $content = $this->fileCache->get($file);
     if (!$content) {
         $content = $this->loadFile($file);
         $this->fileCache->set($file, $content);
     }
     // Not supported.
     //$this->container->addResource(new FileResource($path));
     // empty file
     if (null === $content) {
         return;
     }
     // imports
     // Not supported.
     //$this->parseImports($content, $file);
     // parameters
     if (isset($content['parameters'])) {
         foreach ($content['parameters'] as $key => $value) {
             $this->container->setParameter($key, $this->resolveServices($value));
         }
     }
     // extensions
     // Not supported.
     //$this->loadFromExtensions($content);
     // services
     $this->parseDefinitions($content, $file);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:36,代码来源:YamlFileLoader.php

示例2: load

 /**
  * Loads a Yaml file.
  *
  * @param mixed  $file The resource
  */
 public function load($file)
 {
     // Load from the file cache, fall back to loading the file.
     // @todo Refactor this to cache parsed definition objects in
     //   https://www.drupal.org/node/2464053
     $content = $this->fileCache->get($file);
     if (!$content) {
         $content = $this->loadFile($file);
         $this->fileCache->set($file, $content);
     }
     // Not supported.
     //$this->container->addResource(new FileResource($path));
     // empty file
     if (null === $content) {
         return;
     }
     // imports
     // Not supported.
     //$this->parseImports($content, $file);
     // parameters
     if (isset($content['parameters'])) {
         if (!is_array($content['parameters'])) {
             throw new InvalidArgumentException(sprintf('The "parameters" key should contain an array in %s. Check your YAML syntax.', $file));
         }
         foreach ($content['parameters'] as $key => $value) {
             $this->container->setParameter($key, $this->resolveServices($value));
         }
     }
     // extensions
     // Not supported.
     //$this->loadFromExtensions($content);
     // services
     $this->parseDefinitions($content, $file);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:39,代码来源:YamlFileLoader.php

示例3: 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);
     }
     if ($parameter = Settings::get('container_rebuild_test_parameter')) {
         $container->setParameter('container_rebuild_test_parameter', $parameter);
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:17,代码来源:ServiceProviderTestServiceProvider.php

示例4: register

 /**
  * {@inheritdoc}
  */
 public function register(ContainerBuilder $container)
 {
     $container->setParameter('app.root', DRUPAL_ROOT);
     $this->registerUuid($container);
     $this->registerTest($container);
     // Add the compiler pass that lets service providers modify existing
     // service definitions. This pass must come first so that later
     // list-building passes are operating on the post-alter services list.
     $container->addCompilerPass(new ModifyServiceDefinitionsPass());
     $container->addCompilerPass(new BackendCompilerPass());
     $container->addCompilerPass(new StackedKernelPass());
     // Collect tagged handler services as method calls on consumer services.
     $container->addCompilerPass(new TaggedHandlersPass());
     $container->addCompilerPass(new RegisterStreamWrappersPass());
     // Add a compiler pass for registering event subscribers.
     $container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING);
     $container->addCompilerPass(new RegisterAccessChecksPass());
     // Add a compiler pass for registering services needing destruction.
     $container->addCompilerPass(new RegisterServicesForDestructionPass());
     // Add the compiler pass that will process the tagged services.
     $container->addCompilerPass(new ListCacheBinsPass());
     $container->addCompilerPass(new CacheContextsPass());
     // Register plugin managers.
     $container->addCompilerPass(new PluginManagerPass());
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:28,代码来源:CoreServiceProvider.php

示例5: register

 /**
  * Registers services to the container.
  *
  * @param ContainerBuilder $container
  *   The ContainerBuilder to register services to.
  */
 public function register(ContainerBuilder $container)
 {
     static::$container = $container;
     $class_map = $this->AutoloaderInit();
     $ns = [];
     foreach ($class_map as $name => $path) {
         $path = preg_replace("/\\.php\$/i", '', $path);
         $path = explode(DIRECTORY_SEPARATOR, $path);
         $name = explode('\\', $name);
         while (end($path) === end($name)) {
             array_pop($path);
             array_pop($name);
         }
         $path = implode(DIRECTORY_SEPARATOR, $path);
         $name = implode('\\', $name);
         if (is_dir($path)) {
             if (is_dir($path . '/Plugin') || is_dir($path . '/Entity') || is_dir($path . '/Element')) {
                 $ns[$name][] = $path;
             }
         }
     }
     foreach ($ns as $name => $path) {
         $path = array_unique($path);
         $ns[$name] = count($path) == 1 ? reset($path) : $path;
     }
     $ns += $container->getParameter('container.namespaces');
     $container->setParameter('container.namespaces', $ns);
     $yaml_loader = new YamlFileLoader($container);
     foreach (static::getFiles('/^.+\\.services\\.yml$/i') as $file) {
         $yaml_loader->load($file);
     }
 }
开发者ID:d-f-d,项目名称:d_submodules,代码行数:38,代码来源:DSubmodulesServiceProvider.php

示例6: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $container = new ContainerBuilder();
     $container->setParameter('workspace.default', 1);
     \Drupal::setContainer($container);
     $this->workspaceNegotiator = new DefaultWorkspaceNegotiator();
     $this->workspaceNegotiator->setContainer($container);
     $this->request = Request::create('<front>');
 }
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:13,代码来源:DefaultWorkspaceNegotiatorTest.php

示例7: alter

 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     $definition = $container->getDefinition('language_manager');
     $definition->setClass('Drupal\\language\\ConfigurableLanguageManager')->addArgument(new Reference('config.factory'))->addArgument(new Reference('module_handler'))->addArgument(new Reference('language.config_factory_override'))->addArgument(new Reference('request_stack'));
     if ($default_language_values = $this->getDefaultLanguageValues()) {
         $container->setParameter('language.default_values', $default_language_values);
     }
     // For monolingual sites, we explicitly set the default language for the
     // language config override service as there is no language negotiation.
     if (!$this->isMultilingual()) {
         $container->getDefinition('language.config_factory_override')->addMethodCall('setLanguageFromDefault', array(new Reference('language.default')));
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:16,代码来源:LanguageServiceProvider.php

示例8: setMinimalContainerPreKernel

 public function setMinimalContainerPreKernel()
 {
     // Create a minimal mocked container to support calls to t() in the pre-kernel
     // base system verification code paths below. The strings are not actually
     // used or output for these calls.
     $container = new ContainerBuilder();
     $container->setParameter('language.default_values', Language::$defaultValues);
     $container->register('language.default', 'Drupal\\Core\\Language\\LanguageDefault')->addArgument('%language.default_values%');
     $container->register('string_translation', 'Drupal\\Core\\StringTranslation\\TranslationManager')->addArgument(new Reference('language.default'));
     // Register the stream wrapper manager.
     $container->register('stream_wrapper_manager', 'Drupal\\Core\\StreamWrapper\\StreamWrapperManager')->addMethodCall('setContainer', array(new Reference('service_container')));
     $container->register('file_system', 'Drupal\\Core\\File\\FileSystem')->addArgument(new Reference('stream_wrapper_manager'))->addArgument(Settings::getInstance())->addArgument((new LoggerChannelFactory())->get('file'));
     \Drupal::setContainer($container);
 }
开发者ID:jeyram,项目名称:DrupalConsole,代码行数:14,代码来源:DrupalApi.php

示例9: alter

 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     // Disable Twig cache (php storage does not exist yet).
     $twig_config = $container->getParameter('twig.config');
     $twig_config['cache'] = FALSE;
     $container->setParameter('twig.config', $twig_config);
     // No service may persist when the early installer kernel is rebooted into
     // the production environment.
     // @todo The DrupalKernel reboot performed by drupal_install_system() is
     //   actually not a "regular" reboot (like ModuleHandler::install()), so
     //   services are not actually persisted.
     foreach ($container->findTaggedServiceIds('persist') as $id => $tags) {
         $definition = $container->getDefinition($id);
         $definition->clearTag('persist');
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:19,代码来源:InstallerServiceProvider.php

示例10: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $container = new ContainerBuilder();
     $request = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
     $this->view = $this->getMock('\\Drupal\\views\\Entity\\View', array('initHandlers'), array(array('id' => 'test_view'), 'view'));
     $view_executable = $this->getMock('\\Drupal\\views\\ViewExecutable', array('initHandlers', 'getTitle'), array(), '', FALSE);
     $view_executable->expects($this->any())->method('getTitle')->willReturn('View title');
     $view_executable->storage = $this->view;
     $view_executable->argument = array();
     $display_manager = $this->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')->disableOriginalConstructor()->getMock();
     $container->set('plugin.manager.views.display', $display_manager);
     $access_manager = $this->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')->disableOriginalConstructor()->getMock();
     $container->set('plugin.manager.views.access', $access_manager);
     $route_provider = $this->getMockBuilder('\\Drupal\\Core\\Routing\\RouteProviderInterface')->disableOriginalConstructor()->getMock();
     $container->set('router.route_provider', $route_provider);
     $container->setParameter('authentication_providers', ['basic_auth' => 'basic_auth']);
     $state = $this->getMock('\\Drupal\\Core\\State\\StateInterface');
     $container->set('state', $state);
     $style_manager = $this->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')->disableOriginalConstructor()->getMock();
     $container->set('plugin.manager.views.style', $style_manager);
     $container->set('renderer', $this->getMock('Drupal\\Core\\Render\\RendererInterface'));
     $authentication_collector = $this->getMock('\\Drupal\\Core\\Authentication\\AuthenticationCollectorInterface');
     $container->set('authentication_collector', $authentication_collector);
     $authentication_collector->expects($this->any())->method('getSortedProviders')->will($this->returnValue(['basic_auth' => 'data', 'cookie' => 'data']));
     \Drupal::setContainer($container);
     $this->restExport = RestExport::create($container, array(), "test_routes", array());
     $this->restExport->view = $view_executable;
     // Initialize a display.
     $this->restExport->display = array('id' => 'page_1');
     // Set the style option.
     $this->restExport->setOption('style', array('type' => 'serializer'));
     // Set the auth option.
     $this->restExport->setOption('auth', ['basic_auth']);
     $display_manager->expects($this->once())->method('getDefinition')->will($this->returnValue(array('id' => 'test', 'provider' => 'test')));
     $none = $this->getMockBuilder('\\Drupal\\views\\Plugin\\views\\access\\None')->disableOriginalConstructor()->getMock();
     $access_manager->expects($this->once())->method('createInstance')->will($this->returnValue($none));
     $style_plugin = $this->getMock('\\Drupal\\rest\\Plugin\\views\\style\\Serializer', array('getFormats', 'init'), array(), '', FALSE);
     $style_plugin->expects($this->once())->method('getFormats')->will($this->returnValue(array('json')));
     $style_plugin->expects($this->once())->method('init')->with($view_executable)->will($this->returnValue(TRUE));
     $style_manager->expects($this->once())->method('createInstance')->will($this->returnValue($style_plugin));
     $this->routes = new RouteCollection();
     $this->routes->add('test_1', new Route('/test/1'));
     $this->routes->add('view.test_view.page_1', new Route('/test/2'));
     $this->view->addDisplay('page', NULL, 'page_1');
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:49,代码来源:CollectRoutesTest.php

示例11: testLocks

 /**
  * Test the lock behavior.
  */
 public function testLocks()
 {
     $container = new ContainerBuilder();
     $container->set('module_handler', $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface'));
     $container->set('current_user', $this->getMock('Drupal\\Core\\Session\\AccountInterface'));
     $container->set('cache.test', $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface'));
     $container->set('comment.statistics', $this->getMock('Drupal\\comment\\CommentStatisticsInterface'));
     $request_stack = new RequestStack();
     $request_stack->push(Request::create('/'));
     $container->set('request_stack', $request_stack);
     $container->setParameter('cache_bins', array('cache.test' => 'test'));
     $lock = $this->getMock('Drupal\\Core\\Lock\\LockBackendInterface');
     $cid = 2;
     $lock_name = "comment:{$cid}:.00/";
     $lock->expects($this->at(0))->method('acquire')->with($lock_name, 30)->will($this->returnValue(TRUE));
     $lock->expects($this->at(1))->method('release')->with($lock_name);
     $lock->expects($this->exactly(2))->method($this->anything());
     $container->set('lock', $lock);
     $cache_tag_invalidator = $this->getMock('Drupal\\Core\\Cache\\CacheTagsInvalidator');
     $container->set('cache_tags.invalidator', $cache_tag_invalidator);
     \Drupal::setContainer($container);
     $methods = get_class_methods('Drupal\\comment\\Entity\\Comment');
     unset($methods[array_search('preSave', $methods)]);
     unset($methods[array_search('postSave', $methods)]);
     $methods[] = 'invalidateTagsOnSave';
     $comment = $this->getMockBuilder('Drupal\\comment\\Entity\\Comment')->disableOriginalConstructor()->setMethods($methods)->getMock();
     $comment->expects($this->once())->method('isNew')->will($this->returnValue(TRUE));
     $comment->expects($this->once())->method('hasParentComment')->will($this->returnValue(TRUE));
     $comment->expects($this->once())->method('getParentComment')->will($this->returnValue($comment));
     $comment->expects($this->once())->method('getCommentedEntityId')->will($this->returnValue($cid));
     $comment->expects($this->any())->method('getThread')->will($this->returnValue(''));
     $parent_entity = $this->getMock('\\Drupal\\Core\\Entity\\ContentEntityInterface');
     $parent_entity->expects($this->atLeastOnce())->method('getCacheTagsToInvalidate')->willReturn(['node:1']);
     $comment->expects($this->once())->method('getCommentedEntity')->willReturn($parent_entity);
     $entity_type = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
     $comment->expects($this->any())->method('getEntityType')->will($this->returnValue($entity_type));
     $comment->expects($this->at(1))->method('get')->with('status')->will($this->returnValue((object) array('value' => NULL)));
     $storage = $this->getMock('Drupal\\comment\\CommentStorageInterface');
     // preSave() should acquire the lock. (This is what's really being tested.)
     $comment->preSave($storage);
     // Release the acquired lock before exiting the test.
     $comment->postSave($storage);
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:46,代码来源:CommentLockTest.php

示例12: alter

 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     // Disable Twig cache (php storage does not exist yet).
     $twig_config = $container->getParameter('twig.config');
     $twig_config['cache'] = FALSE;
     $container->setParameter('twig.config', $twig_config);
     // Disable configuration overrides.
     // ConfigFactory would to try to load language overrides and InstallStorage
     // throws an exception upon trying to load a non-existing file.
     $container->get('config.factory')->setOverrideState(FALSE);
     // No service may persist when the early installer kernel is rebooted into
     // the production environment.
     // @todo The DrupalKernel reboot performed by drupal_install_system() is
     //   actually not a "regular" reboot (like ModuleHandler::install()), so
     //   services are not actually persisted.
     foreach ($container->findTaggedServiceIds('persist') as $id => $tags) {
         $definition = $container->getDefinition($id);
         $definition->clearTag('persist');
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:23,代码来源:InstallerServiceProvider.php

示例13: testLocks

 /**
  * Test the lock behavior.
  */
 public function testLocks()
 {
     $container = new ContainerBuilder();
     $container->set('module_handler', $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface'));
     $container->set('current_user', $this->getMock('Drupal\\Core\\Session\\AccountInterface'));
     $container->set('cache.test', $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface'));
     $request_stack = new RequestStack();
     $request_stack->push(Request::create('/'));
     $container->set('request_stack', $request_stack);
     $container->setParameter('cache_bins', array('cache.test' => 'test'));
     $lock = $this->getMock('Drupal\\Core\\Lock\\LockBackendInterface');
     $cid = 2;
     $lock_name = "comment:{$cid}:.00/";
     $lock->expects($this->at(0))->method('acquire')->with($lock_name, 30)->will($this->returnValue(TRUE));
     $lock->expects($this->at(1))->method('release')->with($lock_name);
     $lock->expects($this->exactly(2))->method($this->anything());
     $container->set('lock', $lock);
     \Drupal::setContainer($container);
     $methods = get_class_methods('Drupal\\comment\\Entity\\Comment');
     unset($methods[array_search('preSave', $methods)]);
     unset($methods[array_search('postSave', $methods)]);
     $methods[] = 'onSaveOrDelete';
     $methods[] = 'onUpdateBundleEntity';
     $comment = $this->getMockBuilder('Drupal\\comment\\Entity\\Comment')->disableOriginalConstructor()->setMethods($methods)->getMock();
     $comment->expects($this->once())->method('isNew')->will($this->returnValue(TRUE));
     $comment->expects($this->once())->method('hasParentComment')->will($this->returnValue(TRUE));
     $comment->expects($this->once())->method('getParentComment')->will($this->returnValue($comment));
     $comment->expects($this->once())->method('getCommentedEntityId')->will($this->returnValue($cid));
     $comment->expects($this->any())->method('getThread')->will($this->returnValue(''));
     $entity_type = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
     $comment->expects($this->any())->method('getEntityType')->will($this->returnValue($entity_type));
     $comment->expects($this->at(1))->method('get')->with('status')->will($this->returnValue((object) array('value' => NULL)));
     $comment->expects($this->once())->method('getCacheTag')->will($this->returnValue(array('comment' => array($cid))));
     $comment->expects($this->once())->method('getListCacheTags')->will($this->returnValue(array('comments' => TRUE)));
     $storage = $this->getMock('Drupal\\comment\\CommentStorageInterface');
     $comment->preSave($storage);
     $comment->postSave($storage);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:41,代码来源:CommentLockTest.php

示例14: 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);
     }
 }
开发者ID:hugronaphor,项目名称:cornel,代码行数:41,代码来源:LibrariesServiceProvider.php

示例15: alter

 public function alter(ContainerBuilder $container)
 {
     // Override the password_migrate class with a new class.
     try {
         $definition = $container->getDefinition('password_migrate');
         $definition->setClass('Drupal\\multiversion\\MigratePassword');
     } catch (InvalidArgumentException $e) {
         // Do nothing, migrate module is not installed.
     }
     $renderer_config = $container->getParameter('renderer.config');
     $renderer_config['required_cache_contexts'][] = 'workspace';
     $container->setParameter('renderer.config', $renderer_config);
     // Switch the menu tree storage to our own that respect Workspace cache
     // contexts.
     $definition = $container->getDefinition('menu.tree_storage');
     $definition->setClass('Drupal\\multiversion\\MenuTreeStorage');
     // Override the comment.statistics class with a new class.
     try {
         $definition = $container->getDefinition('comment.statistics');
         $definition->setClass('Drupal\\multiversion\\CommentStatistics');
     } catch (InvalidArgumentException $e) {
         // Do nothing, comment module is not installed.
     }
 }
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:24,代码来源:MultiversionServiceProvider.php


注:本文中的Drupal\Core\DependencyInjection\ContainerBuilder::setParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。