Closed davidverholen closed 8 years ago
So this would make it possible to just require the magento-composer-installer + psr0-autoloader and have your dependancies always autoloaded? Seems interesting and not too hard to create, right?
You could also write the path to the XML node but I guess this is easier and doesn't make a difference when the autoloader isn't used.
So :+1: for this. Or is already possible to rely on composer-installer to load the vendor libraries?
I go even a step further, I modify the bootstrapping, as some classes are loaded before the psr0-autoloader event fires
Manually or with a module? Cause I know I can register to autoloader but if I built a package I need to know that users can autoload the required libraries, without having to do core mods.. or how are you doing that?
https://github.com/Cotya/magento-composer-installer/commit/ebbeccbc673748014f255a2985183890fe9df186 thats the initial commit for this feature, it injects a low level bootstrap into your magento, so basically it does a core mod.
Okay interesting. Is that supposed to be pulled in this repository, or is that your custom fork?
And currently you are just splitting the Mage bootstrapping from the class, and you probably want to add the vendor loader to the bootstrap file?
I guess it would be pointless to ask the Magento guys nicely to make an injection point for custom autoloaders? ;)
haha yes I think that won't happen ;)
So do we actually need to load composer before the modules? I agree that you need to make sure that once you use Composer required classes, you should verify that Composer is loaded, but doesn't need to be before the other classes.
What about something like creating a singleton ComposerAutoload manager, whichs could be just autoloaded by Magento rules. When called (ComposerAutoload::init()
or whatever), it makes sure composer is autoloaded. First time it reads the app/etc/vendor_path.php
file and loads the vendor autoload file. Next time it's called it will just do nothing.
Every module that needs composer autoload support can call the init() method to make sure it can use the classes.
Composer prepends it autoloader so timing wouldn't matter much I guess. Impact should be limited because the class/files are only loaded once. And no need for hacking the core, only 2 requirements:
Or am I thinking to easy?
And you probably won't even need the init method usually, if you let it register to the earliest event. Just when you need it before that, you can force the initialisation by calling it directly.
the earliest event is already to late for some usecases. For example most of the classes you note in /etc/.xml like db backend, cache backend and similar. Also if you work with /shell/.php scripts you get problems, because the earliest event is "different".
Yes but for that you could force it, like I suggested.
If I understand correctly, you suggest that classes, which may get loaded before, should trigger the register of the autoloader itself, right? But I want them to work, without their need to do anything, as "the framework" should handle this. Its a responsibility question, and I dont want to add additional responsibility into classes/modules wanting to make use of it.
I would be totally happy if the framework would handle it automatically :)
But so, is that feature of your planned to be merged in the magento-composer-installer
, or do you want to release it standalone?
Any ETA, or help needed?
this will be a feature of the 3.x release
no ETA yet because of missing development budget to have a steady development. Every help appreciated :)
for communication you can also ping me in https://gitter.im/magento-hackathon/magento-composer-installer, may be a bit simpler as via issues for coordination.
The core mod currently just splits the bootstrap files, not actually inject the composer autoloader, right?
right, still not finally decided on the how, but the app/bootstrap.php
file gets only generated, when it not exist yet, so you can already add every autoloader you like/need there
add a function to create a File which returns the vendor path like in magento2 app/etc/vendor_path.php
https://github.com/magento-hackathon/Magento-PSR-0-Autoloader/issues/4