-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autoload bootstrap #1165
Closed
greg-1-anderson
wants to merge
14
commits into
drush-ops:master
from
greg-1-anderson:autoload-bootstrap
Closed
Autoload bootstrap #1165
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d779126
Preliminary implementation of drush_autoload() function.
greg-1-anderson 785aaa9
Factor out drush_add_commandfile from _drush_add_commandfiles, and ca…
greg-1-anderson 490c17b
Test drush_autoload
greg-1-anderson d4e8000
#572: Move commandfile cache to its own class, so that composer libra…
greg-1-anderson 2b831a9
Remove drush-autoload branch from travis.yml.
greg-1-anderson 6c983c5
Remove drush_autoload function from environment.inc; this function is…
greg-1-anderson f56c55a
Move bootstrap object creation into a separate function.
greg-1-anderson cc9fedd
Separate out drush_preflight_site() from drush_preflight(), moving si…
greg-1-anderson d1ca77a
Test the autoload-bootstrap branch
greg-1-anderson 6c79252
Straighten out bootstrap, so dependencies are executed in a more line…
greg-1-anderson bb7abcc
Code style: use NULL instead of null.
greg-1-anderson 477ae81
Remove Drush\Drush class; replace with procedural functions that we c…
greg-1-anderson 3aef5a2
Remove spurrious constant.
greg-1-anderson f99aadf
Remove testing of autload-bootstrap branch in .travis.yml.
greg-1-anderson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
|
||
|
||
/** | ||
* No bootstrap. | ||
* | ||
* This constant is only used to indicate that the bootstrap process has | ||
* not started yet. It is not possible to have no bootstrap. | ||
*/ | ||
define('DRUSH_BOOTSTRAP_NONE', -1); | ||
|
||
/** | ||
* Use drush_bootstrap_max instead of drush_bootstrap_to_phase | ||
* | ||
* This constant is only usable as the value of the 'bootstrap' | ||
* item of a command object, or as the parameter to | ||
* drush_bootstrap_to_phase. It is not a real bootstrap state. | ||
*/ | ||
define('DRUSH_BOOTSTRAP_MAX', -2); | ||
|
||
/** | ||
* @deprecated | ||
* | ||
* No longer used, but 0 remains reserved. Drush always runs preflight. | ||
* Commands may alternatively use DRUSH_BOOTSTRAP_NONE. | ||
*/ | ||
define('DRUSH_BOOTSTRAP_DRUSH', 0); | ||
|
||
/** | ||
* Set up and test for a valid drupal root, either through the -r/--root options, | ||
* or evaluated based on the current working directory. | ||
* | ||
* Any code that interacts with an entire Drupal installation, and not a specific | ||
* site on the Drupal installation should use this bootstrap phase. | ||
*/ | ||
define('DRUSH_BOOTSTRAP_DRUPAL_ROOT', 1); | ||
|
||
/** | ||
* Set up a Drupal site directory and the correct environment variables to | ||
* allow Drupal to find the configuration file. | ||
* | ||
* If no site is specified with the -l / --uri options, Drush will assume the | ||
* site is 'default', which mimics Drupal's behaviour. | ||
* | ||
* If you want to avoid this behaviour, it is recommended that you use the | ||
* DRUSH_BOOTSTRAP_DRUPAL_ROOT bootstrap phase instead. | ||
* | ||
* Any code that needs to modify or interact with a specific Drupal site's | ||
* settings.php file should bootstrap to this phase. | ||
*/ | ||
define('DRUSH_BOOTSTRAP_DRUPAL_SITE', 2); | ||
|
||
/** | ||
* Load the settings from the Drupal sites directory. | ||
* | ||
* This phase is analagous to the DRUPAL_BOOTSTRAP_CONFIGURATION bootstrap phase in Drupal | ||
* itself, and this is also the first step where Drupal specific code is included. | ||
* | ||
* This phase is commonly used for code that interacts with the Drupal install API, | ||
* as both install.php and update.php start at this phase. | ||
*/ | ||
define('DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION', 3); | ||
|
||
/** | ||
* Connect to the Drupal database using the database credentials loaded | ||
* during the previous bootstrap phase. | ||
* | ||
* This phase is analogous to the DRUPAL_BOOTSTRAP_DATABASE bootstrap phase in | ||
* Drupal. | ||
* | ||
* Any code that needs to interact with the Drupal database API needs to | ||
* be bootstrapped to at least this phase. | ||
*/ | ||
define('DRUSH_BOOTSTRAP_DRUPAL_DATABASE', 4); | ||
|
||
/** | ||
* Fully initialize Drupal. | ||
* | ||
* This is analogous to the DRUPAL_BOOTSTRAP_FULL bootstrap phase in | ||
* Drupal. | ||
* | ||
* Any code that interacts with the general Drupal API should be | ||
* bootstrapped to this phase. | ||
*/ | ||
define('DRUSH_BOOTSTRAP_DRUPAL_FULL', 5); | ||
|
||
/** | ||
* Log in to the initialiased Drupal site. | ||
* | ||
* This is the default bootstrap phase all commands will try to reach, | ||
* unless otherwise specified. | ||
* | ||
* This bootstrap phase is used after the site has been | ||
* fully bootstrapped. | ||
* | ||
* This phase will log you in to the drupal site with the username | ||
* or user ID specified by the --user/ -u option. | ||
* | ||
* Use this bootstrap phase for your command if you need to have access | ||
* to information for a specific user, such as listing nodes that might | ||
* 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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the part of the PR that is most important to me. This and the corresponding code re-org that goes with it makes the Drush bootstrap much cleaner, and I'd rather not go keep the existing code around for all of the Drush 7 stable branch's life.