diff --git a/core/includes/common.inc b/core/includes/common.inc index 88d6fd3..7d553c6 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -5023,7 +5023,7 @@ function drupal_cron_run() { // existing queue. foreach ($queues as $queue_name => $info) { if (isset($info['cron'])) { - queue($queue_name)->createQueue(); + Drupal::queue($queue_name)->createQueue(); } } @@ -5053,7 +5053,7 @@ function drupal_cron_run() { if (isset($info['cron'])) { $function = $info['worker callback']; $end = time() + (isset($info['cron']['time']) ? $info['cron']['time'] : 15); - $queue = queue($queue_name); + $queue = Drupal::queue($queue_name); while (time() < $end && ($item = $queue->claimItem())) { $function($item->data); $queue->deleteItem($item); @@ -6660,33 +6660,5 @@ function drupal_get_filetransfer_info() { */ /** - * Instantiates and statically caches the correct class for a queue. - * - * The following variables can be set by variable_set or $conf overrides: - * - queue_class_$name: The class to be used for the queue $name. - * - queue_default_class: The class to use when queue_class_$name is not - * defined. Defaults to Drupal\Core\Queue\System, a reliable backend using - * SQL. - * - queue_default_reliable_class: The class to use when queue_class_$name is - * not defined and the queue_default_class is not reliable. Defaults to - * Drupal\Core\Queue\System. - * - * @param string $name - * The name of the queue to work with. - * @param bool $reliable - * (optional) TRUE if the ordering of items and guaranteeing every item - * executes at least once is important, FALSE if scalability is the main - * concern. Defaults to FALSE. - * - * @return Drupal\Core\Queue\QueueInterface - * The queue object for a given name. - * - * @see Drupal\Core\Queue\QueueInterface - */ -function queue($name, $reliable = FALSE) { - return drupal_container()->get('queue')->get($name, $reliable); -} - -/** * @} End of "defgroup queue". */ diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index d2e461e..c0a6495 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1510,7 +1510,7 @@ function install_retrieve_file($uri, $destination) { } try { - $request = drupal_container()->get('http_default_client')->get($uri, array('Accept' => 'text/plain')); + $request = Drupal::httpClient()->get($uri, array('Accept' => 'text/plain')); $data = $request->send()->getBody(TRUE); if (empty($data)) { return FALSE; @@ -1533,7 +1533,7 @@ function install_retrieve_file($uri, $destination) { */ function install_check_localization_server($uri) { try { - $request = drupal_container()->get('http_default_client')->head($uri); + $request = Drupal::httpClient()->head($uri); $response = $request->send(); return TRUE; } diff --git a/core/includes/install.inc b/core/includes/install.inc index 3fdc48c..fa70bcd 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -623,10 +623,7 @@ function drupal_install_system() { require_once DRUPAL_ROOT . '/' . $system_path . '/system.install'; $system_versions = drupal_get_schema_versions('system'); $system_version = $system_versions ? max($system_versions) : SCHEMA_INSTALLED; - drupal_container() - ->get('keyvalue') - ->get('system.schema') - ->set('system', $system_version); + Drupal::keyValue('system.schema')->set('system', $system_version); // System module needs to be enabled and the system/module lists need to be // reset first in order to allow config_install_default_config() to invoke diff --git a/core/includes/module.inc b/core/includes/module.inc index 99eac78..d675cd2 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -284,7 +284,7 @@ function module_enable($module_list, $enable_dependencies = TRUE) { $modules_installed = array(); $modules_enabled = array(); - $schema_store = drupal_container()->get('keyvalue')->get('system.schema'); + $schema_store = Drupal::keyValue('system.schema'); $module_config = config('system.module'); $disabled_config = config('system.module.disabled'); $module_handler = drupal_container()->get('module_handler'); @@ -567,7 +567,7 @@ function module_uninstall($module_list = array(), $uninstall_dependents = TRUE) } $storage = drupal_container()->get('config.storage'); - $schema_store = drupal_container()->get('keyvalue')->get('system.schema'); + $schema_store = Drupal::keyValue('system.schema'); $disabled_config = config('system.module.disabled'); foreach ($module_list as $module) { // Uninstall the module. diff --git a/core/includes/schema.inc b/core/includes/schema.inc index e599923..24df9d4 100644 --- a/core/includes/schema.inc +++ b/core/includes/schema.inc @@ -173,7 +173,7 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F } if (!$versions) { - if (!$versions = drupal_container()->get('keyvalue')->get('system.schema')->getAll()) { + if (!$versions = Drupal::keyValue('system.schema')->getAll()) { $versions = array(); } } @@ -195,7 +195,7 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F * The new schema version. */ function drupal_set_installed_schema_version($module, $version) { - drupal_container()->get('keyvalue')->get('system.schema')->set($module, $version); + Drupal::keyValue('system.schema')->set($module, $version); // Reset the static cache of module schema versions. drupal_get_installed_schema_version(NULL, TRUE); } diff --git a/core/includes/update.inc b/core/includes/update.inc index bf11562..9c6bb2c 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -343,7 +343,7 @@ function update_prepare_d8_bootstrap() { $disabled_modules = config('system.module.disabled'); $theme_config = config('system.theme'); $disabled_themes = config('system.theme.disabled'); - $schema_store = drupal_container()->get('keyvalue')->get('system.schema'); + $schema_store = Drupal::keyValue('system.schema'); // Load system.module, because update_prepare_d8_bootstrap() is called in // the initial minimal update.php bootstrap that performs the core @@ -663,7 +663,7 @@ function update_fix_d8_requirements() { * if the module was not installed before. */ function update_module_enable(array $modules, $schema_version = 0) { - $schema_store = drupal_container()->get('keyvalue')->get('system.schema'); + $schema_store = Drupal::keyValue('system.schema'); $old_schema = array(); foreach ($modules as $module) { // Check for initial schema and install it. The schema version of a newly @@ -1237,7 +1237,7 @@ function update_retrieve_dependencies() { $return = array(); // Get a list of installed modules, arranged so that we invoke their hooks in // the same order that module_invoke_all() does. - foreach (drupal_container()->get('keyvalue')->get('system.schema')->getAll() as $module => $schema) { + foreach (Drupal::keyValue('system.schema')->getAll() as $module => $schema) { if ($schema == SCHEMA_UNINSTALLED) { // Nothing to upgrade. continue; diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 5b0b502..f0f5add 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -140,4 +140,135 @@ public static function lock() { return static::$container->get('lock'); } + /** + * Retrieves a configuration object. + * + * This is the main entry point to the configuration API. Calling + * @code Drupal::config('book.admin') @endcode will return a configuration + * object in which the book module can store its administrative settings. + * + * @param string $name + * The name of the configuration object to retrieve. The name corresponds to + * a configuration file. For @code config('book.admin') @endcode, the config + * object returned will contain the contents of book.admin configuration file. + * + * @return Drupal\Core\Config\Config + * A configuration object. + */ + public static function config($name) { + return static::$container->get('config.factory')->get($name); + } + + /** + * Returns a queue for the given queue name. + * + * The following variables can be set by variable_set or $conf overrides: + * - queue_class_$name: The class to be used for the queue $name. + * - queue_default_class: The class to use when queue_class_$name is not + * defined. Defaults to Drupal\Core\Queue\System, a reliable backend using + * SQL. + * - queue_default_reliable_class: The class to use when queue_class_$name is + * not defined and the queue_default_class is not reliable. Defaults to + * Drupal\Core\Queue\System. + * + * @param string $name + * The name of the queue to work with. + * @param bool $reliable + * (optional) TRUE if the ordering of items and guaranteeing every item + * executes at least once is important, FALSE if scalability is the main + * concern. Defaults to FALSE. + * + * @return Drupal\Core\Queue\QueueInterface + * The queue object for a given name. + */ + public static function queue($name, $reliable = FALSE) { + return static::$container->get('queue')->get($name, $reliable); + } + + /** + * Returns a key/value storage collection. + * + * @param $collection + * Name of the key/value collection to return. + * + * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface + */ + public static function keyValue($collection) { + return static::$container->get('keyvalue')->get($collection); + } + + /** + * Returns the state storage service. + * + * Use this to store machine-generated data, local to a specific environment + * that does not need deploying and does not need human editing; for example, + * the last time cron was run. Data which needs to be edited by humans and + * needs to be the same across development, production, etc. environments + * (for example, the system maintenance message) should use config() instead. + * + * @return Drupal\Core\KeyValueStore\KeyValueStoreInterface + */ + public static function state() { + return static::$container->get('state'); + } + + /** + * Returns the default http client. + * + * @return Guzzle\Http\ClientInterface + * A guzzle http client instance. + */ + public static function httpClient() { + return static::$container->get('http_default_client'); + } + + /** + * Returns the entity query object for this entity type. + * + * @param string $entity_type + * The entity type, e.g. node, for which the query object should be + * returned. + * @param string $conjunction + * AND if all conditions in the query need to apply, OR if any of them is + * enough. Optional, defaults to AND. + * + * @return \Drupal\Core\Entity\Query\QueryInterface + * The query object that can query the given entity type. + */ + public static function entityQuery($entity_type, $conjunction = 'AND') { + return static::$container->get('entity.query')->get($entity_type, $conjunction); + } + + /** + * Returns the flood instance. + * + * @return \Drupal\Core\Flood\FloodInterface + */ + public static function flood() { + return static::$container->get('flood'); + } + + /** + * Returns the module handler. + * + * @return \Drupal\Core\Extension\ModuleHandler + */ + public static function moduleHandler() { + return static::$container->get('module_handler'); + } + + /** + * Returns the typed data manager service. + * + * Use the typed data manager service for creating typed data objects. + * + * @return \Drupal\Core\TypedData\TypedDataManager + * The typed data manager. + * + * @see \Drupal\Core\TypedData\TypedDataManager::create() + */ + function typedData() { + return static::$container->get('typed_data'); + } + } diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 6e89fde..ae05f09 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -308,7 +308,7 @@ function aggregator_cron() { ':time' => REQUEST_TIME, ':never' => AGGREGATOR_CLEAR_NEVER )); - $queue = queue('aggregator_feeds'); + $queue = Drupal::queue('aggregator_feeds'); foreach ($result->fetchCol() as $fid) { $feed = aggregator_feed_load($fid); if ($queue->createItem($feed)) { diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/fetcher/DefaultFetcher.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/fetcher/DefaultFetcher.php index f1ae82c..8c059a4 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/fetcher/DefaultFetcher.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/fetcher/DefaultFetcher.php @@ -30,7 +30,8 @@ class DefaultFetcher implements FetcherInterface { * Implements Drupal\aggregator\Plugin\FetcherInterface::fetch(). */ function fetch(Feed $feed) { - $request = drupal_container()->get('http_default_client')->get($feed->url->value); + // @todo: Inject the http client. + $request = \Drupal::httpClient()->get($feed->url->value); $feed->source_string = FALSE; // Generate conditional GET headers. diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index ac8bac3..59fb6fd 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -125,7 +125,7 @@ function hook_cron() { ':time' => REQUEST_TIME, ':never' => AGGREGATOR_CLEAR_NEVER, )); - $queue = queue('aggregator_feeds'); + $queue = Drupal::queue('aggregator_feeds'); foreach ($result as $feed) { $queue->createItem($feed); } diff --git a/core/modules/update/lib/Drupal/update/Tests/UpdateCoreTest.php b/core/modules/update/lib/Drupal/update/Tests/UpdateCoreTest.php index 6c314d2..6e8b1d8 100644 --- a/core/modules/update/lib/Drupal/update/Tests/UpdateCoreTest.php +++ b/core/modules/update/lib/Drupal/update/Tests/UpdateCoreTest.php @@ -201,7 +201,7 @@ function testFetchTasks() { $projectb = array( 'name' => 'bbb_update_test', ); - $queue = queue('update_fetch_tasks'); + $queue = \Drupal::queue('update_fetch_tasks'); $this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty'); update_create_fetch_task($projecta); $this->assertEqual($queue->numberOfItems(), 1, 'Queue contains one item'); diff --git a/core/modules/update/update.fetch.inc b/core/modules/update/update.fetch.inc index 476739a..f43c7f1 100644 --- a/core/modules/update/update.fetch.inc +++ b/core/modules/update/update.fetch.inc @@ -35,7 +35,7 @@ function update_manual_status() { * Reference to an array used for Batch API storage. */ function update_fetch_data_batch(&$context) { - $queue = queue('update_fetch_tasks'); + $queue = Drupal::queue('update_fetch_tasks'); if (empty($context['sandbox']['max'])) { $context['finished'] = 0; $context['sandbox']['max'] = $queue->numberOfItems(); @@ -106,7 +106,7 @@ function update_fetch_data_finished($success, $results) { * Attempts to drain the queue of tasks for release history data to fetch. */ function _update_fetch_data() { - $queue = queue('update_fetch_tasks'); + $queue = Drupal::queue('update_fetch_tasks'); $end = time() + config('update.settings')->get('fetch.timeout'); while (time() < $end && ($item = $queue->claimItem())) { _update_process_fetch_task($item->data); @@ -247,7 +247,7 @@ function _update_create_fetch_task($project) { } $cid = 'fetch_task::' . $project['name']; if (empty($fetch_tasks[$cid])) { - $queue = queue('update_fetch_tasks'); + $queue = Drupal::queue('update_fetch_tasks'); $queue->createItem($project); // Due to race conditions, it is possible that another process already // inserted a row into the {cache_update} table and the following query will diff --git a/core/modules/update/update.install b/core/modules/update/update.install index d6c32d6..b398fe0 100644 --- a/core/modules/update/update.install +++ b/core/modules/update/update.install @@ -69,7 +69,7 @@ function update_schema() { * Implements hook_install(). */ function update_install() { - $queue = queue('update_fetch_tasks', TRUE); + $queue = Drupal::queue('update_fetch_tasks', TRUE); $queue->createQueue(); } @@ -81,7 +81,7 @@ function update_uninstall() { variable_del('update_last_check'); variable_del('update_last_email_notification'); - $queue = queue('update_fetch_tasks'); + $queue = Drupal::queue('update_fetch_tasks'); $queue->deleteQueue(); }