1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PerfectOblivion\Valid\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Config; |
6
|
|
|
use Illuminate\Console\GeneratorCommand; |
7
|
|
|
use PerfectOblivion\Valid\Exceptions\InvalidNamespaceException; |
8
|
|
|
|
9
|
|
|
class ValidationServiceMakeCommand extends GeneratorCommand |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The console command signature. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $signature = 'adr:validation {name}'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Create new validation service class'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The type of class being generated. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $type = 'Validation Service'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Execute the console command. |
34
|
|
|
*/ |
35
|
|
|
public function handle() |
36
|
|
|
{ |
37
|
|
|
if (false === parent::handle() && ! $this->option('force')) { |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get the stub file for the generator. |
44
|
|
|
* |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
protected function getStub() |
48
|
|
|
{ |
49
|
|
|
return __DIR__.'/stubs/validation-service.stub'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get the default namespace for the class. |
54
|
|
|
* |
55
|
|
|
* @param string $rootNamespace |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
protected function getDefaultNamespace($rootNamespace) |
60
|
|
|
{ |
61
|
|
|
$validationNamespace = Config::get('valid.validation-services.namespace', ''); |
62
|
|
|
|
63
|
|
|
if (! $validationNamespace) { |
64
|
|
|
throw InvalidNamespaceException::missingValidationServiceNamespace(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $rootNamespace.'\\'.$validationNamespace; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the desired class name from the input. |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
protected function getNameInput() |
76
|
|
|
{ |
77
|
|
|
$input = studly_case(trim($this->argument('name'))); |
78
|
|
|
$validatorSuffix = Config::get('valid.validation-services.suffix'); |
79
|
|
|
|
80
|
|
|
if (Config::get('valid.validation-services.override_duplicate_suffix')) { |
81
|
|
|
return str_finish($input, $validatorSuffix); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $input.$validatorSuffix; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|