|
1
|
|
|
<?php namespace Serverfireteam\Panel\Commands; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Console\GeneratorCommand; |
|
4
|
|
|
use Illuminate\Support\Str; |
|
5
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
6
|
|
|
|
|
7
|
|
|
class CreateModelObserverCommand extends GeneratorCommand { |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* |
|
11
|
|
|
* @var string contains the command name |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $name = 'panel:createobserver'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* |
|
17
|
|
|
* @var string contains the description of command |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $description = 'Create a new observer model class'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The type of class being generated. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $type = 'Observer'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Get the stub file for the generator. |
|
30
|
|
|
* |
|
31
|
|
|
* @return string Returns the stub file for generating the Observer |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function getStub() |
|
34
|
|
|
{ |
|
35
|
|
|
return base_path().'/vendor/serverfireteam/panel/src/Serverfireteam/Panel/stubs/observer.stub'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get the default namespace for the class. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $rootNamespace |
|
42
|
|
|
* @return string The namespace of the panel's observers |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function getDefaultNamespace($rootNamespace) |
|
45
|
|
|
{ |
|
46
|
|
|
return $rootNamespace.'\Observers'; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Execute the console command. |
|
51
|
|
|
* |
|
52
|
|
|
* @return void |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
public function handle() |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
$name = $this->qualifyClass($this->getNameInput()); |
|
57
|
|
|
|
|
58
|
|
|
if ($this->files->exists($path = $this->getPath($name . 'Observer'))) |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->error($this->type.' already exists!'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$this->makeDirectory($path); |
|
64
|
|
|
|
|
65
|
|
|
$this->files->put($path, $this->buildClass($name)); |
|
66
|
|
|
|
|
67
|
|
|
$this->info($this->type.' created successfully.'); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.