Skip to content

Commit

Permalink
Remove Drush\Drush class; replace with procedural functions that we c…
Browse files Browse the repository at this point in the history
…an use until our DI strategy has been decided.
  • Loading branch information
greg-1-anderson committed Feb 25, 2015
1 parent c08cab9 commit 7718065
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 68 deletions.
27 changes: 27 additions & 0 deletions includes/bootstrap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,30 @@ define('DRUSH_BOOTSTRAP_DRUPAL_FULL', 5);
* be different based on who is logged in.
*/
define('DRUSH_BOOTSTRAP_DRUPAL_LOGIN', 6);

/**
* Used by a Drush extension to request that its Composer autoload
* files be loaded by Drush, if they have not already been.
*
* Usage:
*
* function myextension_init() {
* drush_autoload(__FILE__)
* }
*/
function drush_autoload($commandfile) {
$already_added = commandfiles_cache()->add($commandfile);

if (!$already_added) {
$dir = dirname($commandfile);
$candidates = array("vendor/autoload.php", "../../../vendor/autoload.php");
$drush_autoload_file = drush_get_context('DRUSH_VENDOR_PATH', '');

foreach ($candidates as $candidate) {
$autoload = $dir . '/' . $candidate;
if (file_exists($autoload) && (realpath($autoload) != $drush_autoload_file)) {
include $autoload;
}
}
}
}
17 changes: 13 additions & 4 deletions includes/command.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ function drush_command_normalize_name($command_name) {
* command files.
*/
function drush_commandfile_list() {
return Drush\Drush::commandfiles_cache()->get();
return commandfiles_cache()->get();
}

function _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE) {
Expand All @@ -1392,7 +1392,7 @@ function _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE) {

// Build a list of all of the modules to attempt to load.
// Start with any modules deferred from a previous phase.
$list = Drush\Drush::commandfiles_cache()->deferred();
$list = commandfiles_cache()->deferred();
if (isset($cached_list)) {
$list = array_merge($list, $cached_list);
}
Expand Down Expand Up @@ -1425,7 +1425,7 @@ function _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE) {
// command file cache may not be available anymore, in which case
// we rebuild the cache for this phase.
if ($filepath = realpath($filename)) {
$load_command = Drush\Drush::commandfiles_cache()->add($filepath);
$load_command = commandfiles_cache()->add($filepath);
if ($load_command) {
$needs_sort = TRUE;
}
Expand All @@ -1437,7 +1437,7 @@ function _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE) {
}

if ($needs_sort) {
Drush\Drush::commandfiles_cache()->sort();
commandfiles_cache()->sort();
}
}
}
Expand Down Expand Up @@ -1772,3 +1772,12 @@ function drush_shell_alias_replace() {
_drush_preflight_global_options();
}
}

function commandfiles_cache() {
static $commandfiles_cache = NULL;

if (!isset($commandfiles_cache)) {
$commandfiles_cache = new Drush\Command\Commandfiles();
}
return $commandfiles_cache;
}
2 changes: 1 addition & 1 deletion lib/Drush/Boot/command.inc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function drush_command_belongs_to_disabled_module() {
}
else {
// The command does not define Drupal dependencies. Derive them.
$command_files = Drush\Drush::commandfiles_cache()->get();
$command_files = commandfiles_cache()->get();
$command_path = $commands[$command_name]['path'] . DIRECTORY_SEPARATOR . $commands[$command_name]['commandfile'] . '.drush.inc';
$modules = array_search($command_path, $command_files);
}
Expand Down
63 changes: 0 additions & 63 deletions lib/Drush/Drush.php

This file was deleted.

0 comments on commit 7718065

Please sign in to comment.