Skip to content
This repository has been archived by the owner on Feb 14, 2022. It is now read-only.

config/app.php providers array #6

Closed
unstoppablecarl opened this issue Apr 22, 2015 · 14 comments
Closed

config/app.php providers array #6

unstoppablecarl opened this issue Apr 22, 2015 · 14 comments

Comments

@unstoppablecarl
Copy link

It appears that the providers array in config/app.php CAN NOT be overridden in something like config.local/app.php. Is there a way around this? What other config data cannot be changed using cascading config?

@phanan
Copy link
Owner

phanan commented Apr 23, 2015

It appears that the providers array in config/app.php be overridden in something like config.local/app.php

Isn't this the expected behavior? Can you elaborate?

@DeverStyle
Copy link

Old discussion on the same topic, the idea is that you don't want to replicate/maintain the entire providers array in 2 places. You only want to add the dev providers for the local environment.

@phanan
Copy link
Owner

phanan commented Apr 24, 2015

Thanks @DeverStyle, I get it now. So apparently you can work around with append_config(), which is still available in L5.

@DeverStyle
Copy link

It looks like here for app.providers the arrays are 0 indexed so the local providers would replace existing production providers instead of appending.

@phanan
Copy link
Owner

phanan commented Apr 24, 2015

Well actually I've done a quick check, and it seems app.providers is not overridden:

config/app.php:

    'providers' => [
        'Illuminate\Foundation\Providers\ArtisanServiceProvider',
        'Illuminate\Auth\AuthServiceProvider',
        'Illuminate\Bus\BusServiceProvider',
        'Illuminate\Cache\CacheServiceProvider',
        'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
        'Illuminate\Routing\ControllerServiceProvider',
        'Illuminate\Cookie\CookieServiceProvider',
        // etc etc.

local.config/app.php:

    'providers' => [
        'funny',
    ],

print_r(config('app.providers')) gives:

Array
(
    [0] => funny
    [1] => Illuminate\Auth\AuthServiceProvider
    [2] => Illuminate\Bus\BusServiceProvider
    [3] => Illuminate\Cache\CacheServiceProvider
    [4] => Illuminate\Foundation\Providers\ConsoleSupportServiceProvider
    [5] => Illuminate\Routing\ControllerServiceProvider
    [6] => Illuminate\Cookie\CookieServiceProvider
    [7] => Illuminate\Database\DatabaseServiceProvider
    [8] => Illuminate\Encryption\EncryptionServiceProvider
    // you get the idea
)

@DeverStyle
Copy link

[0] => funny instead of 'Illuminate\Foundation\Providers\ArtisanServiceProvider',

it works with append_config

@phanan
Copy link
Owner

phanan commented Apr 24, 2015

Oh oh. Yeah I saw it. Let me try again.

@phanan
Copy link
Owner

phanan commented Apr 24, 2015

Alright, here you go:

local.config/app.php:

'providers' => append_config([
    'funny',
]),

yields


Array
(
    [0] => Illuminate\Foundation\Providers\ArtisanServiceProvider
    [1] => Illuminate\Auth\AuthServiceProvider
    [2] => Illuminate\Bus\BusServiceProvider
    [3] => Illuminate\Cache\CacheServiceProvider
    [4] => Illuminate\Foundation\Providers\ConsoleSupportServiceProvider
    [5] => Illuminate\Routing\ControllerServiceProvider
    [6] => Illuminate\Cookie\CookieServiceProvider
    [7] => Illuminate\Database\DatabaseServiceProvider
    [8] => Illuminate\Encryption\EncryptionServiceProvider
    [9] => Illuminate\Filesystem\FilesystemServiceProvider
    [10] => Illuminate\Foundation\Providers\FoundationServiceProvider
    [11] => Illuminate\Hashing\HashServiceProvider
    [12] => Illuminate\Mail\MailServiceProvider
    [13] => Illuminate\Pagination\PaginationServiceProvider
    [14] => Illuminate\Pipeline\PipelineServiceProvider
    [15] => Illuminate\Queue\QueueServiceProvider
    [16] => Illuminate\Redis\RedisServiceProvider
    [17] => Illuminate\Auth\Passwords\PasswordResetServiceProvider
    [18] => Illuminate\Session\SessionServiceProvider
    [19] => Illuminate\Translation\TranslationServiceProvider
    [20] => Illuminate\Validation\ValidationServiceProvider
    [21] => Illuminate\View\ViewServiceProvider
    [22] => App\Providers\AppServiceProvider
    [23] => App\Providers\BusServiceProvider
    [24] => App\Providers\ConfigServiceProvider
    [25] => App\Providers\EventServiceProvider
    [26] => App\Providers\RouteServiceProvider
    [27] => PhanAn\CascadingConfig\CascadingConfigServiceProvider
    [10000] => funny
)

So I guess, append_config() then?

@DeverStyle
Copy link

yes, you could update the readme to point people in the right direction.

@phanan
Copy link
Owner

phanan commented Apr 24, 2015

Great idea @DeverStyle. Will do in a minute.

@phanan phanan closed this as completed Apr 24, 2015
@DeverStyle
Copy link

The append_config fix didn't work for me, I got it working as described here by creating a LocalServiceProvider and registering dev providers in there.

@unstoppablecarl
Copy link
Author

There is a typo in my original comment. It should say:

It appears that the providers array in config/app.php CAN NOT be overridden in something like config.local/app.php. Is there a way around this? What other config data cannot be changed using cascading config?

Sorry for the confusion.

@phanan
Copy link
Owner

phanan commented Apr 24, 2015

It appears that the providers array in config/app.php CAN NOT be overridden in something like config.local/app.php

Then I can say I can't replicate that. See above for the discussion between @DeverStyle and me. Do you think you can provide more info?

@langemike
Copy link

Since cascading-config is a provider itself, you have to (re)register the missing providers after the current ones are registered.

What you could do, is extend the Illuminate\Foundation\Application and add a new method:

public function registerMissingConfiguredProviders() {
        $this->afterBootstrapping('Illuminate\Foundation\Bootstrap\RegisterProviders', function($app) {
            $app->registerConfiguredProviders();
        });
}

And add a call to this new method in it's __construct

public function __construct($basePath = null)
{
    parent::__construct($basePath);
    $this->registerMissingConfiguredProviders();
}

Since $app->register does a check for already loaded providers, i believe it doesn't causes a lot of extra overhead.

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

No branches or pull requests

4 participants