Skip to content

Commit

Permalink
Merge branch 'drush-services'
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Apr 28, 2017
2 parents 27485b3 + 0f882ab commit 5e77676
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 48 deletions.
45 changes: 0 additions & 45 deletions drush-services.yml

This file was deleted.

6 changes: 6 additions & 0 deletions drush.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# Drush services
#
# This file defines the core Drush service classes.
#
services:
32 changes: 29 additions & 3 deletions src/Drupal/DrupalKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected function getContainerBuilder() {
}
return $container;
}

/**
* Initializes the service container.
*
Expand All @@ -65,15 +66,40 @@ protected function initializeContainer() {
* {@inheritdoc}
*/
public function discoverServiceProviders() {
// Let Drupal discover all of its service providers
parent::discoverServiceProviders();

// Add those Drush service providers from Drush core that
// need references to the Drupal DI container. This includes
// Drush commands, and those services needed by those Drush
// commands. Note that these commands are not instantiated
// until Drupal is bootstrapped.
$this->addDrushServiceProvider("_drush", DRUSH_BASE_PATH . '/drush.services.yml');

// TODO: We could potentially also add service providers from:
// - DRUSH_BASE_PATH . '/drush/drush.services.yml');
// - DRUSH_BASE_PATH . '/../drush/drush.services.yml');
// Or, perhaps better yet, from every Drush command directory
// (e.g. DRUSH_BASE_PATH/drush/mycmd/drush.services.yml) in
// any of these `drush` folders. In order to do this, it is
// necessary that the class files in these commands are available
// in the autoloader.

// Also add Drush services from all modules
$module_filenames = $this->getModuleFileNames();
// Load each module's serviceProvider class.
foreach ($module_filenames as $module => $filename) {
$filename = dirname($filename) . "/drush.services.yml";
if (file_exists($filename)) {
$this->serviceYamls['app']["drush.$module"] = $filename;
}
$this->addDrushServiceProvider("_drush.$module", $filename);
}
}

/**
* Add a services.yml file if it exists.
*/
protected function addDrushServiceProvider($serviceProviderName, $filename) {
if (file_exists($filename)) {
$this->serviceYamls['app'][$serviceProviderName] = $filename;
}
}
}

0 comments on commit 5e77676

Please sign in to comment.