diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 086f0251cb45b756eb20e0bad367c358714a383d..6d70110b16fd000814391a895dcbe068c67ada2a 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2127,20 +2127,6 @@ function drupal_get_bootstrap_phase() { return drupal_bootstrap(); } -/** - * Retrieves the Drupal Container to standardize object construction. - * - * @deprecated This function has been replaced by the \Drupal class. Use that - * instead. - * - * @return Symfony\Component\DependencyInjection\ContainerInterface|bool - * The instance of the ContainerInterface used to set up and maintain - * object instances or FALSE if none exist yet. - */ -function drupal_container() { - return \Drupal::getContainer(); -} - /** * Returns the list of enabled modules. * diff --git a/core/includes/config.inc b/core/includes/config.inc index d0f1d7bed6fd895e91bc7d5bc171519d9eac9194..af62fdaf749960150238cbb83c76f3fd4dd94a04 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -106,7 +106,7 @@ function ($value) use ($name) { * The name of the module or theme to install default configuration for. */ function config_uninstall_default_config($type, $name) { - $storage = drupal_container()->get('config.storage'); + $storage = \Drupal::service('config.storage'); $config_names = $storage->listAll($name . '.'); foreach ($config_names as $config_name) { \Drupal::config($config_name)->delete(); @@ -119,7 +119,7 @@ function config_uninstall_default_config($type, $name) { * @see \Drupal\Core\Config\StorageInterface::listAll() */ function config_get_storage_names_with_prefix($prefix = '') { - return drupal_container()->get('config.storage')->listAll($prefix); + return \Drupal::service('config.storage')->listAll($prefix); } /** @@ -163,18 +163,19 @@ function config($name) { * The configuration context object. */ function config_context_enter($context_name) { - if (drupal_container()->has($context_name)) { - $context = drupal_container()->get($context_name); + $container = \Drupal::getContainer(); + if ($container->has($context_name)) { + $context = $container->get($context_name); } elseif (class_exists($context_name) && in_array('Drupal\Core\Config\Context\ContextInterface', class_implements($context_name))) { - $context = drupal_container() + $context = $container ->get('config.context.factory') ->get($context_name); } else { throw new ConfigException(sprintf('Unknown config context service or class: %s', $context_name)); } - drupal_container() + $container ->get('config.factory') ->enterContext($context); return $context; @@ -187,8 +188,7 @@ function config_context_enter($context_name) { * @see \Drupal\Core\Config\ConfigFactory */ function config_context_leave() { - drupal_container() - ->get('config.factory') + \Drupal::service('config.factory') ->leaveContext(); } @@ -218,7 +218,7 @@ function config_get_entity_type_by_name($name) { * @return \Drupal\Core\Config\TypedConfigManager */ function config_typed() { - return drupal_container()->get('config.typed'); + return \Drupal::service('config.typed'); } /** diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 8762f0b1e36140ebbd8a8d81cfe6f865641c1ad4..8db114ac9b439114b9f1fb1cd58640bb419866d7 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -2206,8 +2206,8 @@ function install_finished(&$install_state) { drupal_cron_run(); // Save a snapshot of the initially installed configuration. - $active = drupal_container()->get('config.storage'); - $snapshot = drupal_container()->get('config.storage.snapshot'); + $active = \Drupal::service('config.storage'); + $snapshot = \Drupal::service('config.storage.snapshot'); config_import_create_snapshot($active, $snapshot); return $output; diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 305b8f7b515c4404253ec408a4ef1b2e7d620305..856c424a1305b57acbfd560729959e6d41103fa2 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -3092,7 +3092,7 @@ function _menu_router_build($callbacks, $save = FALSE) { // if the list has changed. if ($path_roots != \Drupal::state()->get('menu_path_roots')) { \Drupal::state()->set('menu_path_roots', array_values($path_roots)); - drupal_container()->get('path.alias_manager')->cacheClear(); + \Drupal::service('path.alias_manager')->cacheClear(); } _menu_router_save($menu, $masks); } diff --git a/core/includes/path.inc b/core/includes/path.inc index 9c41abd7cfbaf4a159ecd715cdcc097546d19e35..975dbe8b6327935c50cc2939abee12f1cc8eb9b5 100644 --- a/core/includes/path.inc +++ b/core/includes/path.inc @@ -82,8 +82,8 @@ function current_path() { // @todo Remove the check for whether the request service exists and the // fallback code below, once the path alias logic has been figured out in // http://drupal.org/node/1269742. - if (drupal_container()->isScopeActive('request')) { - $path = drupal_container()->get('request')->attributes->get('_system_path'); + if (\Drupal::getContainer()->isScopeActive('request')) { + $path = \Drupal::request()->attributes->get('_system_path'); if ($path !== NULL) { return $path; } @@ -112,7 +112,7 @@ function path_load($conditions) { elseif (!is_array($conditions)) { return FALSE; } - return drupal_container()->get('path.crud')->load($conditions); + return \Drupal::service('path.crud')->load($conditions); } /** diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 5441e30d295898fe621d5823f66c2cb1851298c5..6bb8179ffa3f3aca20803483f7da58ebc497bd6d 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -106,8 +106,8 @@ public static function setContainer(ContainerInterface $container) { /** * Returns the currently active global container. * - * @deprecated This method is only useful for the testing environment, and as - * a BC shiv for drupal_container(). It should not be used otherwise. + * @deprecated This method is only useful for the testing environment. It + * should not be used otherwise. * * @return \Symfony\Component\DependencyInjection\ContainerInterface */ diff --git a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/GetFilenameUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/GetFilenameUnitTest.php index 0d11b98f04fa267450d84c79593128524bd04b4d..702ee3b653c44c272f00a6d84a1061d330900c1e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/GetFilenameUnitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/GetFilenameUnitTest.php @@ -33,7 +33,7 @@ function testDrupalGetFilename() { // Assert that the test is meaningful by making sure the keyvalue service // does not exist. - $this->assertFalse(drupal_container()->has('keyvalue'), 'The container has no keyvalue service.'); + $this->assertFalse(\Drupal::getContainer()->has('keyvalue'), 'The container has no keyvalue service.'); // Retrieving the location of a module. $this->assertIdentical(drupal_get_filename('module', 'xmlrpc'), 'core/modules/xmlrpc/xmlrpc.module', 'Retrieve module location.'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorTest.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorTest.php index 2f44c886e3b8b7473ad16365a02c0aa02faff0e5..b305d28bca0d912d6cecd4c4ea6421b0bc8730de 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorTest.php @@ -47,7 +47,7 @@ public function setUp() { // Use a non-db cache backend, so that we can use DiscoveryTestBase (which // extends UnitTestBase). // @todo switch to injecting the MemoryBackend http://drupal.org/node/1903346 - drupal_container()->set("cache.$this->cacheBin", new MemoryBackend($this->cacheBin)); + \Drupal::getContainer()->set("cache.$this->cacheBin", new MemoryBackend($this->cacheBin)); // Create discovery objects to test. $this->emptyDiscovery = new StaticDiscovery(); diff --git a/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php b/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php index ffe398f6e0619283bfafb4d2d8c69c5cf031bcd7..527b57e9a53b365dde29335476186a2074565727 100644 --- a/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\system\Tests\ServiceProvider\ServiceProviderTest. + * Contains \Drupal\system\Tests\ServiceProvider\ServiceProviderTest. */ namespace Drupal\system\Tests\ServiceProvider; @@ -33,8 +33,9 @@ public static function getInfo() { * Tests that services provided by module service providers get registered to the DIC. */ function testServiceProviderRegistration() { - $this->assertTrue(drupal_container()->getDefinition('file.usage')->getClass() == 'Drupal\\service_provider_test\\TestFileUsage', 'Class has been changed'); - $this->assertTrue(drupal_container()->has('service_provider_test_class'), 'The service_provider_test_class service has been registered to the DIC'); + $container = \Drupal::getContainer(); + $this->assertTrue($container->getDefinition('file.usage')->getClass() == 'Drupal\\service_provider_test\\TestFileUsage', 'Class has been changed'); + $this->assertTrue($container->has('service_provider_test_class'), 'The service_provider_test_class service has been registered to the DIC'); // The event subscriber method in the test class calls drupal_set_message with // a message saying it has fired. This will fire on every page request so it // should show up on the front page. @@ -48,11 +49,11 @@ function testServiceProviderRegistration() { function testServiceProviderRegistrationDynamic() { // Uninstall the module and ensure the service provider's service is not registered. \Drupal::moduleHandler()->uninstall(array('service_provider_test')); - $this->assertFalse(drupal_container()->has('service_provider_test_class'), 'The service_provider_test_class service does not exist in the DIC.'); + $this->assertFalse(\Drupal::getContainer()->has('service_provider_test_class'), 'The service_provider_test_class service does not exist in the DIC.'); // Install the module and ensure the service provider's service is registered. \Drupal::moduleHandler()->install(array('service_provider_test')); - $this->assertTrue(drupal_container()->has('service_provider_test_class'), 'The service_provider_test_class service exists in the DIC.'); + $this->assertTrue(\Drupal::getContainer()->has('service_provider_test_class'), 'The service_provider_test_class service exists in the DIC.'); } } diff --git a/core/scripts/generate-d7-content.sh b/core/scripts/generate-d7-content.sh index bd24300f3b8d50b19b9b6b1f2aabfeb56e82e285..30c61a2bfb1c93dbf1099ec34fc493f74c555584 100644 --- a/core/scripts/generate-d7-content.sh +++ b/core/scripts/generate-d7-content.sh @@ -44,7 +44,7 @@ // Create six users $query = db_insert('users')->fields(array('uid', 'name', 'pass', 'mail', 'status', 'created', 'access')); -$password_hasher = drupal_container()->get('password'); +$password_hasher = \Drupal::service('password'); for ($i = 0; $i < 6; $i++) { $name = "test user $i"; $pass = md5("test PassW0rd $i !(.)"); @@ -252,7 +252,7 @@ 'alias' => "content/poll/$i/results", 'source' => "node/$node->nid/results", ); - drupal_container()->get('path.crud')->save($path['source'], $path['alias']); + \Drupal::service('path.crud')->save($path['source'], $path['alias']); // Add some votes $node = node_load($node->nid); diff --git a/core/scripts/password-hash.sh b/core/scripts/password-hash.sh index 485f497ac64d41e2d58e6a299798368d88e3147f..ad0ace6e741ad46dfc8b21d01af2bc0aeeaeb015 100755 --- a/core/scripts/password-hash.sh +++ b/core/scripts/password-hash.sh @@ -83,7 +83,7 @@ include_once $core . '/includes/password.inc'; include_once $core . '/includes/bootstrap.inc'; -$password_hasher = drupal_container()->get('password'); +$password_hasher = \Drupal::service('password'); foreach ($passwords as $password) { print("\npassword: $password \t\thash: ". $password_hasher->hash($password) ."\n"); diff --git a/core/themes/engines/twig/twig.engine b/core/themes/engines/twig/twig.engine index e09ec99bfc3137693eb6fea86146de14496d28ab..23e245c9f9f9835e0176df55671be4920a10d6da 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -51,7 +51,7 @@ function twig_render_template($template_file, $variables) { $output = array( 'debug_prefix' => '', 'debug_info' => '', - 'rendered_markup' => drupal_container()->get('twig')->loadTemplate($template_file)->render($variables), + 'rendered_markup' => \Drupal::service('twig')->loadTemplate($template_file)->render($variables), 'debug_suffix' => '', ); if (settings()->get('twig_debug', FALSE)) { diff --git a/core/update.php b/core/update.php index 48059208471e95c8f9acdb70ab2a14a9f8710de3..527a7038646d1ad2b027d46dbb113bb212de458b 100644 --- a/core/update.php +++ b/core/update.php @@ -193,8 +193,9 @@ function update_info_page() { // Change query-strings on css/js files to enforce reload for all users. _drupal_flush_css_js(); // Flush the cache of all data for the update status module. - drupal_container()->get('keyvalue.expirable')->get('update')->deleteAll(); - drupal_container()->get('keyvalue.expirable')->get('update_available_release')->deleteAll(); + $keyvalue = \Drupal::service('keyvalue.expirable'); + $keyvalue->get('update')->deleteAll(); + $keyvalue->get('update_available_release')->deleteAll(); update_task_list('info'); drupal_set_title('Drupal database update'); @@ -254,7 +255,7 @@ function update_access_allowed() { $module_filenames['user'] = 'core/modules/user/user.module'; $module_handler->setModuleList($module_filenames); $module_handler->reload(); - drupal_container()->get('kernel')->updateModules($module_filenames, $module_filenames); + \Drupal::service('kernel')->updateModules($module_filenames, $module_filenames); return user_access('administer software updates'); } catch (\Exception $e) {