Completed
Push — master ( 252f02...b5c386 )
by wen
12:02
created

ComponentMakeCommand::createObserver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Sco\Admin\Console;
4
5
use Illuminate\Console\GeneratorCommand;
6
use Symfony\Component\Console\Input\InputOption;
7
8
class ComponentMakeCommand extends GeneratorCommand
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $name = 'make:component';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Create a new component class(ScoAdmin)';
23
24
    /**
25
     * The type of class being generated.
26
     *
27
     * @var string
28
     */
29
    protected $type = 'Component';
30
31
    /**
32
     * Execute the console command.
33
     *
34
     * @return void
35
     */
36
    public function handle()
37
    {
38
        if (parent::handle() === false && !$this->option('force')) {
39
            return;
40
        }
41
42
        if ($this->option('observer')) {
43
            $this->createObserver();
44
        }
45
    }
46
47
    /**
48
     * Create a new permission observer for the component
49
     */
50
    protected function createObserver()
51
    {
52
        $this->call('make:observer', [
53
            'name' => $this->argument('name') . 'Observer'
54
        ]);
55
    }
56
57
    /**
58
     * Get the stub file for the generator.
59
     *
60
     * @return string
61
     */
62
    protected function getStub()
63
    {
64
        return __DIR__ . '/stubs/component.stub';
65
    }
66
67
    /**
68
     * Get the default namespace for the class.
69
     *
70
     * @param  string  $rootNamespace
71
     * @return string
72
     */
73
    protected function getDefaultNamespace($rootNamespace)
74
    {
75
        return $rootNamespace . '\Components';
76
    }
77
78
    /**
79
     * Get the console command options.
80
     *
81
     * @return array
82
     */
83
    protected function getOptions()
84
    {
85
        return [
86
            [
87
                'observer', 'o', InputOption::VALUE_NONE,
88
                'Create a new permission observer for the component',
89
            ],
90
            [
91
                'force', null, InputOption::VALUE_NONE,
92
                'Create the class even if the component already exists.',
93
            ],
94
        ];
95
    }
96
}
97