diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 2a29937..260fbee 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2125,20 +2125,6 @@ function drupal_get_bootstrap_phase() { } /** - * 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. * * @deprecated as of Drupal 8.0. Use diff --git a/core/includes/config.inc b/core/includes/config.inc index 8e9ce5e..a7ac953 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -105,7 +105,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(); @@ -118,7 +118,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); } /** @@ -162,18 +162,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; @@ -186,8 +187,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(); } @@ -217,7 +217,7 @@ function config_get_entity_type_by_name($name) { * @return \Drupal\Core\TypedData\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 e0653b9..100400d 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -2212,8 +2212,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 7afc274..645caae 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -3142,7 +3142,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 9c41abd..975dbe8 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 a03ee24..49e5f7d 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 0d11b98..702ee3b 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 2f44c88..b305d28 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 ffe398f..be50bc6 100644 --- a/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php @@ -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. @@ -46,13 +47,14 @@ function testServiceProviderRegistration() { * Tests that the DIC keeps up with module enable/disable in the same request. */ function testServiceProviderRegistrationDynamic() { + $container = \Drupal::getContainer(); // 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($container->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($container->has('service_provider_test_class'), 'The service_provider_test_class service exists in the DIC.'); } } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 17d7fb0..855f65a 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2137,7 +2137,7 @@ function system_page_build(&$page) { * Implements hook_custom_theme(). */ function system_custom_theme() { - if (drupal_container()->isScopeActive('request')) { + if (\Drupal::getContainer()->isScopeActive('request')) { $request = \Drupal::request(); $path = $request->attributes->get('_system_path'); if (user_access('view the administration theme') && path_is_admin($path)) { diff --git a/core/scripts/generate-d7-content.sh b/core/scripts/generate-d7-content.sh index bd24300..30c61a2 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 485f497..4036183 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::getContainer('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 e09ec99..23e245c 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 4805920..87b5e29 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.expireable'); + $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) {