-
-
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
Autoload bootstrap #1165
Conversation
…ll it from drush_autoload.
…ser libraries can interact with Drush via Drush\Drush::autoload().
… now Drush\Drush::autoload().
…te selection and all site-specific config file loading until after the bootstrap class has been found. Give commandfiles a chance to provide bootstrap candidates, but for now always use the built-in instance.
…ar order. Move valid_root() function into DrupalBoot class.
The tests passed when I ran on my branch: https://travis-ci.org/greg-1-anderson/drush/builds/50285664 If this is okay to commit, I will rebase and fix the merge conflicts. |
return $candidate; | ||
} | ||
} | ||
return FALSE; | ||
return null; |
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.
capitalize here, and above (in the diff)
Left a few comments. I think this looks good. Might have to wait for Drush 8 though. Will chat with Greg. |
$bootstrap->preflight(); | ||
// Find the selected site based on --root, --uri or cwd, and | ||
// return the bootstrap object that goes with it. | ||
$bootstrap = _drush_preflight_root(); |
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.
As I said offline, I'd like to get some of this stuff in for Drupal 7 branch for better maintainability. Other parts, like making a Drush\Drush class, is not as important to me, and can wait until later. The one thing we'd need to figure out, if we punt Drush\Drush and keep the rest, is how the existing procedural code should get a reference to the commandfile class. This sort of thing is usually done with a singleton pattern, but that's not really a best practice in code that uses DI, and I don't know that we want to put in a dependency injection container in Drush 7. That's why I settled for a static class (Drush\Drush) that held our other classes that use modern techniques. Maybe we could just fake this with drush_set_context for now, if you don't want Drush\Drush. |
…an use until our DI strategy has been decided.
In the commits above, I removed the Drush\Drush class, and went with simple procedural access functions. Maybe we can put this in for Drush 7 just as a bootstrap cleanup, and continue with DI stuff after we kick off Drush 8. |
Giving this a try with Backdrop so we can try to package in "Backdrush" with Backdrop apps for Kalabox2. The custom Boot class seems to load good and proper. Not as familiar with Drush or Backdrop as i would like to be... but it seems like after getting the custom class to load and writing a good valid_path method for backdrop the task is to write custom bootstrap.inc and command.inc files to actually handle the bootstrapping of backdrop. Does that approach sound on target to you? |
So i gave this a shot and it works decently (read: some basic stuff works like What i'm using right now is this custom Boot class plus associated files Plus this hacky hack to get drush to recognize that Backdrop is Drupal 7 compatible. Some observations and thoughts here:
I'm more than happy to keep working on this but it would be good to get some feedback on these things and ideally a consensus-ish direction on how to proceed. |
Also let me know if you want me to create a new issue for this! |
Update over here: So actually have got this working on Backdrop ... seemed like some commands just didn't have a bootstrap level. Not sure why that is but if you give them FULL BOOTSTRAP everything seems to work. Of course i dont think we want to blanket full bootstrap all commands that have no bootstrap level specified so going to investigate this a little more and see if there is a better way to add this data in. |
Waiting for Moshe to get back from vacation, to review this and see if it we can get it in for Drush 7. The Backdrop continuation work is looking good, but I think that this discussion should be continued at #342. |
Cool cool! I'll kick these comments over there then! On Sunday, February 22, 2015, Greg Anderson [email protected]
Cheers, Mike Pirog |
This looks good to me. Please take one last look at my code comments and see if any are unaddressed. Then, feel free to merge. Also, I think the title of this PR should be updated as it morphed over time. |
Merged into master. Thanks. |
Pumped to see this merged! On Wed, Feb 25, 2015 at 12:42 PM, Greg Anderson [email protected]
Cheers, Mike Pirog |
This is a continuation of #1156. I started a new branch in case I needed to back up, but I'm pretty happy about how this is straightening out.
This patch no longer attempts to rely on Composer for initialization. Doing Symfony Console-like stuff looks like a great idea, but we'll have to tackle this later, in Drush 8. For now, I am maintaining the behavior of the current Drush bootstrap. Commandfiles must exist in the usual magic locations (~/.drush, etc.)
The bootstrap is a lot cleaner now. In drush.php, the main preflight phases are now:
drush_preflight();
$bootstrap = _drush_preflight_root();
drush_preflight_site();
These preflight phases also appear in preflight.inc in this order, and their responsibilities are much more clearly defined. valid_root() is moved to the Boot class.
So, if you have a commandfile in ~/.drush, it can define a Boot class that is consulted when searching for the Drupal root from the cwd. Once a Boot class is found, Drush remembers it for successive operations, so existing sitealias code & c. still works the same way it always has.
If this looks okay, I think that some of the code from the bootstrap.inc next to DrupalBoot could be moved into includes/bootstrap.inc. Taking the "DRUPAL" out of some of these constants will have to be a Drupal-8 activity.
Oh, and Drush\Drush::autoload() still exists, but now the recommended time to call it is in your drush_hook_init(). I just realized that autoload() is still adding the commandfile; this is innocuous, but unnecessary. I'll remove it. The only purpose of this method will be to include the Drush extension's autoload.php file, if it was not already included as part of the Drupal site's autoload.php.