1 | <?php |
||
10 | class ResourceMakeCommand extends Command |
||
11 | { |
||
12 | /** |
||
13 | * The name and signature of the console command. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $signature = 'make:resource {name : The model name} {attributes?}'; |
||
18 | |||
19 | /** |
||
20 | * The console command description. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $description = 'Create a new model, migration, controller and add routes'; |
||
25 | |||
26 | /** |
||
27 | * The filesystem instance. |
||
28 | * |
||
29 | * @var \Illuminate\Filesystem\Filesystem |
||
30 | */ |
||
31 | private $files; |
||
32 | |||
33 | /** |
||
34 | * @var Composer |
||
35 | */ |
||
36 | private $composer; |
||
37 | |||
38 | /** |
||
39 | * @var array The data types that can be created in a migration. |
||
40 | */ |
||
41 | private $dataTypes = [ |
||
42 | 'string', 'integer', 'boolean', 'bigIncrements', 'bigInteger', |
||
43 | 'binary', 'boolean', 'char', 'date', 'dateTime', 'float', 'increments', |
||
44 | 'json', 'jsonb', 'longText', 'mediumInteger', 'mediumText', 'nullableTimestamps', |
||
45 | 'smallInteger', 'tinyInteger', 'softDeletes', 'text', 'time', 'timestamp', |
||
46 | 'timestamps', 'rememberToken', |
||
47 | ]; |
||
48 | |||
49 | private $fakerMethods = [ |
||
50 | 'string' => ['method' => 'words', 'parameters' => '2, true'], |
||
51 | 'integer' => ['method' => 'randomNumber', 'parameters' => ''], |
||
52 | ]; |
||
53 | |||
54 | /** |
||
55 | * @var array $columnProperties Properties that can be applied to a table column. |
||
56 | */ |
||
57 | private $columnProperties = [ |
||
58 | 'unsigned', 'index', 'nullable' |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * Create a new command instance. |
||
63 | * |
||
64 | * @param Filesystem $files |
||
65 | * @param Composer $composer |
||
66 | */ |
||
67 | public function __construct(Filesystem $files, Composer $composer) |
||
75 | |||
76 | /** |
||
77 | * Execute the console command. |
||
78 | * |
||
79 | * @return mixed |
||
80 | */ |
||
81 | public function handle() |
||
95 | |||
96 | private function createModelFactory($name) |
||
119 | |||
120 | public function buildFakerAttributes($attributes) |
||
138 | |||
139 | /** |
||
140 | * Create and store a new Model to the filesystem. |
||
141 | * |
||
142 | * @param string $name |
||
143 | * @return bool |
||
144 | */ |
||
145 | private function createModel($name) |
||
164 | |||
165 | private function createMigration($name) |
||
189 | |||
190 | private function createController($modelName) |
||
211 | |||
212 | private function appendRoutes($modelName) |
||
233 | |||
234 | protected function buildMigration($name) |
||
253 | |||
254 | protected function buildModel($name) |
||
268 | |||
269 | public function convertModelToTableName($model) |
||
273 | |||
274 | public function buildMigrationFilename($model) |
||
280 | |||
281 | private function replaceClassName($name, $stub) |
||
285 | |||
286 | private function addMigrationAttributes($text, $stub) |
||
293 | |||
294 | /** |
||
295 | * Convert a pipe-separated list of attributes to an array. |
||
296 | * |
||
297 | * @param string $text The Pipe separated attributes |
||
298 | * @return array |
||
299 | */ |
||
300 | public function parseAttributesFromInputString($text) |
||
315 | |||
316 | /** |
||
317 | * Convert a PHP array into a string version. |
||
318 | * |
||
319 | * @param $array |
||
320 | * |
||
321 | * @return string |
||
322 | */ |
||
323 | public function convertArrayToString($array) |
||
348 | |||
349 | public function addModelAttributes($name, $attributes, $stub) |
||
361 | |||
362 | public function buildTableColumns($attributes) |
||
380 | |||
381 | /** |
||
382 | * Get the column field type based from the properties of the field being created. |
||
383 | * |
||
384 | * @param array $properties |
||
385 | * @return string |
||
386 | */ |
||
387 | private function getFieldTypeFromProperties($properties) |
||
402 | |||
403 | /** |
||
404 | * Can the data type have it's size controlled within the migration? |
||
405 | * |
||
406 | * @param string $type |
||
407 | * @return bool |
||
408 | */ |
||
409 | private function typeCanDefineSize($type) |
||
413 | |||
414 | /** |
||
415 | * Extract a numeric length value from all properties specified for the attribute. |
||
416 | * |
||
417 | * @param array $properties |
||
418 | * @return int $length |
||
419 | */ |
||
420 | private function extractFieldLengthValue($properties) |
||
430 | |||
431 | /** |
||
432 | * Get the column properties that should be applied to the column. |
||
433 | * |
||
434 | * @param $properties |
||
435 | * @return array |
||
436 | */ |
||
437 | private function extractAttributePropertiesToApply($properties) |
||
441 | |||
442 | /** |
||
443 | * Create a Schema Builder column. |
||
444 | * |
||
445 | * @param string $fieldType The type of column to create |
||
446 | * @param string $name Name of the column to create |
||
447 | * @param int $length Field length |
||
448 | * @param array $traits Additional properties to apply to the column |
||
449 | * @return string |
||
450 | */ |
||
451 | private function buildSchemaColumn($fieldType, $name, $length = 0, $traits = []) |
||
462 | |||
463 | /** |
||
464 | * Build a Model name from a word. |
||
465 | * |
||
466 | * @param string $name |
||
467 | * @return string |
||
468 | */ |
||
469 | private function modelName($name) |
||
473 | |||
474 | } |
||
475 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.