diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6029805..da813ad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.1, 8.2] + php: [8.2] steps: - name: Checkout code diff --git a/composer.json b/composer.json index bf86259..f55976f 100644 --- a/composer.json +++ b/composer.json @@ -13,26 +13,26 @@ } ], "require": { - "php": "^8.1", + "php": "^8.2", "guzzlehttp/guzzle": "^7.5", - "illuminate/database": "^10.0", - "illuminate/encryption": "^10.0", - "illuminate/hashing": "^10.0", - "illuminate/http": "^10.0", - "illuminate/queue": "^10.0", - "illuminate/routing": "^10.0", - "illuminate/translation": "^10.0", - "illuminate/validation": "^10.0", - "laravel-zero/framework": "^10.2", - "laravel/sanctum": "^3.3", - "nunomaduro/termwind": "^1.15.1", + "illuminate/database": "^11.0", + "illuminate/encryption": "^11.0", + "illuminate/hashing": "^11.0", + "illuminate/http": "^11.0", + "illuminate/queue": "^11.0", + "illuminate/routing": "^11.0", + "illuminate/translation": "^11.0", + "illuminate/validation": "^11.0", + "illuminate/view": "^11.0", + "laravel-zero/framework": "^11.0", + "laravel/sanctum": "^4.0", "react/async": "^4.2", "react/http": "^1.9", "symfony/psr-http-message-bridge": "^6.4", "team-reflex/discord-php": "^7.3" }, "require-dev": { - "laravel/pint": "^1.13" + "laravel/pint": "^1.15" }, "autoload": { "psr-4": { diff --git a/src/LaracordServiceProvider.php b/src/LaracordServiceProvider.php index dbb6ad1..9532e8a 100644 --- a/src/LaracordServiceProvider.php +++ b/src/LaracordServiceProvider.php @@ -2,9 +2,11 @@ namespace Laracord; +use Illuminate\Contracts\Foundation\CachesConfiguration; use Illuminate\Contracts\Http\Kernel as KernelContract; use Illuminate\Support\ServiceProvider; use Laracord\Http\Kernel; +use LaravelZero\Framework\Components\Database\Provider as DatabaseProvider; class LaracordServiceProvider extends ServiceProvider { @@ -31,29 +33,15 @@ class LaracordServiceProvider extends ServiceProvider */ public function register() { - $this->mergeConfigFrom(__DIR__.'/../config/app.php', 'app'); - $this->mergeConfigFrom(__DIR__.'/../config/cache.php', 'cache'); - $this->mergeConfigFrom(__DIR__.'/../config/commands.php', 'commands'); - $this->mergeConfigFrom(__DIR__.'/../config/database.php', 'database'); - $this->mergeConfigFrom(__DIR__.'/../config/discord.php', 'discord'); - $this->mergeConfigFrom(__DIR__.'/../config/filesystems.php', 'filesystems'); - $this->mergeConfigFrom(__DIR__.'/../config/view.php', 'view'); - - $paths = [ - 'cache' => $this->app['config']->get('cache.stores.file.path'), - 'view' => $this->app['config']->get('view.compiled'), - ]; - - foreach ($paths as $path) { - if (! is_dir($path)) { - mkdir($path, 0755, true); - } - } + $this->mergeConfigs(); + $this->createDirectories(); foreach ($this->providers as $provider) { $this->app->register($provider); } + $this->registerDatabase(); + $this->app->singleton(KernelContract::class, Kernel::class); } @@ -78,4 +66,63 @@ public function boot() Console\Commands\TokenMakeCommand::class, ]); } + + /** + * Merge the application configuration. + */ + protected function mergeConfigs(): void + { + $this->mergeConfigFrom(__DIR__.'/../config/app.php', 'app'); + $this->mergeConfigFrom(__DIR__.'/../config/cache.php', 'cache'); + $this->mergeConfigFrom(__DIR__.'/../config/commands.php', 'commands'); + $this->mergeConfigFrom(__DIR__.'/../config/database.php', 'database'); + $this->mergeConfigFrom(__DIR__.'/../config/discord.php', 'discord'); + $this->mergeConfigFrom(__DIR__.'/../config/filesystems.php', 'filesystems'); + $this->mergeConfigFrom(__DIR__.'/../config/view.php', 'view'); + } + + /** + * Create the application directories. + */ + protected function createDirectories(): void + { + $paths = [ + 'cache' => $this->app['config']->get('cache.stores.file.path'), + 'view' => $this->app['config']->get('view.compiled'), + ]; + + foreach ($paths as $path) { + if (! is_dir($path)) { + mkdir($path, 0755, true); + } + } + } + + /** + * Register the Database service provider if needed. + */ + protected function registerDatabase(): void + { + if (! (new DatabaseProvider($this->app))->isAvailable()) { + $this->app->booting(fn () => $this->app->register(DatabaseProvider::class)); + } + } + + /** + * Merge the given configuration with the existing configuration. + * + * @param string $path + * @param string $key + * @return void + */ + protected function mergeConfigFrom($path, $key) + { + if (! ($this->app instanceof CachesConfiguration && $this->app->configurationIsCached())) { + $config = $this->app->make('config'); + + $config->set($key, array_merge( + $config->get($key, []), require $path + )); + } + } }