veilig
veilig

Reputation: 5135

composer package only for development in laravel providers

If I have a package (that I have to add to app/config/app.php providers/aliases) that I only really want on my development boxes (b/c I only use for development) is there an approach that will allow me to do this leveraging composer require --dev <package> along w/ composer install --no-dev

I need to add an index into both the providers and aliases array...but I would prefer NOT to manage those large arrays in multiple config environment folders if possible

Upvotes: 2

Views: 1397

Answers (2)

ivanhoe
ivanhoe

Reputation: 4753

For anyone looking how to do this in Laravel 5, you can still emulate the L4 behaviour.

On the top of app/Providers/AppServiceProvider add:

use Illuminate\Foundation\AliasLoader;

And then edit the register() method:

public function register()
{

    $path = $this->app->environment() .'.app';
    $config = $this->app->make('config');
    $aliasLoader = AliasLoader::getInstance();

    if ($config->has($path)) {
        array_map([$this->app, 'register'], $config->get($path .'.providers'));

        foreach ($config->get($path .'.aliases') as $key => $class) {
            $aliasLoader->alias($key, $class);
        }
    }
}

Then just add config/<YOUR ENVIRONMENT NAME>/app.php config file and define additional providers and aliases, same as in app.php

For example:

return [

    'providers' => [
        Barryvdh\Debugbar\ServiceProvider::class,
    ],

    'aliases' => [
        'Debugbar' => Barryvdh\Debugbar\Facade::class,
    ],

];

Upvotes: 1

user1669496
user1669496

Reputation: 33148

Create a folder in your config directory that matches your environment name. dev in this case.

Next, recreate any files you wish to override and place them into that folder. app.php in this case

Next open bootstrap/start.php and find $app->detectEnvironment. The array passed to this method determines which environment you are working with. Setting the key to this array as dev will overwrite any of your config files with their counterparts in your dev folder.

If you do not wish to create an entirely new providers array in app.php file for each environment and say you only wanted to add a certain provider to your dev environment, you may use a helper method like so...

'providers' => append_config(array(
    'DevOnlyServiceProvider',
))

All this information was pulled from the Laravel documentation found here: http://laravel.com/docs/configuration

Upvotes: 7

Related Questions