@@ -1,57 +1,57 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - 'options' => [ |
|
5 | - 'generated_by_default' => ['migration', 'controller', 'model'], |
|
6 | - 'override' => true |
|
7 | - ], |
|
8 | - 'modules' => [ |
|
4 | + 'options' => [ |
|
5 | + 'generated_by_default' => ['migration', 'controller', 'model'], |
|
6 | + 'override' => true |
|
7 | + ], |
|
8 | + 'modules' => [ |
|
9 | 9 | |
10 | - // optional parameters : |
|
11 | - // 'multiple'=>[] |
|
12 | - // 'images'=>'single' //Images type: single, multiple |
|
10 | + // optional parameters : |
|
11 | + // 'multiple'=>[] |
|
12 | + // 'images'=>'single' //Images type: single, multiple |
|
13 | 13 | |
14 | - 'categories' => [ |
|
15 | - 'data'=> [ |
|
16 | - // Separated by ':', numeric value represents size of the field its 192 by default and is optional |
|
14 | + 'categories' => [ |
|
15 | + 'data'=> [ |
|
16 | + // Separated by ':', numeric value represents size of the field its 192 by default and is optional |
|
17 | 17 | |
18 | - // Regular data types: |
|
19 | - // string, int, text, bool, date |
|
18 | + // Regular data types: |
|
19 | + // string, int, text, bool, date |
|
20 | 20 | |
21 | - // Data type modifiers |
|
22 | - // unique |
|
21 | + // Data type modifiers |
|
22 | + // unique |
|
23 | 23 | |
24 | - //Must start with data type nd then followed by size, then by modifiers if required |
|
24 | + //Must start with data type nd then followed by size, then by modifiers if required |
|
25 | 25 | |
26 | - // Special data types: |
|
27 | - // parent: requires name of a module, creates a one-to-many relation with the current module |
|
28 | - // related: requires name of a module, creates many to many relation with current module |
|
26 | + // Special data types: |
|
27 | + // parent: requires name of a module, creates a one-to-many relation with the current module |
|
28 | + // related: requires name of a module, creates many to many relation with current module |
|
29 | 29 | |
30 | - 'title' => 'string:128', |
|
31 | - 'slug' => 'string:128:unique', |
|
32 | - 'short_description' => 'string', |
|
33 | - ], |
|
34 | - 'images'=>'single' |
|
35 | - ], |
|
30 | + 'title' => 'string:128', |
|
31 | + 'slug' => 'string:128:unique', |
|
32 | + 'short_description' => 'string', |
|
33 | + ], |
|
34 | + 'images'=>'single' |
|
35 | + ], |
|
36 | 36 | |
37 | - 'tags' => [ |
|
38 | - 'data'=> [ |
|
39 | - 'title' => 'string:128' |
|
40 | - ] |
|
41 | - ], |
|
37 | + 'tags' => [ |
|
38 | + 'data'=> [ |
|
39 | + 'title' => 'string:128' |
|
40 | + ] |
|
41 | + ], |
|
42 | 42 | |
43 | - 'posts' => [ |
|
44 | - 'data' => [ |
|
45 | - 'author' => 'parent:users', |
|
46 | - 'title' => 'string:256', |
|
47 | - 'slug' => 'string:128:unique', |
|
48 | - 'short_description' => 'string', |
|
49 | - 'full_description' => 'text', |
|
50 | - 'category' => 'parent:categories', |
|
51 | - 'posted_at' => 'datetime', |
|
52 | - 'tags' => 'related:tags' |
|
53 | - ], |
|
54 | - 'images'=>'multiple' |
|
55 | - ], |
|
56 | - ] |
|
43 | + 'posts' => [ |
|
44 | + 'data' => [ |
|
45 | + 'author' => 'parent:users', |
|
46 | + 'title' => 'string:256', |
|
47 | + 'slug' => 'string:128:unique', |
|
48 | + 'short_description' => 'string', |
|
49 | + 'full_description' => 'text', |
|
50 | + 'category' => 'parent:categories', |
|
51 | + 'posted_at' => 'datetime', |
|
52 | + 'tags' => 'related:tags' |
|
53 | + ], |
|
54 | + 'images'=>'multiple' |
|
55 | + ], |
|
56 | + ] |
|
57 | 57 | ]; |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | '{{modelTableSchema}}' => $this->getSchema() |
20 | 20 | ]); |
21 | 21 | |
22 | - $dateSuffix = (int)date('His') + ++self::$counter; |
|
23 | - file_put_contents(database_path() . "/migrations/" . date('Y_m_d_') . $dateSuffix . "_create_" . $module->getModuleName() . "_table.php", $migrationTemplate); |
|
22 | + $dateSuffix = (int) date('His') + ++self::$counter; |
|
23 | + file_put_contents(database_path()."/migrations/".date('Y_m_d_').$dateSuffix."_create_".$module->getModuleName()."_table.php", $migrationTemplate); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | protected function getSchema() |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $schema .= $option->getSchema(); |
36 | 36 | |
37 | 37 | if ($column != $lastColumn) { |
38 | - $schema .= PHP_EOL . $this->getTabs(3); |
|
38 | + $schema .= PHP_EOL.$this->getTabs(3); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 |
@@ -6,7 +6,7 @@ |
||
6 | 6 | |
7 | 7 | class BaseGenerator |
8 | 8 | { |
9 | - protected $module; |
|
9 | + protected $module; |
|
10 | 10 | |
11 | 11 | public function getModule() |
12 | 12 | { |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | public function getStub($type) |
22 | 22 | { |
23 | - return file_get_contents(__DIR__ . "/../resources/stubs/" . $type . ".stub"); |
|
23 | + return file_get_contents(__DIR__."/../resources/stubs/".$type.".stub"); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public function buildTemplate($stub, $variables) |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | public function getTabs($number) |
32 | 32 | { |
33 | 33 | $schema = ""; |
34 | - for ($i=0; $i < $number; $i++) { |
|
34 | + for ($i = 0; $i < $number; $i++) { |
|
35 | 35 | $schema .= " "; |
36 | 36 | } |
37 | 37 | return $schema; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | '{{foreignMethods}}' => $this->getForeignMethods() |
16 | 16 | ]); |
17 | 17 | |
18 | - file_put_contents(base_path("app/Models/" . $module->getModelName() . ".php"), $migrationTemplate); |
|
18 | + file_put_contents(base_path("app/Models/".$module->getModelName().".php"), $migrationTemplate); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | protected function getMassAssignables() |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | foreach ($this->module->getData() as $column => $optionString) { |
26 | 26 | $optionArray = explode(':', $optionString); |
27 | 27 | if (in_array($optionArray[0], ['string', 'int', 'text', 'bool', 'date'])) { |
28 | - $massAssignables[] = "'" . $column . "'"; |
|
28 | + $massAssignables[] = "'".$column."'"; |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 |
@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | public function __construct($module) |
16 | 16 | { |
17 | - $this->module = (object)$module; |
|
17 | + $this->module = (object) $module; |
|
18 | 18 | $this->data = $this->module->data; |
19 | 19 | $this->name = $this->module->name; |
20 | 20 | } |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | { |
51 | 51 | if ($this->hasSpecialSchema()) { |
52 | 52 | $schema = $this->processSpecialSchema(); |
53 | - }else{ |
|
53 | + } else { |
|
54 | 54 | foreach ($this->optionArray as $option) { |
55 | 55 | if ($option == self::COLUMN_UNIQUE) $this->hasUnique(); |
56 | - if (is_numeric($option) && $option <= 2048) $this->hasSize((int)$option); |
|
56 | + if (is_numeric($option) && $option <= 2048) $this->hasSize((int) $option); |
|
57 | 57 | } |
58 | 58 | |
59 | - $schema = '$table->' . $this->getType() . "('{$this->column}'"; |
|
59 | + $schema = '$table->'.$this->getType()."('{$this->column}'"; |
|
60 | 60 | $schema .= $this->hasSize() ? ", {$this->getSize()})" : ")"; |
61 | 61 | $schema .= $this->isUnique() ? "->unique()" : ""; |
62 | 62 | $schema .= ";"; |
@@ -64,23 +64,23 @@ discard block |
||
64 | 64 | return $schema; |
65 | 65 | } |
66 | 66 | |
67 | - protected function getType(){ |
|
67 | + protected function getType() { |
|
68 | 68 | return $this->keyToType[array_shift($this->optionArray)]; |
69 | 69 | } |
70 | 70 | |
71 | - protected function getSize(){ |
|
71 | + protected function getSize() { |
|
72 | 72 | return $this->size; |
73 | 73 | } |
74 | 74 | |
75 | - protected function isUnique(){ |
|
75 | + protected function isUnique() { |
|
76 | 76 | return $this->uniqueFlag; |
77 | 77 | } |
78 | 78 | |
79 | - protected function hasUnique($set = true){ |
|
79 | + protected function hasUnique($set = true) { |
|
80 | 80 | $this->uniqueFlag = ($set === true) ? true : false; |
81 | 81 | } |
82 | 82 | |
83 | - protected function hasSize($size = null){ |
|
83 | + protected function hasSize($size = null) { |
|
84 | 84 | if ($size !== null) { |
85 | 85 | $this->size = $size; |
86 | 86 | } |
@@ -90,31 +90,31 @@ discard block |
||
90 | 90 | public function getTabs($number) |
91 | 91 | { |
92 | 92 | $schema = ""; |
93 | - for ($i=0; $i < $number; $i++) { |
|
93 | + for ($i = 0; $i < $number; $i++) { |
|
94 | 94 | $schema .= " "; |
95 | 95 | } |
96 | 96 | return $schema; |
97 | 97 | } |
98 | 98 | |
99 | - protected function processSpecialSchema(){ |
|
100 | - $specialMethod = 'process' . ucfirst($this->specialType); |
|
99 | + protected function processSpecialSchema() { |
|
100 | + $specialMethod = 'process'.ucfirst($this->specialType); |
|
101 | 101 | return $this->$specialMethod(); |
102 | 102 | } |
103 | 103 | |
104 | - protected function processParent(){ |
|
104 | + protected function processParent() { |
|
105 | 105 | $schema = ""; |
106 | 106 | $parent = array_pop($this->optionArray); |
107 | - $schema .= "\$table->integer('" . str_singular($parent) . "_id')->unsigned()->nullable();"; |
|
108 | - $schema .= PHP_EOL . $this->getTabs(3); |
|
109 | - $schema .= "\$table->foreign('" . str_singular($parent) . "_id')->references('id')->on('$parent')->onDelete('set null');"; |
|
107 | + $schema .= "\$table->integer('".str_singular($parent)."_id')->unsigned()->nullable();"; |
|
108 | + $schema .= PHP_EOL.$this->getTabs(3); |
|
109 | + $schema .= "\$table->foreign('".str_singular($parent)."_id')->references('id')->on('$parent')->onDelete('set null');"; |
|
110 | 110 | return $schema; |
111 | 111 | } |
112 | 112 | |
113 | - protected function processRelated(){ |
|
113 | + protected function processRelated() { |
|
114 | 114 | return ""; |
115 | 115 | } |
116 | 116 | |
117 | - protected function hasSpecialSchema(){ |
|
117 | + protected function hasSpecialSchema() { |
|
118 | 118 | if ($this->optionArray[0] == self::TYPE_PARENT) { |
119 | 119 | array_shift($this->optionArray); |
120 | 120 | $this->specialType = self::TYPE_PARENT; |
@@ -50,10 +50,14 @@ |
||
50 | 50 | { |
51 | 51 | if ($this->hasSpecialSchema()) { |
52 | 52 | $schema = $this->processSpecialSchema(); |
53 | - }else{ |
|
53 | + } else{ |
|
54 | 54 | foreach ($this->optionArray as $option) { |
55 | - if ($option == self::COLUMN_UNIQUE) $this->hasUnique(); |
|
56 | - if (is_numeric($option) && $option <= 2048) $this->hasSize((int)$option); |
|
55 | + if ($option == self::COLUMN_UNIQUE) { |
|
56 | + $this->hasUnique(); |
|
57 | + } |
|
58 | + if (is_numeric($option) && $option <= 2048) { |
|
59 | + $this->hasSize((int)$option); |
|
60 | + } |
|
57 | 61 | } |
58 | 62 | |
59 | 63 | $schema = '$table->' . $this->getType() . "('{$this->column}'"; |