Created
August 19, 2020 10:03
-
-
Save Yazan-Stash/fb95fad0ac15af104cb1157dd7b0d12c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Support\Composer; | |
use Illuminate\Filesystem\Filesystem; | |
use Illuminate\Console\GeneratorCommand; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
class ActionMakeCommand extends GeneratorCommand | |
{ | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'make:action'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Create a new action class'; | |
/** | |
* The type of class being generated. | |
* | |
* @var string | |
*/ | |
protected $type = 'Action'; | |
/** | |
* The Composer instance. | |
* | |
* @var \Illuminate\Support\Composer | |
*/ | |
protected $composer; | |
/** | |
* Create a new command instance. | |
* | |
* @param \Illuminate\Filesystem\Filesystem $files | |
* @param \Illuminate\Support\Composer $composer | |
* @return void | |
*/ | |
public function __construct(Filesystem $files, Composer $composer) | |
{ | |
parent::__construct($files); | |
$this->composer = $composer; | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return void | |
*/ | |
public function handle() | |
{ | |
parent::handle(); | |
$this->composer->dumpAutoloads(); | |
} | |
/** | |
* Get the stub file for the generator. | |
* | |
* @return string | |
*/ | |
protected function getStub() | |
{ | |
return base_path('stubs/action.stub'); | |
} | |
/** | |
* Get the default namespace for the class. | |
* | |
* @param string $rootNamespace | |
* @return string | |
*/ | |
protected function getDefaultNamespace($rootNamespace) | |
{ | |
return $rootNamespace.'\Actions'; | |
} | |
protected function buildClass($name) | |
{ | |
$stub = $this->files->get($this->getStub()); | |
return $this->replaceNamespace($stub, $name)->replaceClass($stub, $name); | |
} | |
protected function getOptions() | |
{ | |
return [ | |
['force', null, InputOption::VALUE_NONE, 'Create the class even if the action already exists'] | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment