Skip to content

Commit

Permalink
🎉 Laravel 11 support (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed May 9, 2024
2 parents b33ea63 + b803536 commit af0e802
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.1, 8.2]
php: [8.2]

steps:
- name: Checkout code
Expand Down
26 changes: 13 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
83 changes: 65 additions & 18 deletions src/LaracordServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}

Expand All @@ -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
));
}
}
}

0 comments on commit af0e802

Please sign in to comment.