-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from jorgemudry/feature_new_make_exception_com…
…mand Add a new make:exception command
- Loading branch information
Showing
6 changed files
with
170 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Flipbox\LumenGenerator\Console; | ||
|
||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
class ExceptionMakeCommand extends GeneratorCommand | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'make:exception'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new custom exception class'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Exception'; | ||
|
||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
if ($this->option('render')) { | ||
return $this->option('report') | ||
? __DIR__.'/stubs/exception-render-report.stub' | ||
: __DIR__.'/stubs/exception-render.stub'; | ||
} | ||
|
||
return $this->option('report') | ||
? __DIR__.'/stubs/exception-report.stub' | ||
: __DIR__.'/stubs/exception.stub'; | ||
} | ||
|
||
/** | ||
* 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) | ||
{ | ||
return $rootNamespace.'\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'], | ||
]; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/LumenGenerator/Console/stubs/exception-render-report.stub
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,29 @@ | ||
<?php | ||
|
||
namespace DummyNamespace; | ||
|
||
use Exception; | ||
|
||
class DummyClass extends Exception | ||
{ | ||
/** | ||
* Report the exception. | ||
* | ||
* @return void | ||
*/ | ||
public function report() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Render the exception as an HTTP response. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function render($request) | ||
{ | ||
// | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace DummyNamespace; | ||
|
||
use Exception; | ||
|
||
class DummyClass extends Exception | ||
{ | ||
/** | ||
* Render the exception as an HTTP response. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function render($request) | ||
{ | ||
// | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace DummyNamespace; | ||
|
||
use Exception; | ||
|
||
class DummyClass extends Exception | ||
{ | ||
/** | ||
* Report the exception. | ||
* | ||
* @return void | ||
*/ | ||
public function report() | ||
{ | ||
// | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace DummyNamespace; | ||
|
||
use Exception; | ||
|
||
class DummyClass extends Exception | ||
{ | ||
// | ||
} |
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