Skip to content

Commit

Permalink
Merge pull request #78 from jorgemudry/feature_new_make_exception_com…
Browse files Browse the repository at this point in the history
…mand

Add a new make:exception command
  • Loading branch information
joelhy authored May 4, 2020
2 parents 47c6564 + 4820140 commit ea72f49
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/LumenGenerator/Console/ExceptionMakeCommand.php
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 src/LumenGenerator/Console/stubs/exception-render-report.stub
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)
{
//
}
}
19 changes: 19 additions & 0 deletions src/LumenGenerator/Console/stubs/exception-render.stub
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)
{
//
}
}
18 changes: 18 additions & 0 deletions src/LumenGenerator/Console/stubs/exception-report.stub
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()
{
//
}
}
10 changes: 10 additions & 0 deletions src/LumenGenerator/Console/stubs/exception.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace DummyNamespace;

use Exception;

class DummyClass extends Exception
{
//
}
11 changes: 11 additions & 0 deletions src/LumenGenerator/LumenGeneratorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class LumenGeneratorServiceProvider extends ServiceProvider
'ConsoleMake' => 'command.console.make',
'ControllerMake' => 'command.controller.make',
'EventMake' => 'command.event.make',
'ExceptionMake' => 'command.exception.make',
'JobMake' => 'command.job.make',
'ListenerMake' => 'command.listener.make',
'MailMake' => 'command.mail.make',
Expand Down Expand Up @@ -148,6 +149,16 @@ protected function registerEventMakeCommand()
});
}

/**
* Register the command.
*/
protected function registerExceptionMakeCommand()
{
$this->app->singleton('command.exception.make', function ($app) {
return new Console\ExceptionMakeCommand($app['files']);
});
}

/**
* Register the command.
*/
Expand Down

0 comments on commit ea72f49

Please sign in to comment.