2016-12-08 16:09:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
|
|
|
|
use Nwidart\Modules\Commands\GeneratorCommand;
|
|
|
|
use Nwidart\Modules\Support\Stub;
|
|
|
|
use Nwidart\Modules\Traits\ModuleCommandTrait;
|
|
|
|
|
2016-12-08 19:00:13 +01:00
|
|
|
class MakeClass extends GeneratorCommand
|
2016-12-08 16:09:45 +01:00
|
|
|
{
|
|
|
|
use ModuleCommandTrait;
|
|
|
|
|
|
|
|
protected $argumentName = 'name';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-12-08 19:00:13 +01:00
|
|
|
protected $name = 'ninja:make-class';
|
2016-12-08 16:09:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-12-08 19:00:13 +01:00
|
|
|
protected $description = 'Create class stub';
|
2016-12-08 16:09:45 +01:00
|
|
|
|
|
|
|
protected function getArguments()
|
|
|
|
{
|
|
|
|
return [
|
2016-12-08 21:39:15 +01:00
|
|
|
['name', InputArgument::REQUIRED, 'The name of the module.'],
|
2016-12-08 19:00:13 +01:00
|
|
|
['module', InputArgument::REQUIRED, 'The name of module will be used.'],
|
|
|
|
['class', InputArgument::REQUIRED, 'The name of the class.'],
|
2016-12-08 21:39:15 +01:00
|
|
|
['prefix', InputArgument::OPTIONAL, 'The prefix of the class.'],
|
2016-12-08 16:09:45 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTemplateContents()
|
|
|
|
{
|
|
|
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
2016-12-08 21:39:15 +01:00
|
|
|
$path = str_replace('/', '\\', config('modules.paths.generator.' . $this->argument('class')));
|
2016-12-08 16:09:45 +01:00
|
|
|
|
2016-12-08 21:39:15 +01:00
|
|
|
return (new Stub('/' . $this->argument('prefix') . $this->argument('class') . '.stub', [
|
|
|
|
'NAMESPACE' => $this->getClassNamespace($module) . "\\" . $path,
|
2016-12-08 16:09:45 +01:00
|
|
|
'LOWER_NAME' => $module->getLowerName(),
|
|
|
|
'CLASS' => $this->getClass(),
|
|
|
|
'STUDLY_NAME' => Str::studly($module->getLowerName()),
|
|
|
|
]))->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDestinationFilePath()
|
|
|
|
{
|
|
|
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
2016-12-08 19:00:13 +01:00
|
|
|
$seederPath = $this->laravel['modules']->config('paths.generator.' . $this->argument('class'));
|
2016-12-08 16:09:45 +01:00
|
|
|
|
|
|
|
return $path . $seederPath . '/' . $this->getFileName() . '.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getFileName()
|
|
|
|
{
|
2016-12-08 21:39:15 +01:00
|
|
|
return studly_case($this->argument('prefix')) . studly_case($this->argument('name')) . Str::studly($this->argument('class'));
|
2016-12-08 16:09:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|