Skip to content

Commit 2668914

Browse files
authored
Merge pull request #10 from sevannerse/master
added exception support
2 parents 5205b70 + 5b25930 commit 2668914

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace Akaunting\Module\Commands;
4+
5+
use Akaunting\Module\Support\Config\GenerateConfigReader;
6+
use Akaunting\Module\Support\Stub;
7+
use Akaunting\Module\Traits\ModuleCommandTrait;
8+
use Illuminate\Support\Str;
9+
use Symfony\Component\Console\Input\InputArgument;
10+
11+
class ExceptionMakeCommand extends GeneratorCommand
12+
{
13+
use ModuleCommandTrait;
14+
15+
protected $argumentName = 'name';
16+
17+
/**
18+
* The console command name.
19+
*
20+
* @var string
21+
*/
22+
protected $name = 'module:make-exception';
23+
24+
/**
25+
* The console command description.
26+
*
27+
* @var string
28+
*/
29+
protected $description = 'Create a new custom exception class for the specified module';
30+
31+
public function getTemplateContents()
32+
{
33+
$module = $this->getModule();
34+
35+
return (new Stub('/exception.stub', [
36+
'NAMESPACE' => $this->getClassNamespace($module),
37+
'CLASS' => $this->getClass(),
38+
]))->render();
39+
}
40+
41+
public function getDestinationFilePath()
42+
{
43+
$path = $this->laravel['module']->getModulePath($this->getModuleAlias());
44+
45+
$exceptionPath = GenerateConfigReader::read('exception');
46+
47+
return $path . $exceptionPath->getPath() . '/' . $this->getFileName() . '.php';
48+
}
49+
50+
/**
51+
* @return string
52+
*/
53+
protected function getFileName()
54+
{
55+
return Str::studly($this->argument('name'));
56+
}
57+
58+
public function getDefaultNamespace(): string
59+
{
60+
return $this->laravel['module']->config('paths.generator.exception.path', 'Exceptions');
61+
}
62+
63+
/**
64+
* Get the console command arguments.
65+
*
66+
* @return array
67+
*/
68+
protected function getArguments()
69+
{
70+
return [
71+
['name', InputArgument::REQUIRED, 'The name of the exception.'],
72+
['alias', InputArgument::OPTIONAL, 'The alias of module will be used.'],
73+
];
74+
}
75+
}

src/Commands/stubs/exception.stub

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace $NAMESPACE$;
4+
5+
use Exception;
6+
7+
class $CLASS$ implements Exception
8+
{
9+
/**
10+
* Report the exception.
11+
*
12+
* @return bool|null
13+
*/
14+
public function report()
15+
{
16+
//
17+
}
18+
19+
/**
20+
* Render the exception as an HTTP response.
21+
*
22+
* @param \Illuminate\Http\Request $request
23+
* @return \Illuminate\Http\Response
24+
*/
25+
public function render($request)
26+
{
27+
//
28+
}
29+
}

src/Config/module.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
'component' => ['path' => 'View/Components', 'generate' => false],
126126
'cast' => ['path' => 'Casts', 'generate' => false],
127127
'observer' => ['path' => 'Observers', 'generate' => false],
128+
'exception' => ['path' => 'Exceptions', 'generate' => false],
128129
],
129130
],
130131

src/Providers/Console.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Console extends ServiceProvider
2222
Commands\DumpCommand::class,
2323
Commands\EnableCommand::class,
2424
Commands\EventMakeCommand::class,
25+
Commands\ExceptionMakeCommand::class,
2526
Commands\JobMakeCommand::class,
2627
Commands\ListenerMakeCommand::class,
2728
Commands\MailMakeCommand::class,

0 commit comments

Comments
 (0)