-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to create resources, jobs, exceptions repositories(with…
… default CRUDs) and services, Fixed problem with generating a model (stub not found) Fixed problem with generating migrations when creating models, "routes" has been capitalized, to enforce consistency
- Loading branch information
1 parent
007d0f9
commit 2972d8f
Showing
19 changed files
with
817 additions
and
62 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
namespace PhpSquad\DomainMaker\Console; | ||
|
||
use Illuminate\Console\GeneratorCommand; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Illuminate\Support\Str; | ||
|
||
|
||
|
||
/// Modified version of: | ||
/// https://github.com/laravel/framework/blob/8.x/src/Illuminate/Foundation/Console/ExceptionMakeCommand.php | ||
class DomainExceptionMakeCommand extends GeneratorCommand | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'domain:make:exception'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new custom exception class for a domain'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Exception'; | ||
|
||
/** | ||
* The domain to create the exception in | ||
* | ||
* @var string | ||
*/ | ||
protected $domain; | ||
|
||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
if ($this->option('render')) { | ||
return $this->option('report') | ||
? $this->resolveStubPath('/stubs/exception-render-report.stub') | ||
: $this->resolveStubPath('/stubs/exception-render.stub'); | ||
} | ||
|
||
return $this->option('report') | ||
? $this->resolveStubPath('/stubs/exception-report.stub') | ||
: $this->resolveStubPath('/stubs/exception.stub'); | ||
} | ||
|
||
|
||
/** | ||
* Resolve the fully-qualified path to the stub. | ||
* | ||
* @param string $stub | ||
* @return string | ||
*/ | ||
protected function resolveStubPath($stub) | ||
{ | ||
$localPath = __DIR__ . '/..' . $stub; | ||
$publishedPath = $this->laravel->basePath(trim($stub, '/')); | ||
return file_exists($publishedPath) | ||
? $publishedPath | ||
: $localPath; | ||
} | ||
|
||
/** | ||
* Determine if the class already exists. | ||
* | ||
* @param string $rawName | ||
* @return bool | ||
*/ | ||
protected function alreadyExists($rawName) | ||
{ | ||
return class_exists($this->rootNamespace() . 'Exceptions\\' . $rawName); | ||
} | ||
|
||
/** | ||
* Get the default namespace for the class. | ||
* | ||
* @param string $rootNamespace | ||
* @return string | ||
*/ | ||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
$this->domain = Str::studly($this->argument('domain')); | ||
return $rootNamespace . '\Domains\\' . $this->domain . '\\Exceptions'; | ||
} | ||
|
||
/** | ||
* Get the console command options. | ||
* | ||
* @return array | ||
*/ | ||
protected function getOptions() | ||
{ | ||
return [ | ||
['render', null, InputOption::VALUE_NONE, 'Create the exception with an empty render method'], | ||
|
||
['report', null, InputOption::VALUE_NONE, 'Create the exception with an empty report method'], | ||
]; | ||
} | ||
|
||
protected function getArguments() | ||
{ | ||
return [ | ||
['domain', InputArgument::REQUIRED, 'The domain of the class'], | ||
['name', InputArgument::REQUIRED, 'The name of the class'], | ||
]; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace PhpSquad\DomainMaker\Console; | ||
|
||
use Illuminate\Console\Concerns\CreatesMatchingTest; | ||
use Illuminate\Console\GeneratorCommand; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Illuminate\Support\Str; | ||
|
||
/// Modified version of: | ||
/// https://github.com/laravel/framework/blob/8.x/src/Illuminate/Foundation/Console/JobMakeCommand.php | ||
class DomainJobMakeCommand extends GeneratorCommand | ||
{ | ||
use CreatesMatchingTest; | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'domain:make:job'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new job class'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Job'; | ||
|
||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
return $this->option('sync') | ||
? $this->resolveStubPath('/stubs/job.stub') | ||
: $this->resolveStubPath('/stubs/job.queued.stub'); | ||
} | ||
|
||
/** | ||
* Resolve the fully-qualified path to the stub. | ||
* | ||
* @param string $stub | ||
* @return string | ||
*/ | ||
protected function resolveStubPath($stub) | ||
{ | ||
$localPath = __DIR__ . '/..' . $stub; | ||
$publishedPath = $this->laravel->basePath(trim($stub, '/')); | ||
return file_exists($publishedPath) | ||
? $publishedPath | ||
: $localPath; | ||
} | ||
|
||
|
||
/** | ||
* Get the default namespace for the class. | ||
* | ||
* @param string $rootNamespace | ||
* @return string | ||
*/ | ||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
$this->domain = Str::studly($this->argument('domain')); | ||
return $rootNamespace . '\Domains\\' . $this->domain . '\\Jobs'; | ||
} | ||
|
||
/** | ||
* Get the console command options. | ||
* | ||
* @return array | ||
*/ | ||
protected function getOptions() | ||
{ | ||
return [ | ||
['sync', null, InputOption::VALUE_NONE, 'Indicates that job should be synchronous'], | ||
]; | ||
} | ||
|
||
protected function getArguments() | ||
{ | ||
return [ | ||
['domain', InputArgument::REQUIRED, 'The domain of the class'], | ||
['name', InputArgument::REQUIRED, 'The name of the class'], | ||
]; | ||
} | ||
} |
Oops, something went wrong.