-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.5] Add make command for custom exceptions #21483
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/Illuminate/Foundation/Console/ExceptionMakeCommand.php
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 Illuminate\Foundation\Console; | ||
|
||
use Illuminate\Console\GeneratorCommand; | ||
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'; | ||
} else { | ||
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.'], | ||
]; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Illuminate/Foundation/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,30 @@ | ||
<?php | ||
|
||
namespace DummyNamespace; | ||
|
||
use Exception; | ||
|
||
class DummyClass extends Exception | ||
{ | ||
|
||
/** | ||
* Render the exception into an HTTP response. | ||
* | ||
* @param \Illuminate\Http\Request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function render($request) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Report the exception. | ||
* | ||
* @return void | ||
*/ | ||
public function report() | ||
{ | ||
// | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Illuminate/Foundation/Console/stubs/exception-render.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,19 @@ | ||
<?php | ||
|
||
namespace DummyNamespace; | ||
|
||
use Exception; | ||
|
||
class DummyClass extends Exception | ||
{ | ||
|
||
/** | ||
* Render an exception into a response. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
*/ | ||
public function render($request) | ||
{ | ||
// | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Illuminate/Foundation/Console/stubs/exception-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,19 @@ | ||
<?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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can get rid of this
else
, because it'll return early here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right, I was following the code in other MakeCommands. I'll fix it as soon as possible.
Thank you.