Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Laravel 11 support #57

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
));
}
}
}
Loading