@@ -28,16 +28,74 @@ abstract class GeneratorCommand extends Command
28
28
* @var array
29
29
*/
30
30
protected $ reservedNames = [
31
- '__halt_compiler ' , 'break ' , 'clone ' , 'die ' , 'empty ' , 'endswitch ' , 'final ' ,
32
- 'function ' , 'include ' , 'isset ' , 'print ' , 'require_once ' , 'trait ' , 'while ' ,
33
- 'abstract ' , 'callable ' , 'const ' , 'do ' , 'enddeclare ' , 'endwhile ' , 'finally ' ,
34
- 'global ' , 'include_once ' , 'list ' , 'private ' , 'return ' , 'try ' , 'xor ' , 'and ' ,
35
- 'case ' , 'continue ' , 'echo ' , 'endfor ' , 'eval ' , 'fn ' , 'goto ' , 'instanceof ' ,
36
- 'namespace ' , 'protected ' , 'static ' , 'unset ' , 'yield ' , 'array ' , 'catch ' ,
37
- 'declare ' , 'else ' , 'endforeach ' , 'exit ' , 'for ' , 'if ' , 'insteadof ' , 'new ' ,
38
- 'public ' , 'switch ' , 'use ' , 'as ' , 'class ' , 'default ' , 'elseif ' , 'endif ' ,
39
- 'extends ' , 'foreach ' , 'implements ' , 'interface ' , 'or ' , 'require ' , 'throw ' ,
31
+ '__halt_compiler ' ,
32
+ 'abstract ' ,
33
+ 'and ' ,
34
+ 'array ' ,
35
+ 'as ' ,
36
+ 'break ' ,
37
+ 'callable ' ,
38
+ 'case ' ,
39
+ 'catch ' ,
40
+ 'class ' ,
41
+ 'clone ' ,
42
+ 'const ' ,
43
+ 'continue ' ,
44
+ 'declare ' ,
45
+ 'default ' ,
46
+ 'die ' ,
47
+ 'do ' ,
48
+ 'echo ' ,
49
+ 'else ' ,
50
+ 'elseif ' ,
51
+ 'empty ' ,
52
+ 'enddeclare ' ,
53
+ 'endfor ' ,
54
+ 'endforeach ' ,
55
+ 'endif ' ,
56
+ 'endswitch ' ,
57
+ 'endwhile ' ,
58
+ 'eval ' ,
59
+ 'exit ' ,
60
+ 'extends ' ,
61
+ 'final ' ,
62
+ 'finally ' ,
63
+ 'fn ' ,
64
+ 'for ' ,
65
+ 'foreach ' ,
66
+ 'function ' ,
67
+ 'global ' ,
68
+ 'goto ' ,
69
+ 'if ' ,
70
+ 'implements ' ,
71
+ 'include ' ,
72
+ 'include_once ' ,
73
+ 'instanceof ' ,
74
+ 'insteadof ' ,
75
+ 'interface ' ,
76
+ 'isset ' ,
77
+ 'list ' ,
78
+ 'namespace ' ,
79
+ 'new ' ,
80
+ 'or ' ,
81
+ 'print ' ,
82
+ 'private ' ,
83
+ 'protected ' ,
84
+ 'public ' ,
85
+ 'require ' ,
86
+ 'require_once ' ,
87
+ 'return ' ,
88
+ 'static ' ,
89
+ 'switch ' ,
90
+ 'throw ' ,
91
+ 'trait ' ,
92
+ 'try ' ,
93
+ 'unset ' ,
94
+ 'use ' ,
40
95
'var ' ,
96
+ 'while ' ,
97
+ 'xor ' ,
98
+ 'yield ' ,
41
99
];
42
100
43
101
/**
@@ -69,11 +127,11 @@ abstract protected function getStub();
69
127
*/
70
128
public function handle ()
71
129
{
72
- // First we will check whether the name can be found in the reserved names.
73
- // We have so called "reserved names" to ensure that no files are generated
74
- // using PHP keywords for example, because that would cause errors .
130
+ // First we need to ensure that the given name is not a reserved word within the PHP
131
+ // language and that the class name will actually be valid. If it is not valid we
132
+ // can error now and prevent from polluting the filesystem using invalid files .
75
133
if ($ this ->isReservedName ($ this ->getNameInput ())) {
76
- $ this ->error ('The name " ' .$ this ->getNameInput ().'" is reserved. Please pick something else . ' );
134
+ $ this ->error ('The name " ' .$ this ->getNameInput ().'" is reserved by PHP . ' );
77
135
78
136
return false ;
79
137
}
@@ -82,7 +140,7 @@ public function handle()
82
140
83
141
$ path = $ this ->getPath ($ name );
84
142
85
- // We will check to see if the class already exists. If it does, we don't want
143
+ // Next, We will check to see if the class already exists. If it does, we don't want
86
144
// to create the class and overwrite the user's code. So, we will bail out so the
87
145
// code is untouched. Otherwise, we will continue generating this class' files.
88
146
if ((! $ this ->hasOption ('force ' ) ||
@@ -295,18 +353,6 @@ protected function userProviderModel()
295
353
return $ config ->get ("auth.providers. {$ provider }.model " );
296
354
}
297
355
298
- /**
299
- * Get the console command arguments.
300
- *
301
- * @return array
302
- */
303
- protected function getArguments ()
304
- {
305
- return [
306
- ['name ' , InputArgument::REQUIRED , 'The name of the class ' ],
307
- ];
308
- }
309
-
310
356
/**
311
357
* Checks whether the given name is reserved.
312
358
*
@@ -319,4 +365,16 @@ protected function isReservedName($name)
319
365
320
366
return in_array ($ name , $ this ->reservedNames );
321
367
}
368
+
369
+ /**
370
+ * Get the console command arguments.
371
+ *
372
+ * @return array
373
+ */
374
+ protected function getArguments ()
375
+ {
376
+ return [
377
+ ['name ' , InputArgument::REQUIRED , 'The name of the class ' ],
378
+ ];
379
+ }
322
380
}
0 commit comments