Skip to content
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

[Proposal] ability to specify Service Provider based on composer.json require or require-dev. #1603

Closed
crynobone opened this issue Jun 11, 2013 · 7 comments

Comments

@crynobone
Copy link
Member

For example if I use Guard, or Generator. It mostly needed on composer --dev environment and not production.

Current Behaviour

These so call development helpers package are great for "development purpose", however due to the way we register "provides" in app/config/app.php all these package need to sit under require instead of require-dev.

Proposed Behaviour

Have a way to detect whether current environment are for "development" or "production", or easier implementation to register array per environment so that we can make use of require-dev in composer.json.

@crynobone
Copy link
Member Author

@WMeldon
Copy link
Contributor

WMeldon commented Jul 25, 2013

I'd like to see an option for this as well. Just realized it was an issue today actually.

I recall reading a something from Taylor regarding the way configurations are loaded and why it doesn't work for array type config options (eg service providers). Something to do with cascading or some other wizardry.

@taylorotwell
Copy link
Member

I would put them in require-dev, and then in your app/start/local.php file you can do:

App::register('GuardServiceProvider');

etc...

@antoniofrignani
Copy link
Contributor

This doesn't work for me.

I have this in my app/start/local.php:

    App::register('DayleRees\ContainerDebug\ServiceProvider');
    App::register('Barryvdh\Debugbar\ServiceProvider');

and, even if i have no errors, i can't get the debug bar in there, nor i can use the php artisan container:debug command. Most probably it is because with App::register method, laravel is calling the register method of the provider but not the boot method.

Had to change my local.php to

    $app = App::getFacadeRoot();
    $dbgbar = new \Barryvdh\Debugbar\ServiceProvider($app);
    App::register( $dbgbar );
    $cntdbg = new \DayleRees\ContainerDebug\ServiceProvider($app);
    App::register( $cntdbg );
    $dbgbar->boot();
    $cntdbg->boot();

to make it work.

To me, it seems a more obvious solution to have this kind of service provider registrations cascade through the various environments app.php config files.

@crynobone
Copy link
Member Author

Note to @taylorotwell on @antoniofrignani comment:

In 4.1 the App::register() method would run $provider->boot() if application is already booted, however this same method doesn't do it in 4.0.

@terion-name
Copy link

But what about aliases in this case?
UPD
This does the trick...

$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Profiler', 'Profiler\Facades\Profiler');

@allanlaal
Copy link

current workaround: https://github.com/percymamedy/laravel-dev-booter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants