Thanks for bringing this up. In the context of Drupal and early event is subscribed to in order to register the autoloader automatically. I think the trick here will be to determine if there is an event that is fired in the context of Drush that we can take the same strategy on so we don't have to require devs to register the thing explicitly.
Took a few minutes with Moshe and whiteboarded the challenges. I think there is a better understanding of what the potential issues are and what Composer Manager attempts to do to mitigate, however there is no clear solution at this time.
I don't yet understand the issue well, but Drush's earliest hook is hook_drush_init(). Can you solve this by putting \Drupal::service('composer_manager.manager')->registerAutolaoder(); there?
As far as I can tell, it's too late for my use case, where Drush begins bootstrap, starts to rebuild entity type static caches, then fails (since I have an entity type implementing an interface only reachable from the other autoloader):
I've tried to read through the bootstrap code, but found it difficult to grasp, since it tries to accommodate multiple core versions. Perhaps what we need to do is add an earlier hook.
This is not a problem specific to Drush. Same happens with core/rebuild.php.
In the first place, the problem is that the request event to which composer_manager subscribes to register its autoloader is not fired until the request is being dispatched at HttpKernel::handleRaw().
@pcambra ad me have been working in trying to fire the request kernel event (in rebuild.php and drush) so the autoloader gets notified earlier. We got it but other subscribers to the event try to do things assuming all modules are already loaded (namely PathSubscriber.php tries to get path of 'public' file scheme, but file schemes are initialized to void since file module is not loaded yet). Here's a patch with our work on rebuild.php for reference: https://gist.github.com/jonhattan/84f52cfeb06868cc6ade
Possible solutions:
1. In composer manager. Drop the event subscriber and require the autoloader in settings.php (Per hook_boot() change record).
2. In core. Propose a new event that fires earlier. For example "aferboot" or "prerequest" at Drupal::Kernel::handle.
3. In core. Ask someone. Put an eye on autoloader related issues and wait for some resolution. Possible related:
Comments
Comment #1
cpliakas commentedComment #2
jbrown commentedCurrently you need
in a drush command due to #1955386: Automatically register Composer's autoloader early in the bootstrap process to improve DX
Comment #3
cpliakas commentedThanks for bringing this up. In the context of Drupal and early event is subscribed to in order to register the autoloader automatically. I think the trick here will be to determine if there is an event that is fired in the context of Drush that we can take the same strategy on so we don't have to require devs to register the thing explicitly.
Comment #4
cpliakas commentedTook a few minutes with Moshe and whiteboarded the challenges. I think there is a better understanding of what the potential issues are and what Composer Manager attempts to do to mitigate, however there is no clear solution at this time.
Comment #5
moshe weitzman commentedI don't yet understand the issue well, but Drush's earliest hook is hook_drush_init(). Can you solve this by putting
\Drupal::service('composer_manager.manager')->registerAutolaoder();there?Comment #6
bojanz commentedAs far as I can tell, it's too late for my use case, where Drush begins bootstrap, starts to rebuild entity type static caches, then fails (since I have an entity type implementing an interface only reachable from the other autoloader):
I've tried to read through the bootstrap code, but found it difficult to grasp, since it tries to accommodate multiple core versions. Perhaps what we need to do is add an earlier hook.
Comment #7
pcambraCrossposting https://github.com/drush-ops/drush/issues/718 here
Comment #8
jonhattanThis is not a problem specific to Drush. Same happens with core/rebuild.php.
In the first place, the problem is that the
requestevent to which composer_manager subscribes to register its autoloader is not fired until the request is being dispatched at HttpKernel::handleRaw().@pcambra ad me have been working in trying to fire the
requestkernel event (in rebuild.php and drush) so the autoloader gets notified earlier. We got it but other subscribers to the event try to do things assuming all modules are already loaded (namely PathSubscriber.php tries to get path of 'public' file scheme, but file schemes are initialized to void since file module is not loaded yet). Here's a patch with our work on rebuild.php for reference: https://gist.github.com/jonhattan/84f52cfeb06868cc6adePossible solutions:
1. In composer manager. Drop the event subscriber and require the autoloader in settings.php (Per hook_boot() change record).
2. In core. Propose a new event that fires earlier. For example "aferboot" or "prerequest" at Drupal::Kernel::handle.
3. In core. Ask someone. Put an eye on autoloader related issues and wait for some resolution. Possible related:
* #2023325: Add interface for classloader so it can be cleanly swapped
* #2253593: Stop classloader searching filesystem for classes before drupal_classloader() is called
* #1241190: Possible approaches to bootstrap/front loading of classes
* #1818628: Use Composer's optimized ClassLoader for Core/Component classes
Comment #9
jonhattanI can confirm that
require 'sites/all/vendor/autoload.php';in settings.php fixes the issue.Comment #10
moshe weitzman commented@chris - what do you think of requiring autoload.php in settings.php per #9? maybe thats a temporary workaround?
Comment #11
bojanz commentedThis will be resolved by #2350639: Rewrite 8.x-1.x, since composer_manager will stop having its own autoloader.
Thanks for the feedback and the help in identifying the underlying causes.