-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[5.5] Autoload Package Providers #19420
Conversation
I like this idea 👍 |
@driesvints Can't 👍 enough! |
@m1guelpf yeah, this falls outside the caching commands. It'll create a new |
@driesvints And wouldn't this broke everything if a non-existent provider is provided? Is there some thind of check for this before caching? |
@m1guelpf I added a new commit where we'll check first to see if the class exists before registering. |
@driesvints What will happen to the providers on the config/app.php file? |
@m1guelpf nothing. They'll continue to work as expected. That part remains untouched. |
This looks amazing, I'm wondering why it's not been done before |
Yes this is great idea. Even if a single package have multiple providers which usually don't happen can it work? |
@bloggervista this indeed also works for multiple providers |
Few problems I have with this:
Personally, I would prefer to see some kind of |
You can still turn off this behavior and use your own providers to have these checks. You can add a package to
You can turn off this behaviour through the config option and register the providers manually in
I thought of this and considered having an
This is true & we're checking in on that.
This is a different discussion I believe :) |
@garygreen I have rewritten some things to address all of those concerns. |
Nice, look forward to seeing it. It would be nice if the |
It would be opcached in production anyways. |
The only one thing about this way to loading service providers. What if I want to use package but extend service provider with my own one? Is it possible? |
@a-komarev yes, there's a config option to turn off the behavior. |
@a-komarev and you'll be able to not auto-discover individual packages. |
All of the concerns expressed so far have been addressed. I am about to push the code. |
This is nice feature, however the order of loading them might need further discussion, for instance I tried using laravel passport and it failed to the concept as it expects to have auth class defined in the container, where as that doesn't seem to exists. |
@raftalks I think it's best that you open an issue on the passport repo for that |
@driesvints What what order will the plugin will be auto loaded ? I mean is it like adding service provider at last ? |
@bloggervista behavior was recently changed: #19646 |
Thanks for info i was worried about it :) |
@driesvints what is the new config option to disable auto-discovery altogether ? I am using the latest 5.5-dev and auto-discovery is enabled and working. But I can't seem to find any new option in any of the config files that have something to do with package discovery |
@vesper8 Try defining At least that's what's being used on this PR. |
@vesper8 you can use this:
Here are the docs: https://laravel.com/docs/master/packages#package-discovery @brunogaspar Note the quote in the first comment: the implementation here has been greatly refactored. |
is there a way to list all the service providers and aliases that have been discovered ?
something like I know they are listed in /bootstrap/cache/packages.php but think it would be nice to have them listed in the console edit: proposed my own PR to add this functionality #20938 |
This PR adds autoloading functionality for packages. Package maintainers can define their providers through the
extra
key in theircomposer.json
file and they will be automatically loaded by the framework, eliminating the need for developers to manually register them.Example:
Or define multiple providers:
Benefits
require
list. They may simple be added inrequire-dev
and when deploying to production, they won't be loaded into the app anymoreSome Notes
packages.php
file inbootstrap/cache
PackageAssetLoader
accepts any given key so you can still use it for other keys than justproviders