diff --git a/app/Commands/AbcBcd.php b/app/Commands/AbcBcd.php deleted file mode 100644 index f8581fc..0000000 --- a/app/Commands/AbcBcd.php +++ /dev/null @@ -1,44 +0,0 @@ -command(static::class)->everyMinute(); - } -} diff --git a/app/Commands/Crud/CrudMigrationCreator.php b/app/Commands/Crud/CrudMigrationCreator.php index 33347c4..ba87dd6 100644 --- a/app/Commands/Crud/CrudMigrationCreator.php +++ b/app/Commands/Crud/CrudMigrationCreator.php @@ -9,6 +9,10 @@ class CrudMigrationCreator extends RealMigrationCreator { use PackageDetail; + public function __construct() + { + } + /** * Get the full path to the migration. * @@ -22,7 +26,7 @@ protected function getPath($name, $path) $path = $this->getComposer()->type === 'library' ? $path . 'src/' : $path; $path = $path . 'database/migrations'; - if (! $this->files->isDirectory($path)) { + if (!$this->files->isDirectory($path)) { $this->files->makeDirectory($path, 0777, true); } diff --git a/app/Commands/Crud/MigrateMakeCommand.php b/app/Commands/Crud/MigrateMakeCommand.php index b7553c8..67df591 100644 --- a/app/Commands/Crud/MigrateMakeCommand.php +++ b/app/Commands/Crud/MigrateMakeCommand.php @@ -5,6 +5,7 @@ use Illuminate\Support\Str; use Illuminate\Support\Composer; use Illuminate\Database\Console\Migrations\BaseCommand; +use Illuminate\Database\Console\Migrations\TableGuesser; class MigrateMakeCommand extends BaseCommand { @@ -17,7 +18,8 @@ class MigrateMakeCommand extends BaseCommand {--create= : The table to be created} {--table= : The table to migrate} {--path= : The location where the migration file should be created} - {--realpath : Indicate any provided migration file paths are pre-resolved absolute paths}'; + {--realpath : Indicate any provided migration file paths are pre-resolved absolute paths} + {--fullpath : Output the full path of the migration}'; /** * The console command description. @@ -43,7 +45,7 @@ class MigrateMakeCommand extends BaseCommand /** * Create a new migration install command instance. * - * @param \Illuminate\Database\Migrations\MigrationCreator $creator + * @param \App\Commands\Crud\MigrationCreator $creator * @param \Illuminate\Support\Composer $composer * @return void */ @@ -74,7 +76,7 @@ public function handle() // If no table was given as an option but a create option is given then we // will use the "create" option as the table name. This allows the devs // to pass a table name into this option as a short-cut for creating. - if (! $table && is_string($create)) { + if (!$table && is_string($create)) { $table = $create; $create = true; @@ -83,7 +85,7 @@ public function handle() // Next, we will attempt to guess the table name if this the migration has // "create" in the name. This will allow us to provide a convenient way // of creating migrations that create new tables for the application. - if (! $table) { + if (!$table) { [$table, $create] = TableGuesser::guess($name); } @@ -122,8 +124,8 @@ protected function writeMigration($name, $table, $create) */ protected function getMigrationPath() { - if (! is_null($targetPath = $this->input->getOption('path'))) { - return ! $this->usingRealPath() + if (!is_null($targetPath = $this->input->getOption('path'))) { + return !$this->usingRealPath() ? $this->laravel->basePath() . '/' . $targetPath : $targetPath; } diff --git a/app/Commands/Foundation/Factories/FactoryMakeCommand.php b/app/Commands/Foundation/Factories/FactoryMakeCommand.php index 5d18a92..e540c20 100644 --- a/app/Commands/Foundation/Factories/FactoryMakeCommand.php +++ b/app/Commands/Foundation/Factories/FactoryMakeCommand.php @@ -2,10 +2,10 @@ namespace App\Commands\Foundation\Factories; +use Illuminate\Support\Str; +use App\Commands\Helpers\PackageDetail; use Illuminate\Console\GeneratorCommand; use Symfony\Component\Console\Input\InputOption; -use App\Commands\Helpers\PackageDetail; -use Illuminate\Support\Str; class FactoryMakeCommand extends GeneratorCommand { @@ -38,6 +38,9 @@ class FactoryMakeCommand extends GeneratorCommand */ protected function getStub() { + if ($this->option('legacy')) { + return __DIR__ . '/stubs/factory_legacy.stub'; + } return __DIR__ . '/stubs/factory.stub'; } @@ -49,13 +52,39 @@ protected function getStub() */ protected function buildClass($name) { - $model = $this->option('model') + $namespaceModel = $this->option('model') ? $this->qualifyClass($this->option('model')) : 'Model'; + if ($this->option('legacy')) { + return str_replace( + 'DummyModel', + $namespaceModel, + parent::buildClass($name) + ); + } + + $model = class_basename($namespaceModel); + + if (Str::startsWith($namespaceModel, 'App\\Models')) { + $namespace = Str::beforeLast('Database\\Factories\\' . Str::after($namespaceModel, 'App\\Models\\'), '\\'); + } else { + $namespace = 'Database\\Factories'; + } + + $replace = [ + '{{ factoryNamespace }}' => $namespace, + 'NamespacedDummyModel' => $namespaceModel, + '{{ namespacedModel }}' => $namespaceModel, + '{{namespacedModel}}' => $namespaceModel, + 'DummyModel' => $model, + '{{ model }}' => $model, + '{{model}}' => $model, + ]; + return str_replace( - 'DummyModel', - $model, + array_keys($replace), + array_values($replace), parent::buildClass($name) ); } @@ -82,6 +111,7 @@ protected function getOptions() { return [ ['model', 'm', InputOption::VALUE_OPTIONAL, 'The name of the model'], + ['legacy', 'l'], ]; } } diff --git a/app/Commands/Foundation/Factories/stubs/factory.stub b/app/Commands/Foundation/Factories/stubs/factory.stub index 9e3f90b..b85cdf4 100644 --- a/app/Commands/Foundation/Factories/stubs/factory.stub +++ b/app/Commands/Foundation/Factories/stubs/factory.stub @@ -1,9 +1,28 @@ define(DummyModel::class, function (Faker $faker) { - return [ - // - ]; -}); +use Illuminate\Database\Eloquent\Factories\Factory; +use {{ namespacedModel }}; + +class {{ model }}Factory extends Factory +{ + /** + * The name of the factory's corresponding model. + * + * @var string + */ + protected $model = {{ model }}::class; + + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/app/Commands/Foundation/Factories/stubs/factory_legacy.stub b/app/Commands/Foundation/Factories/stubs/factory_legacy.stub new file mode 100644 index 0000000..9e3f90b --- /dev/null +++ b/app/Commands/Foundation/Factories/stubs/factory_legacy.stub @@ -0,0 +1,9 @@ +define(DummyModel::class, function (Faker $faker) { + return [ + // + ]; +}); diff --git a/app/Commands/Foundation/Migrations/MigrateMakeCommand.php b/app/Commands/Foundation/Migrations/MigrateMakeCommand.php index bb2e61a..1f9dcd7 100644 --- a/app/Commands/Foundation/Migrations/MigrateMakeCommand.php +++ b/app/Commands/Foundation/Migrations/MigrateMakeCommand.php @@ -4,6 +4,7 @@ use Illuminate\Support\Str; use Illuminate\Support\Composer; +use Illuminate\Database\Migrations\MigrationCreator; use Illuminate\Database\Console\Migrations\BaseCommand; class MigrateMakeCommand extends BaseCommand @@ -17,7 +18,8 @@ class MigrateMakeCommand extends BaseCommand {--create= : The table to be created} {--table= : The table to migrate} {--path= : The location where the migration file should be created} - {--realpath : Indicate any provided migration file paths are pre-resolved absolute paths}'; + {--realpath : Indicate any provided migration file paths are pre-resolved absolute paths} + {--fullpath : Output the full path of the migration}'; /** * The console command description. diff --git a/composer.json b/composer.json index 9496e98..a149eca 100644 --- a/composer.json +++ b/composer.json @@ -21,14 +21,13 @@ } ], "require": { - "php": "^7.2", - "illuminate/database": "^6.0", - "laravel-zero/framework": "^6.0", - "padraic/phar-updater": "^1.0.6" + "php": "^7.3", + "illuminate/database": "^8.0", + "laravel-zero/framework": "^8.0" }, "require-dev": { - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^7.3" + "mockery/mockery": "^1.4.2", + "phpunit/phpunit": "^9.3" }, "autoload": { "psr-4": {