Created
December 13, 2018 16:38
-
-
Save chrisblackwell/ba9fc17fc5f455bae74642461f3b6777 to your computer and use it in GitHub Desktop.
Laravel make command
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; | |
use Illuminate\Support\Str; | |
use Illuminate\Console\GeneratorCommand; | |
use Symfony\Component\Console\Input\InputOption; | |
class SomethingMakeCommand extends GeneratorCommand | |
{ | |
protected $name = 'make:something'; | |
protected $description = 'Create a new Something class'; | |
protected $type = 'Something'; | |
public function handle() | |
{ | |
if (parent::handle() === false) { | |
if (! $this->option('force')) { | |
return; | |
} | |
} | |
} | |
protected function getStub() | |
{ | |
return __DIR__.'/../../stubs/DummySomething.stub'; | |
} | |
protected function getDefaultNamespace($rootNamespace) | |
{ | |
if ($this->isCustomNamespace()) { | |
return $rootNamespace; | |
} | |
return $rootNamespace.'\Something'; | |
} | |
protected function getOptions(): array | |
{ | |
return [ | |
['force', null, InputOption::VALUE_NONE, 'Create the class even if the view-model already exists'], | |
]; | |
} | |
protected function isCustomNamespace(): bool | |
{ | |
return Str::contains($this->argument('name'), '/'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment