From 2ae4333c779d1910e1b65325028908c2b56e0335 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 28 Sep 2023 09:02:52 +0800 Subject: [PATCH] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 7 +- src/Commands/GeneratorCommand.php | 29 +---- src/LaravelServiceProvider.php | 29 ----- src/PresetManager.php | 44 ------- src/Presets/Laravel.php | 178 ---------------------------- src/Presets/Preset.php | 176 --------------------------- testbench.yaml | 2 - tests/Presets/LaravelPresetTest.php | 53 --------- 8 files changed, 2 insertions(+), 516 deletions(-) delete mode 100644 src/LaravelServiceProvider.php delete mode 100644 src/PresetManager.php delete mode 100644 src/Presets/Laravel.php delete mode 100644 src/Presets/Preset.php delete mode 100644 tests/Presets/LaravelPresetTest.php diff --git a/composer.json b/composer.json index 97cb661..1dec5e2 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ }, "require-dev": { "fakerphp/faker": "^1.21", - "laravel/framework": "^10.17", + "laravel/framework": "dev-generator-presets as 10.x-dev", "laravel/pint": "^1.6", "mockery/mockery": "^1.5.1", "orchestra/testbench-core": "^8.11", @@ -57,11 +57,6 @@ "extra": { "branch-alias": { "dev-master": "9.0-dev" - }, - "laravel": { - "providers": [ - "Orchestra\\Canvas\\Core\\LaravelServiceProvider" - ] } }, "scripts": { diff --git a/src/Commands/GeneratorCommand.php b/src/Commands/GeneratorCommand.php index b3e1d8c..5694b4b 100644 --- a/src/Commands/GeneratorCommand.php +++ b/src/Commands/GeneratorCommand.php @@ -4,42 +4,15 @@ use Illuminate\Filesystem\Filesystem; use Orchestra\Canvas\Core\Concerns; -use Orchestra\Canvas\Core\Contracts\GeneratesCode; /** * @property string|null $name * @property string|null $description */ -abstract class GeneratorCommand extends \Illuminate\Console\GeneratorCommand implements GeneratesCode +abstract class GeneratorCommand extends \Illuminate\Console\GeneratorCommand { - use Concerns\CodeGenerator; - use Concerns\TestGenerator; use Concerns\UsesGeneratorOverrides; - /** - * Create a new controller creator command instance. - * - * @return void - */ - public function __construct(Filesystem $files) - { - parent::__construct($files); - - $this->addGeneratorPresetOptions(); - } - - /** - * Execute the console command. - * - * @return bool|null - * - * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException - */ - public function handle() - { - return $this->generateCode() ? self::SUCCESS : self::FAILURE; - } - /** * Get the destination class path. * diff --git a/src/LaravelServiceProvider.php b/src/LaravelServiceProvider.php deleted file mode 100644 index 47b5e6b..0000000 --- a/src/LaravelServiceProvider.php +++ /dev/null @@ -1,29 +0,0 @@ -app->singleton(PresetManager::class, fn ($app) => new PresetManager($app)); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides(): array - { - return [ - PresetManager::class, - ]; - } -} diff --git a/src/PresetManager.php b/src/PresetManager.php deleted file mode 100644 index a407dc1..0000000 --- a/src/PresetManager.php +++ /dev/null @@ -1,44 +0,0 @@ -container); - } - - /** - * Set the default driver name. - * - * @param string $name - * @return void - */ - public function setDefaultDriver($name) - { - $this->defaultPreset = $name; - } - - /** - * Get the default driver name. - * - * @return string - */ - public function getDefaultDriver() - { - return $this->defaultPreset; - } -} diff --git a/src/Presets/Laravel.php b/src/Presets/Laravel.php deleted file mode 100644 index 73d5115..0000000 --- a/src/Presets/Laravel.php +++ /dev/null @@ -1,178 +0,0 @@ -app->basePath(); - } - - /** - * Get the path to the source directory. - * - * @return string - */ - public function sourcePath() - { - return $this->app->basePath('app'); - } - - /** - * Get the path to the testing directory. - * - * @return string - */ - public function testingPath() - { - return $this->app->basePath('tests'); - } - - /** - * Get the path to the resource directory. - * - * @return string - */ - public function resourcePath() - { - return $this->app->resourcePath(); - } - - /** - * Get the path to the view directory. - * - * @return string - */ - public function viewPath() - { - return $this->app['config']['view.paths'][0] ?? $this->app->resourcePath('views'); - } - - /** - * Get the path to the factory directory. - * - * @return string - */ - public function factoryPath() - { - return $this->app->databasePath('factories'); - } - - /** - * Get the path to the migration directory. - * - * @return string - */ - public function migrationPath() - { - return $this->app->databasePath('migrations'); - } - - /** - * Get the path to the seeder directory. - */ - public function seederPath(): string - { - if (is_dir($seederPath = $this->app->databasePath('seeds'))) { - return $seederPath; - } - - return $this->app->databasePath('seeders'); - } - - /** - * Preset namespace. - * - * @return string - */ - public function rootNamespace() - { - return $this->app->getNamespace(); - } - - /** - * Command namespace. - * - * @return string - */ - public function commandNamespace() - { - return "{$this->rootNamespace()}Console\Commands\\"; - } - - /** - * Model namespace. - * - * @return string - */ - public function modelNamespace() - { - return is_dir("{$this->sourcePath()}/Models") ? "{$this->rootNamespace()}Models\\" : $this->rootNamespace(); - } - - /** - * Provider namespace. - * - * @return string - */ - public function providerNamespace() - { - return "{$this->rootNamespace()}Providers\\"; - } - - /** - * Testing namespace. - * - * @return string - */ - public function testingNamespace() - { - return 'Tests\\'; - } - - /** - * Database factory namespace. - * - * @return string - */ - public function factoryNamespace() - { - return 'Database\Factories\\'; - } - - /** - * Database seeder namespace. - * - * @return string - */ - public function seederNamespace() - { - return 'Database\Seeders\\'; - } - - /** - * Preset has custom stub path. - * - * @return bool - */ - public function hasCustomStubPath() - { - return true; - } -} diff --git a/src/Presets/Preset.php b/src/Presets/Preset.php deleted file mode 100644 index 8b6de9e..0000000 --- a/src/Presets/Preset.php +++ /dev/null @@ -1,176 +0,0 @@ -app = $app; - } - - /** - * Check if preset name equal to $name. - * - * @param string $name - * @return bool - */ - public function is($name) - { - return $this->name() === $name; - } - - /** - * Get the model for the default guard's user provider. - * - * @param string|null $guard - * @return string|null - */ - public function userProviderModel($guard = null) - { - /** @var \Illuminate\Contracts\Config\Repository $config */ - $config = $this->app->make('config'); - - $guard = $guard ?: $config->get('auth.defaults.guard'); - - if (\is_null($provider = $config->get('auth.guards.'.$guard.'.provider'))) { - throw new LogicException('The ['.$guard.'] guard is not defined in your "auth" configuration file.'); - } - - return $config->get("auth.providers.{$provider}.model"); - } - - /** - * Preset name. - * - * @return string - */ - abstract public function name(); - - /** - * Get the path to the base working directory. - * - * @return string - */ - abstract public function basePath(); - - /** - * Get the path to the source directory. - * - * @return string - */ - abstract public function sourcePath(); - - /** - * Get the path to the testing directory. - * - * @return string - */ - abstract public function testingPath(); - - /** - * Get the path to the resource directory. - * - * @return string - */ - abstract public function resourcePath(); - - /** - * Get the path to the view directory. - * - * @return string - */ - abstract public function viewPath(); - - /** - * Get the path to the factory directory. - * - * @return string - */ - abstract public function factoryPath(); - - /** - * Get the path to the migration directory. - * - * @return string - */ - abstract public function migrationPath(); - - /** - * Get the path to the seeder directory. - * - * @return string - */ - abstract public function seederPath(); - - /** - * Preset namespace. - * - * @return string - */ - abstract public function rootNamespace(); - - /** - * Command namespace. - * - * @return string - */ - abstract public function commandNamespace(); - - /** - * Model namespace. - * - * @return string - */ - abstract public function modelNamespace(); - - /** - * Provider namespace. - * - * @return string - */ - abstract public function providerNamespace(); - - /** - * Testing namespace. - * - * @return string - */ - abstract public function testingNamespace(); - - /** - * Database factory namespace. - * - * @return string - */ - abstract public function factoryNamespace(); - - /** - * Database seeder namespace. - * - * @return string - */ - abstract public function seederNamespace(); - - /** - * Preset has custom stub path. - * - * @return bool - */ - abstract public function hasCustomStubPath(); -} diff --git a/testbench.yaml b/testbench.yaml index ab4b7fc..e69de29 100644 --- a/testbench.yaml +++ b/testbench.yaml @@ -1,2 +0,0 @@ -providers: - - Orchestra\Canvas\Core\LaravelServiceProvider diff --git a/tests/Presets/LaravelPresetTest.php b/tests/Presets/LaravelPresetTest.php deleted file mode 100644 index 97689a4..0000000 --- a/tests/Presets/LaravelPresetTest.php +++ /dev/null @@ -1,53 +0,0 @@ -app[PresetManager::class]->driver('laravel'); - - $this->assertInstanceOf(Laravel::class, $preset); - $this->assertSame('laravel', $preset->name()); - $this->assertTrue($preset->is('laravel')); - - $this->assertSame($this->app->basePath(), $preset->basePath()); - $this->assertSame($this->app->basePath('app'), $preset->sourcePath()); - $this->assertSame($this->app->basePath('tests'), $preset->testingPath()); - $this->assertSame($this->app->resourcePath(), $preset->resourcePath()); - $this->assertSame($this->app->resourcePath('views'), $preset->viewPath()); - $this->assertSame($this->app->databasePath('factories'), $preset->factoryPath()); - $this->assertSame($this->app->databasePath('migrations'), $preset->migrationPath()); - $this->assertSame($this->app->databasePath('seeders'), $preset->seederPath()); - - $this->assertSame($this->app->getNamespace(), $preset->rootNamespace()); - $this->assertSame($this->app->getNamespace().'Console\Commands\\', $preset->commandNamespace()); - $this->assertSame($this->app->getNamespace().'Models\\', $preset->modelNamespace()); - $this->assertSame($this->app->getNamespace().'Providers\\', $preset->providerNamespace()); - $this->assertSame('Database\Factories\\', $preset->factoryNamespace()); - $this->assertSame('Database\Seeders\\', $preset->seederNamespace()); - $this->assertSame('Tests\\', $preset->testingNamespace()); - - $this->assertTrue($preset->hasCustomStubPath()); - $this->assertSame('Illuminate\Foundation\Auth\User', $preset->userProviderModel()); - } - - /** @test */ - public function it_available_as_default_driver() - { - $preset = $this->app[PresetManager::class]->driver(); - - $this->assertInstanceOf(Laravel::class, $preset); - $this->assertSame('laravel', $preset->name()); - $this->assertTrue($preset->is('laravel')); - } -}