added meta:model functionality
This commit is contained in:
parent
6197055901
commit
766e6a6c2c
98
src/Commands/MetaModelCommand.php
Normal file
98
src/Commands/MetaModelCommand.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Glmdev\Meta\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Console\GeneratorCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class MetaModelCommand extends \Illuminate\Console\GeneratorCommand
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'meta:model';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new meta-enabled Eloquent model class';
|
||||
|
||||
/**
|
||||
* The type of class being generated.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'Model';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
if (parent::fire() === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->option('migration')) {
|
||||
$table = Str::plural(Str::snake(class_basename($this->argument('name'))));
|
||||
|
||||
$this->call('meta:migration', [
|
||||
'name' => "create_{$table}_table",
|
||||
'--create' => $table,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->option('controller')) {
|
||||
$controller = Str::studly(class_basename($this->argument('name')));
|
||||
|
||||
$this->call('make:controller', [
|
||||
'name' => "{$controller}Controller",
|
||||
'--resource' => $this->option('resource'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stub file for the generator.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getStub()
|
||||
{
|
||||
return __DIR__.'/../stubs/model.stub';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default namespace for the class.
|
||||
*
|
||||
* @param string $rootNamespace
|
||||
* @return string
|
||||
*/
|
||||
protected function getDefaultNamespace($rootNamespace)
|
||||
{
|
||||
return $rootNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['migration', 'm', InputOption::VALUE_NONE, 'Create a new migration file for the model.'],
|
||||
|
||||
['controller', 'c', InputOption::VALUE_NONE, 'Create a new controller for the model.'],
|
||||
|
||||
['resource', 'r', InputOption::VALUE_NONE, 'Indicates if the generated controller should be a resource controller'],
|
||||
];
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ class MetaServiceProvider extends ServiceProvider
|
||||
*/
|
||||
protected $commands = [
|
||||
'\Glmdev\Meta\Commands\MetaMigrationCommand',
|
||||
'\Glmdev\Meta\Commands\MetaModelCommand',
|
||||
];
|
||||
|
||||
public function boot(){}
|
||||
|
8
src/stubs/model.stub
Normal file
8
src/stubs/model.stub
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace DummyNamespace;
|
||||
|
||||
class DummyClass extends \Glmdev\Meta\Meta
|
||||
{
|
||||
//
|
||||
}
|
Loading…
Reference in New Issue
Block a user