Last active
November 4, 2021 16:46
-
-
Save kmuenkel/c9607e959b049260df188e34b8bfc804 to your computer and use it in GitHub Desktop.
Register Service Providers for 'require-dev' packages only if 'composer install' was run without the '--no-dev' argument.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
class AppServiceProvider | |
{ | |
public function register() | |
{ | |
$this->registerDev() | |
} | |
protected function registerDev() | |
{ | |
$installed = []; | |
if (File::exists($path = base_path('vendor').'/composer/installed.json')) { | |
$installed = json_decode(File::get($path), true); | |
$installed = array_column($installed['packages'] ?? $installed, 'name'); | |
} | |
$configuration = json_decode(File::get(base_path('composer.json')), true); | |
$configuration = array_keys($configuration['require-dev'] ?? []); | |
if (array_intersect($installed, $configuration)) { | |
foreach (config('app.dev_providers', []) as $providerName) { | |
$this->app->register($providerName); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment