├── .gitignore
├── phpcs.xml.dist
├── CODE_OF_CONDUCT.md
├── .editorconfig
├── tests
├── Helpers
│ ├── MyLocalServiceProvider.php
│ └── MyStagingServiceProvider.php
├── TestCase.php
└── Unit
│ ├── Aliases
│ ├── EmptyConditionalAliasTest.php
│ ├── ConditionalAliasTestCase.php
│ └── ConditionalAliasTest.php
│ └── Providers
│ ├── EmptyConditionalProviderTest.php
│ ├── ConditionalProviderTest.php
│ └── ConditionalProviderTestCase.php
├── ISSUE_TEMPLATE.md
├── src
└── ConditionalProvidersServiceProvider.php
├── phpunit.xml.dist
├── LICENSE.md
├── CONTRIBUTING.md
├── PULL_REQUEST_TEMPLATE.md
├── .travis.yml
├── CHANGELOG.md
├── composer.json
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | composer.phar
3 | composer.lock
4 | .DS_Store
5 |
--------------------------------------------------------------------------------
/phpcs.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ./src
6 | ./tests
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Code of Conduct
2 |
3 | It's simple, really:
4 |
5 | - Everyone is welcome to contribute
6 | - Use common sense at all times
7 | - Be open to other opinions and constructive criticism
8 | - Be friendly
9 |
10 | Feel like someone's in violation of this? [Contact me directly][link-author-email].
11 |
12 | [link-author-email]: mailto:hello@sebastiaanluca.com
13 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | ; This file is for unifying the coding style for different editors and IDEs.
2 | ; More information at http://editorconfig.org
3 |
4 | root = true
5 |
6 | [*]
7 | charset = utf-8
8 | indent_size = 4
9 | indent_style = space
10 | end_of_line = lf
11 | insert_final_newline = true
12 | trim_trailing_whitespace = true
13 |
14 | [*.md]
15 | trim_trailing_whitespace = false
16 |
17 | [*.yml]
18 | indent_size = 2
19 |
--------------------------------------------------------------------------------
/tests/Helpers/MyLocalServiceProvider.php:
--------------------------------------------------------------------------------
1 | detectEnvironment(function () {
28 | return $this->environment;
29 | });
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/Unit/Aliases/EmptyConditionalAliasTest.php:
--------------------------------------------------------------------------------
1 | getAliases();
22 |
23 | $this->assertTrue(count($aliases) > 1);
24 |
25 | $this->assertArrayNotHasKey('MyLocalFacade', $aliases);
26 | $this->assertArrayNotHasKey('MyStagingFacade', $aliases);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Description
2 |
3 | Make it clear if the issue is a **bug**, an **enhancement** or just a **question**. The easiest way to indicate this is to prefix the title, e.g. `[Question] I have a question`.
4 |
5 | Provide a detailed description of the change or addition you are proposing. Include some screenshots or code examples if possible.
6 |
7 | ### Your environment
8 |
9 | If you're reporting a bug or asking a specific question, include as many relevant details about your environment so we can reproduce it. The more, the better.
10 |
11 | - Package version or last commit
12 | - Operating system and version
13 | - PHP version
14 | - Laravel version
15 | - Related package versions
16 | - …
17 |
18 | ## Context
19 |
20 | Why is this change important to you? How would you use it? How can it benefit other users?
21 |
22 | ## Possible implementation
23 |
24 | Not obligatory, but suggest an idea for implementing addition or change.
25 |
--------------------------------------------------------------------------------
/tests/Unit/Providers/EmptyConditionalProviderTest.php:
--------------------------------------------------------------------------------
1 | app->getLoadedProviders();
23 |
24 | $this->assertTrue(count($providers) > 1);
25 |
26 | $this->assertArrayNotHasKey(MyLocalServiceProvider::class, $providers);
27 | $this->assertArrayNotHasKey(MyStagingServiceProvider::class, $providers);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/ConditionalProvidersServiceProvider.php:
--------------------------------------------------------------------------------
1 | app->environment();
20 |
21 | $providers = $this->app['config']->get('app.' . $environment . '_providers', []);
22 |
23 | foreach ($providers as $provider) {
24 | $this->app->register($provider);
25 | }
26 |
27 | $facades = $this->app['config']->get('app.' . $environment . '_aliases', []);
28 |
29 | foreach ($facades as $class => $name) {
30 | AliasLoader::getInstance()->alias($class, $name);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 | ./tests/Feature
22 |
23 |
24 | ./tests/Unit
25 |
26 |
27 |
28 |
29 | src/
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/tests/Unit/Providers/ConditionalProviderTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(count($this->app->getLoadedProviders()) > 1);
24 | }
25 |
26 | public function test it loads providers based on environment() : void
27 | {
28 | $this->assertArrayHasKey(MyLocalServiceProvider::class, $this->app->getLoadedProviders());
29 | }
30 |
31 | public function test it does not load providers from other environments() : void
32 | {
33 | $this->assertArrayNotHasKey(MyStagingServiceProvider::class, $this->app->getLoadedProviders());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # The MIT License (MIT)
2 |
3 | Copyright (c) 2017 Sebastiaan Luca
4 |
5 | > Permission is hereby granted, free of charge, to any person obtaining a copy
6 | > of this software and associated documentation files (the "Software"), to deal
7 | > in the Software without restriction, including without limitation the rights
8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | > copies of the Software, and to permit persons to whom the Software is
10 | > furnished to do so, subject to the following conditions:
11 | >
12 | > The above copyright notice and this permission notice shall be included in
13 | > all copies or substantial portions of the Software.
14 | >
15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | > THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Contributions are very welcome and will be fully credited.
4 |
5 | We accept contributions via pull requests.
6 |
7 | ## Pull request guidelines
8 |
9 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - Don't go crazy with the formatting.
10 |
11 | - **Add tests** - Your patch won't be accepted if it doesn't have tests. Don't worry though! Feel free to submit a PR without, we'll help you along the way.
12 |
13 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
14 |
15 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
16 |
17 | - **Create feature branches** - Don't ask us to pull from your master branch unless it only contains the PR code.
18 |
19 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
20 |
21 | - **Send coherent history** - Make sure each commit in your pull request is somewhat meaningful and contains related changes. Don't go overboard by changing a dozen files and doing everything in a single commit.
22 |
--------------------------------------------------------------------------------
/tests/Unit/Aliases/ConditionalAliasTestCase.php:
--------------------------------------------------------------------------------
1 | push('app.providers', ConditionalProvidersServiceProvider::class);
24 |
25 | $app['config']->set(
26 | 'app.local_aliases',
27 | ['MyLocalFacade' => 'SebastiaanLuca\\ConditionalProviders\\MyLocalFacade']
28 | );
29 |
30 | $app['config']->set(
31 | 'app.staging_aliases',
32 | ['MyStagingFacade' => 'SebastiaanLuca\\ConditionalProviders\\MyStagingFacade']
33 | );
34 |
35 | $app['config']->set('app.testing_aliases', []);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/Unit/Aliases/ConditionalAliasTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(count(AliasLoader::getInstance()->getAliases()) > 1);
23 | }
24 |
25 | public function test it loads aliases based on environment() : void
26 | {
27 | $aliases = AliasLoader::getInstance()->getAliases();
28 |
29 | $this->assertArrayHasKey('MyLocalFacade', $aliases);
30 | $this->assertSame('SebastiaanLuca\\ConditionalProviders\\MyLocalFacade', $aliases['MyLocalFacade']);
31 | }
32 |
33 | public function test it does not load aliases from other environments() : void
34 | {
35 | $this->assertArrayNotHasKey('MyStagingFacade', AliasLoader::getInstance()->getAliases());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/Unit/Providers/ConditionalProviderTestCase.php:
--------------------------------------------------------------------------------
1 | push('app.providers', ConditionalProvidersServiceProvider::class);
26 |
27 | $app['config']->set(
28 | 'app.local_providers',
29 | [MyLocalServiceProvider::class]
30 | );
31 |
32 | $app['config']->set(
33 | 'app.staging_providers',
34 | [MyStagingServiceProvider::class]
35 | );
36 |
37 | $app['config']->set('app.testing_providers', []);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## PR Type
2 |
3 | What kind of pull request is this? Put an `x` in all the boxes that apply:
4 |
5 | - [ ] Bug fix (non-breaking change which fixes an issue)
6 | - [ ] New feature (non-breaking change which adds functionality)
7 | - [ ] Extend feature (non-breaking change which extends existing functionality)
8 | - [ ] Change feature (non-breaking change which either changes or refactors existing functionality)
9 | - [ ] Breaking change (fix or feature that would cause existing functionality to change)
10 |
11 | ## What does it change?
12 |
13 | Describe your changes in detail.
14 |
15 | ## Why this PR?
16 |
17 | Why is this change required? What problem does it solve?
18 |
19 | ## How has this been tested?
20 |
21 | Please describe in detail how you tested your changes (or are planning on testing them).
22 |
23 | ## Checklist
24 |
25 | To facilitate merging your change and the approval of this PR, please make sure you've reviewed and applied the following:
26 |
27 | - This PR addresses exactly one issue
28 | - All changes were made in a fork of this project (preferably also in a separate branch)
29 | - It follows the code style of this project
30 | - Tests were added to cover the changes
31 | - All previously existing tests still pass
32 | - If the change to the code requires a change to the documentation, it has been updated accordingly
33 |
34 | If you're unsure about any of these, don't hesitate to ask. We're here to help!
35 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 7.3
5 | - 7.4
6 | - nightly
7 |
8 | cache:
9 | directories:
10 | - $HOME/.composer/cache
11 |
12 | env:
13 | matrix:
14 | - LARAVEL_VERSION="^6.0" COMPOSER_FLAGS="--prefer-lowest"
15 | - LARAVEL_VERSION="^6.0" COMPOSER_FLAGS="--prefer-stable"
16 | - LARAVEL_VERSION="^7.0" COMPOSER_FLAGS="--prefer-lowest"
17 | - LARAVEL_VERSION="^7.0" COMPOSER_FLAGS="--prefer-stable"
18 | - LARAVEL_VERSION="dev-master" ORCHESTRA_VERSION="dev-master" COMPOSER_FLAGS="--prefer-lowest" MINIMUM_STABILITY="dev"
19 | - LARAVEL_VERSION="dev-master" ORCHESTRA_VERSION="dev-master" COMPOSER_FLAGS="--prefer-stable" MINIMUM_STABILITY="dev"
20 |
21 | matrix:
22 | allow_failures:
23 | - php: nightly
24 | - env: LARAVEL_VERSION="dev-master" ORCHESTRA_VERSION="dev-master" COMPOSER_FLAGS="--prefer-lowest" MINIMUM_STABILITY="dev"
25 | - env: LARAVEL_VERSION="dev-master" ORCHESTRA_VERSION="dev-master" COMPOSER_FLAGS="--prefer-stable" MINIMUM_STABILITY="dev"
26 | fast_finish: true
27 |
28 | before_install:
29 | - composer validate --strict
30 | - travis_retry composer self-update
31 | - if [[ -n ${MINIMUM_STABILITY} ]]; then composer config minimum-stability ${MINIMUM_STABILITY}; echo "Minimum stability set to ${MINIMUM_STABILITY}"; else echo "Minimum stability left unchanged"; fi
32 | - if [[ -n ${ORCHESTRA_VERSION} ]]; then composer require orchestra/testbench=${ORCHESTRA_VERSION} --dev --no-update; else echo "orchestra/testbench version requirement left unchanged"; fi
33 | - composer require laravel/framework=${LARAVEL_VERSION} --no-update
34 |
35 | install:
36 | - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
37 |
38 | script:
39 | - vendor/bin/phpunit
40 |
41 | notifications:
42 | email:
43 | on_failure: change
44 | on_success: never
45 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All Notable changes to `sebastiaanluca/laravel-conditional-providers` will be documented in this file.
4 |
5 | Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
6 |
7 | ## 5.0.0 (2020-04-24)
8 |
9 | ### Added
10 |
11 | - Added support for Laravel 7
12 |
13 | ### Removed
14 |
15 | - Dropped support for Laravel 5
16 | - Dropped support for PHP 7.2
17 |
18 | ## 4.0.0 (2019-08-11)
19 |
20 | - Add support for Laravel 6.0
21 |
22 | ## 3.0.0 (2019-03-01)
23 |
24 | ### Added
25 |
26 | - Added support for Laravel 5.8
27 |
28 | ### Removed
29 |
30 | - Removed support for Laravel 5.7 and lower
31 |
32 | ### Fixed
33 |
34 | - Fixed static code analyses
35 |
36 | ## 2.0.1 (2018-09-04)
37 |
38 | ### Changed
39 |
40 | - Tweak code analyses
41 | - Add code analyses to tests
42 |
43 | ## 2.0.1 (2018-09-04)
44 |
45 | ### Added
46 |
47 | - Code analyses
48 |
49 | ### Changed
50 |
51 | - Renamed `phpunit.xml`
52 |
53 | ### Fixed
54 |
55 | - Don't test against Laravel 5.6
56 | - Fix laravel/framework version requirement
57 | - Optimized code using static code analyses
58 |
59 | ## 2.0.0 (2018-09-04)
60 |
61 | ### Added
62 |
63 | - Run tests against Laravel 5.7
64 |
65 | ### Changed
66 |
67 | - Formatted tests
68 |
69 | ### Removed
70 |
71 | - Removed support for PHP 7.1 and lower
72 | - Removed support for Laravel 5.6 and lower
73 |
74 | ## 1.1.0 (2017-07-19)
75 |
76 | - Added conditional loading of aliases (facades)
77 | - Refactored and fixed tests
78 |
79 | ## 1.0.0 (2017-07-13)
80 |
81 | ### Added
82 |
83 | - Added the conditional environment service provider
84 | - Set up test environment and added tests
85 | - Written readme and guidelines
86 | - Added Laravel 5.5 auto-discovery
87 |
88 | ### Changed
89 |
90 | - Renamed service provider to `\SebastiaanLuca\ConditionalProviders\ConditionalProvidersServiceProvider`
91 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sebastiaanluca/laravel-conditional-providers",
3 | "type": "library",
4 | "description": "Load Laravel service providers based on the current environment.",
5 | "keywords": [
6 | "laravel",
7 | "service provider",
8 | "environment",
9 | "conditional"
10 | ],
11 | "homepage": "https://github.com/sebastiaanluca/laravel-conditional-providers",
12 | "license": "MIT",
13 | "authors": [
14 | {
15 | "name": "Sebastiaan Luca",
16 | "email": "hello@sebastiaanluca.com",
17 | "homepage": "https://www.sebastiaanluca.com",
18 | "role": "Author"
19 | }
20 | ],
21 | "require": {
22 | "php": "^7.3",
23 | "laravel/framework": "^6.0|^7.0"
24 | },
25 | "require-dev": {
26 | "orchestra/testbench": "^4.0|^5.1",
27 | "phpunit/phpunit": "^8.5"
28 | },
29 | "autoload": {
30 | "psr-4": {
31 | "SebastiaanLuca\\ConditionalProviders\\": "src"
32 | }
33 | },
34 | "autoload-dev": {
35 | "psr-4": {
36 | "SebastiaanLuca\\ConditionalProviders\\Tests\\": "tests"
37 | }
38 | },
39 | "scripts": {
40 | "composer-validate": "@composer validate --no-check-all --strict --ansi",
41 | "test": "vendor/bin/phpunit",
42 | "test-lowest": [
43 | "composer update --prefer-lowest --prefer-dist --no-interaction --ansi",
44 | "@test"
45 | ],
46 | "test-stable": [
47 | "composer update --prefer-stable --prefer-dist --no-interaction --ansi",
48 | "@test"
49 | ],
50 | "check": [
51 | "@composer-validate",
52 | "@test"
53 | ]
54 | },
55 | "config": {
56 | "sort-packages": true
57 | },
58 | "extra": {
59 | "laravel": {
60 | "providers": [
61 | "SebastiaanLuca\\ConditionalProviders\\ConditionalProvidersServiceProvider"
62 | ]
63 | }
64 | },
65 | "minimum-stability": "dev",
66 | "prefer-stable": true
67 | }
68 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Laravel Conditional Providers
2 |
3 | [![Latest stable release][version-badge]][link-packagist]
4 | [![Software license][license-badge]](LICENSE.md)
5 | [![Build status][travis-badge]][link-travis]
6 | [![Total downloads][downloads-badge]][link-packagist]
7 | [![Total stars][stars-badge]][link-github]
8 |
9 | [![Read my blog][blog-link-badge]][link-blog]
10 | [![View my other packages and projects][packages-link-badge]][link-packages]
11 | [![Follow @sebastiaanluca on Twitter][twitter-profile-badge]][link-twitter]
12 | [![Share this package on Twitter][twitter-share-badge]][link-twitter-share]
13 |
14 | **Load Laravel service providers and facades based on the current environment.**
15 |
16 | Specify the service providers and facades to load per environment directly in your configuration file. No more need to add lengthy blocks of conditionals to your `AppServiceProvider`, do it all in the app configuration file like you would with any service provider and facade!
17 |
18 | Inspired by [Matt Staufer](https://mattstauffer.co/blog/conditionally-loading-service-providers-in-laravel-5), [Sven Luijten](https://github.com/svenluijten/env-providers), and others.
19 |
20 | ## Table of contents
21 |
22 | - [What does it solve?](#what-does-it-solve)
23 | - [Requirements](#requirements)
24 | - [How to install](#how-to-install)
25 | - [How to use](#how-to-use)
26 | - [Conditional providers](#conditional-providers)
27 | - [Conditional aliases](#conditional-aliases)
28 | - [License](#license)
29 | - [Change log](#change-log)
30 | - [Testing](#testing)
31 | - [Contributing](#contributing)
32 | - [Security](#security)
33 | - [Credits](#credits)
34 | - [About](#about)
35 |
36 | ## What does it solve?
37 |
38 | Say you're using a package like [barryvdh/laravel-ide-helper](https://github.com/barryvdh/laravel-ide-helper) in your project. If you've followed its installation instructions and require it only in development environments (like you should), you'd do the following:
39 |
40 | ```bash
41 | composer require barryvdh/laravel-ide-helper --dev
42 | ```
43 |
44 | And then add the service provider to your app's config providers array:
45 |
46 | ```php
47 | 'providers' => [
48 |
49 | Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
50 |
51 | ]
52 | ```
53 |
54 | Now when you run `composer install --no-dev` in your production environment to install all but development packages, this will throw an exception. Laravel will try to load the registered service provider class which it can't find, because the package is not installed.
55 |
56 | ```
57 | [Symfony\Component\Debug\Exception\FatalThrowableError]
58 | Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' not found
59 | ```
60 |
61 | Of course you can —per the instructions— conditionally load the provider manually in the register method of the `app/Providers/AppServiceProvider.php` file:
62 |
63 | ```php
64 | public function register()
65 | {
66 | if ($this->app->environment() !== 'production') {
67 | $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
68 | }
69 | }
70 | ```
71 |
72 | But you'd have to do this for each development package and each environment you don't want it loaded in, which is hardly maintainable and pollutes your application-specific code.
73 |
74 | Enter Laravel conditional providers [to easily do all of this](#how-to-use) in your main application config file!
75 |
76 | ## Requirements
77 |
78 | - PHP 7.3 or higher
79 | - Laravel 6.0 or higher
80 |
81 | ## How to install
82 |
83 | ```bash
84 | composer require sebastiaanluca/laravel-conditional-providers
85 | ```
86 |
87 | ## How to use
88 |
89 | ### Conditional providers
90 |
91 | Disable auto-discovery of the package's service provider by adding it to your composer.json's relevant section:
92 |
93 | ```json
94 | "extra": {
95 | "laravel": {
96 | "dont-discover": [
97 | "barryvdh/laravel-debugbar"
98 | ]
99 | }
100 | },
101 | ```
102 |
103 | Once you're set up, simply __add a providers array per environment__ to your `config/app.php` file:
104 |
105 | ```php
106 | 'providers' => [
107 |
108 | // Contains your global providers which will load in any environment
109 |
110 | ],
111 |
112 | 'local_providers' => [
113 |
114 | // Contains your 'local' environment providers
115 |
116 | // Mostly used to load debug helpers, optimization tools, et cetera
117 |
118 | Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
119 | Barryvdh\Debugbar\ServiceProvider::class,
120 |
121 | ],
122 |
123 | 'production_providers' => [
124 |
125 | // Contains your 'production' environment providers
126 |
127 | // Great for when you only want to get analytics or
128 | // bug reports in production and disable the provider
129 | // entirely when developing.
130 |
131 | ],
132 | ```
133 |
134 | Each providers key is __optional__ and can be empty —so you could just use the `local_providers` array or none at all.
135 |
136 | The example above will do the following in a `local` environment:
137 |
138 | - Load every provider from `providers`
139 | - Load every provider from `local_providers`
140 | - Ignore everything in `production_providers`
141 |
142 | All done! Now your app service provider is clean and you get a better view on what's loaded and when, with the added benefit of enabling or disabling packages based on environment.
143 |
144 | ### Conditional aliases
145 |
146 | In addition to conditionally loading providers, this workflow is also available for aliases/facades. __Add a facades/aliases array per environment__ to your `config/app.php` file like so:
147 |
148 | ```php
149 | 'aliases' => [
150 |
151 | // Contains your global aliases which will load in any environment
152 |
153 | ],
154 |
155 | 'local_aliases' => [
156 |
157 | // Contains your 'local' environment aliases/facades
158 |
159 | 'Debugbar' => Barryvdh\Debugbar\Facade::class,
160 |
161 | ],
162 |
163 | 'production_aliases' => [
164 |
165 | // Contains your 'production' environment aliases/facades
166 |
167 | ],
168 | ```
169 |
170 | That's it! This will load the `Debugbar` facade only in the local environment.
171 |
172 | ## License
173 |
174 | This package operates under the MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.
175 |
176 | ## Change log
177 |
178 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
179 |
180 | ## Testing
181 |
182 | ``` bash
183 | composer install
184 | composer test
185 | ```
186 |
187 | ## Contributing
188 |
189 | Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CODE_OF_CONDUCT.md) for details.
190 |
191 | ## Security
192 |
193 | If you discover any security related issues, please email [hello@sebastiaanluca.com][link-author-email] instead of using the issue tracker.
194 |
195 | ## Credits
196 |
197 | - [Sebastiaan Luca][link-github-profile]
198 | - [All Contributors][link-contributors]
199 |
200 | ## About
201 |
202 | My name is Sebastiaan and I'm a freelance Laravel developer specializing in building custom Laravel applications. Check out my [portfolio][link-portfolio] for more information, [my blog][link-blog] for the latest tips and tricks, and my other [packages][link-packages] to kick-start your next project.
203 |
204 | Have a project that could use some guidance? Send me an e-mail at [hello@sebastiaanluca.com][link-author-email]!
205 |
206 | [version-badge]: https://img.shields.io/packagist/v/sebastiaanluca/laravel-conditional-providers.svg?label=stable
207 | [license-badge]: https://img.shields.io/badge/license-MIT-informational.svg
208 | [travis-badge]: https://img.shields.io/travis/sebastiaanluca/laravel-conditional-providers/master.svg
209 | [downloads-badge]: https://img.shields.io/packagist/dt/sebastiaanluca/laravel-conditional-providers.svg?color=brightgreen
210 | [stars-badge]: https://img.shields.io/github/stars/sebastiaanluca/laravel-conditional-providers.svg?color=brightgreen
211 |
212 | [blog-link-badge]: https://img.shields.io/badge/link-blog-lightgrey.svg
213 | [packages-link-badge]: https://img.shields.io/badge/link-other_packages-lightgrey.svg
214 | [twitter-profile-badge]: https://img.shields.io/twitter/follow/sebastiaanluca.svg?style=social
215 | [twitter-share-badge]: https://img.shields.io/twitter/url/http/shields.io.svg?style=social
216 |
217 | [link-github]: https://github.com/sebastiaanluca/laravel-conditional-providers
218 | [link-packagist]: https://packagist.org/packages/sebastiaanluca/laravel-conditional-providers
219 | [link-travis]: https://travis-ci.org/sebastiaanluca/laravel-conditional-providers
220 | [link-twitter-share]: https://twitter.com/intent/tweet?text=Check%20out%20this%20extensive%20set%20of%20generic%20PHP%20helper%20functions%20and%20classes!%20Via%20@sebastiaanluca%20https://github.com/sebastiaanluca/laravel-conditional-providers
221 | [link-contributors]: ../../contributors
222 |
223 | [link-portfolio]: https://www.sebastiaanluca.com
224 | [link-blog]: https://blog.sebastiaanluca.com
225 | [link-packages]: https://packagist.org/packages/sebastiaanluca
226 | [link-twitter]: https://twitter.com/sebastiaanluca
227 | [link-github-profile]: https://github.com/sebastiaanluca
228 | [link-author-email]: mailto:hello@sebastiaanluca.com
229 |
--------------------------------------------------------------------------------