How to define providers that only work in a local environment with Laravel 4?

Asked

Viewed 123 times

0

On Laravel 4, we have a file called app/config/app.php, that we use to be able to define configuration information that will be used in the application.

When I am in development environment, I configure the application to process the app/config/local/app.phpin order to have information that will be used only in a development environment.

But I have a problem: When I try to add a value in providers to be process only in local environment, I’m getting errors running the Artisan or memso the application.

I imagine this is happening because, when we store a configuration file, the indexes of app/config/app.phpare replaced by what we use in app/config/local/app.php, and probably this is causing some item of the index providers be removed.

Example app/config/app.php:

'providers' => array(

    'Illuminate\Auth\AuthServiceProvider',
    'Illuminate\Auth\Reminders\ReminderServiceProvider',
    'Illuminate\Cache\CacheServiceProvider',
    'Illuminate\Cookie\CookieServiceProvider',
    'Illuminate\Database\DatabaseServiceProvider',
    'Illuminate\Database\MigrationServiceProvider',
    'Illuminate\Database\SeedServiceProvider',
    'Illuminate\Encryption\EncryptionServiceProvider',
    'Illuminate\Filesystem\FilesystemServiceProvider',
    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
    'Illuminate\Hashing\HashServiceProvider',
    'Illuminate\Html\HtmlServiceProvider',
    'Illuminate\Log\LogServiceProvider',
    'Illuminate\Mail\MailServiceProvider',
    'Illuminate\Pagination\PaginationServiceProvider',
    'Illuminate\Queue\QueueServiceProvider',
    'Illuminate\Redis\RedisServiceProvider',
    'Illuminate\Remote\RemoteServiceProvider',
    'Illuminate\Routing\ControllerServiceProvider',
    'Illuminate\Session\CommandsServiceProvider',
    'Illuminate\Session\SessionServiceProvider',
    'Illuminate\Translation\TranslationServiceProvider',
    'Illuminate\Validation\ValidationServiceProvider',
    'Illuminate\View\ViewServiceProvider',
    'Illuminate\Workbench\WorkbenchServiceProvider',

Example app/config/local/app.php:

'providers' => array(
     'Way\Generators\GeneratorsServiceProvider',
     'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider',
 )

How can I solve this problem?

1 answer

0


In Laravel 4, there is a function called append_config, that reindexes a array for a high numbering, starting from the 99999.

This happens because the class Config by default override the arrays same indexes present in the settings files. When you set a local configuration, the value set there replaces the original value.

So, you could set your file app/config/local/app.php as follows:

'providers' => append_config(array(
     'Way\Generators\GeneratorsServiceProvider',
     'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider',
 ))

To be honest, I found the solution to append_config a bit of a nut. So I preferred to settle by naming the contents:

'providers' => array(
     'local.generator.provider' => 'Way\Generators\GeneratorsServiceProvider',
     'local.xethron.providers' => 'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider',
 )

In the above case, appointments will not collide, since by default, the file app/config/app.php uses a array no index (which makes it sequential and numerical).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.