1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mjedari\Larafilter\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\GeneratorCommand; |
6
|
|
|
use Mjedari\Larafilter\Facades\LaraFilter; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
|
9
|
|
|
class MakeFilterCommand extends GeneratorCommand |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The name and signature of the console command. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $name = 'make:filter'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The name and signature of the console command. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $type = 'filter'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The console command description. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $description = 'Create a new query filter class.'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get the console command arguments. |
34
|
|
|
* |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
protected function getArguments() |
38
|
|
|
{ |
39
|
|
|
return [ |
40
|
|
|
['name', InputArgument::REQUIRED, 'The name of the filter'], |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get the desired class name from the input. |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
protected function getNameInput() |
50
|
|
|
{ |
51
|
|
|
return ucfirst(trim($this->argument('name'))); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function getStub() |
55
|
|
|
{ |
56
|
|
|
return __DIR__.'/stubs/filter.php.stub'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function getDefaultNamespace($rootNamespace) |
60
|
|
|
{ |
61
|
|
|
return $rootNamespace.'\Filters'; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Execute the console command. |
66
|
|
|
*/ |
67
|
|
|
public function handle() |
68
|
|
|
{ |
69
|
|
|
parent::handle(); |
70
|
|
|
|
71
|
|
|
$this->doOtherOperations(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected function doOtherOperations() |
75
|
|
|
{ |
76
|
|
|
if (larafilter::configNotPublished()) { |
77
|
|
|
return $this->warn('Please publish the config file by running '. |
78
|
|
|
'\'php artisan vendor:publish --tag=larafilter-config\''); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
// Get the fully qualified class name (FQN) |
82
|
|
|
$class = $this->qualifyClass($this->getNameInput()); |
83
|
|
|
|
84
|
|
|
// get the destination path, based on the default namespace |
85
|
|
|
$path = $this->getPath($class); |
86
|
|
|
|
87
|
|
|
$content = file_get_contents($path); |
88
|
|
|
|
89
|
|
|
// Update the file content with additional data (regular expressions) |
90
|
|
|
|
91
|
|
|
file_put_contents($path, $content); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
protected function rootNamespace() |
95
|
|
|
{ |
96
|
|
|
return $this->laravel->getNamespace(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
protected function getPath($name) |
100
|
|
|
{ |
101
|
|
|
return parent::getPath($name); // TODO: Change the autogenerated stub |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|