@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | /** |
| 26 | 26 | * Replace and store the Stub. |
| 27 | 27 | * |
| 28 | - * @return string |
|
| 28 | + * @return TranslateCompiler |
|
| 29 | 29 | */ |
| 30 | 30 | public function replaceAndStore() |
| 31 | 31 | { |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * Get output filename |
| 72 | 72 | * |
| 73 | 73 | * |
| 74 | - * @return $this |
|
| 74 | + * @return string |
|
| 75 | 75 | */ |
| 76 | 76 | protected function getOutputFilename() |
| 77 | 77 | { |
@@ -2,13 +2,11 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Scaffolder\Compilers\AngularJs; |
| 4 | 4 | |
| 5 | -use Illuminate\Support\Facades\File; |
|
| 6 | 5 | use Scaffolder\Compilers\AbstractCompiler; |
| 7 | 6 | use Scaffolder\Compilers\Support\FileToCompile; |
| 8 | 7 | use Scaffolder\Compilers\Support\PathParser; |
| 9 | 8 | use Scaffolder\Support\Directory; |
| 10 | 9 | use Scaffolder\Support\CamelCase; |
| 11 | -use stdClass ; |
|
| 12 | 10 | |
| 13 | 11 | |
| 14 | 12 | class TranslateCompiler extends AbstractCompiler |
@@ -13,73 +13,73 @@ |
||
| 13 | 13 | |
| 14 | 14 | class TranslateCompiler extends AbstractCompiler |
| 15 | 15 | { |
| 16 | - protected $cachePrefix = 'translate_'; |
|
| 17 | - protected $stubFilename = 'Translate.js' ; |
|
| 18 | - |
|
| 19 | - public function __construct($scaffolderConfig, $modelData = null) |
|
| 20 | - { |
|
| 21 | - $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/'; |
|
| 22 | - parent::__construct($scaffolderConfig, $modelData); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Replace and store the Stub. |
|
| 27 | - * |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function replaceAndStore() |
|
| 31 | - { |
|
| 16 | + protected $cachePrefix = 'translate_'; |
|
| 17 | + protected $stubFilename = 'Translate.js' ; |
|
| 18 | + |
|
| 19 | + public function __construct($scaffolderConfig, $modelData = null) |
|
| 20 | + { |
|
| 21 | + $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/'; |
|
| 22 | + parent::__construct($scaffolderConfig, $modelData); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Replace and store the Stub. |
|
| 27 | + * |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function replaceAndStore() |
|
| 31 | + { |
|
| 32 | 32 | |
| 33 | - return $this->replaceColumns() |
|
| 34 | - ->replaceArea() |
|
| 35 | - ->store(new FileToCompile(false, $this->modelData->modelHash)); |
|
| 33 | + return $this->replaceColumns() |
|
| 34 | + ->replaceArea() |
|
| 35 | + ->store(new FileToCompile(false, $this->modelData->modelHash)); |
|
| 36 | 36 | |
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * replace columns |
|
| 41 | - * |
|
| 42 | - * @return $this |
|
| 43 | - */ |
|
| 44 | - public function replaceArea(){ |
|
| 45 | - $this->stub = str_replace('{{singular}}', ucwords($this->modelData->tableName), $this->stub); |
|
| 46 | - $this->stub = str_replace('{{plural}}', ucwords(CamelCase::pluralize($this->modelData->tableName)), $this->stub); |
|
| 47 | - return $this; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * replace columns |
|
| 52 | - * |
|
| 53 | - * @return $this |
|
| 54 | - */ |
|
| 55 | - public function replaceColumns(){ |
|
| 56 | - |
|
| 57 | - $columns = []; |
|
| 58 | - |
|
| 59 | - foreach ($this->modelData->fields as $field) |
|
| 60 | - { |
|
| 61 | - array_push($columns, "\t\t".sprintf('"%s" : "%s"', $field->name, CamelCase::convertToCamelCase($field->name) )); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - $this->stub = str_replace('{{columns}}', join(",\n", $columns), $this->stub); |
|
| 65 | - |
|
| 66 | - return $this ; |
|
| 67 | - |
|
| 68 | - } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * replace columns |
|
| 41 | + * |
|
| 42 | + * @return $this |
|
| 43 | + */ |
|
| 44 | + public function replaceArea(){ |
|
| 45 | + $this->stub = str_replace('{{singular}}', ucwords($this->modelData->tableName), $this->stub); |
|
| 46 | + $this->stub = str_replace('{{plural}}', ucwords(CamelCase::pluralize($this->modelData->tableName)), $this->stub); |
|
| 47 | + return $this; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * replace columns |
|
| 52 | + * |
|
| 53 | + * @return $this |
|
| 54 | + */ |
|
| 55 | + public function replaceColumns(){ |
|
| 56 | + |
|
| 57 | + $columns = []; |
|
| 58 | + |
|
| 59 | + foreach ($this->modelData->fields as $field) |
|
| 60 | + { |
|
| 61 | + array_push($columns, "\t\t".sprintf('"%s" : "%s"', $field->name, CamelCase::convertToCamelCase($field->name) )); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + $this->stub = str_replace('{{columns}}', join(",\n", $columns), $this->stub); |
|
| 65 | + |
|
| 66 | + return $this ; |
|
| 67 | + |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Get output filename |
|
| 72 | - * |
|
| 73 | - * |
|
| 74 | - * @return $this |
|
| 75 | - */ |
|
| 76 | - protected function getOutputFilename() |
|
| 77 | - { |
|
| 78 | - $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/i18n/' ; |
|
| 79 | - |
|
| 80 | - Directory::createIfNotExists($folder, 0755, true); |
|
| 81 | - |
|
| 82 | - return $folder . 'en.json'; |
|
| 83 | - } |
|
| 70 | + /** |
|
| 71 | + * Get output filename |
|
| 72 | + * |
|
| 73 | + * |
|
| 74 | + * @return $this |
|
| 75 | + */ |
|
| 76 | + protected function getOutputFilename() |
|
| 77 | + { |
|
| 78 | + $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/i18n/' ; |
|
| 79 | + |
|
| 80 | + Directory::createIfNotExists($folder, 0755, true); |
|
| 81 | + |
|
| 82 | + return $folder . 'en.json'; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | } |
| 86 | 86 | \ No newline at end of file |
@@ -8,17 +8,17 @@ discard block |
||
| 8 | 8 | use Scaffolder\Compilers\Support\PathParser; |
| 9 | 9 | use Scaffolder\Support\Directory; |
| 10 | 10 | use Scaffolder\Support\CamelCase; |
| 11 | -use stdClass ; |
|
| 11 | +use stdClass; |
|
| 12 | 12 | |
| 13 | 13 | |
| 14 | 14 | class TranslateCompiler extends AbstractCompiler |
| 15 | 15 | { |
| 16 | 16 | protected $cachePrefix = 'translate_'; |
| 17 | - protected $stubFilename = 'Translate.js' ; |
|
| 17 | + protected $stubFilename = 'Translate.js'; |
|
| 18 | 18 | |
| 19 | 19 | public function __construct($scaffolderConfig, $modelData = null) |
| 20 | 20 | { |
| 21 | - $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/'; |
|
| 21 | + $this->stubsDirectory = __DIR__.'/../../../../stubs/AngularJs/'; |
|
| 22 | 22 | parent::__construct($scaffolderConfig, $modelData); |
| 23 | 23 | } |
| 24 | 24 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return $this |
| 43 | 43 | */ |
| 44 | - public function replaceArea(){ |
|
| 44 | + public function replaceArea() { |
|
| 45 | 45 | $this->stub = str_replace('{{singular}}', ucwords($this->modelData->tableName), $this->stub); |
| 46 | 46 | $this->stub = str_replace('{{plural}}', ucwords(CamelCase::pluralize($this->modelData->tableName)), $this->stub); |
| 47 | 47 | return $this; |
@@ -52,18 +52,18 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return $this |
| 54 | 54 | */ |
| 55 | - public function replaceColumns(){ |
|
| 55 | + public function replaceColumns() { |
|
| 56 | 56 | |
| 57 | 57 | $columns = []; |
| 58 | 58 | |
| 59 | 59 | foreach ($this->modelData->fields as $field) |
| 60 | 60 | { |
| 61 | - array_push($columns, "\t\t".sprintf('"%s" : "%s"', $field->name, CamelCase::convertToCamelCase($field->name) )); |
|
| 61 | + array_push($columns, "\t\t".sprintf('"%s" : "%s"', $field->name, CamelCase::convertToCamelCase($field->name))); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $this->stub = str_replace('{{columns}}', join(",\n", $columns), $this->stub); |
| 65 | 65 | |
| 66 | - return $this ; |
|
| 66 | + return $this; |
|
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | protected function getOutputFilename() |
| 77 | 77 | { |
| 78 | - $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/i18n/' ; |
|
| 78 | + $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/i18n/'; |
|
| 79 | 79 | |
| 80 | 80 | Directory::createIfNotExists($folder, 0755, true); |
| 81 | 81 | |
| 82 | - return $folder . 'en.json'; |
|
| 82 | + return $folder.'en.json'; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | } |
| 86 | 86 | \ No newline at end of file |
@@ -13,6 +13,9 @@ discard block |
||
| 13 | 13 | protected $cachePrefix = 'controller_'; |
| 14 | 14 | protected $stubFilename = 'Controller/Controller.php' ; |
| 15 | 15 | |
| 16 | + /** |
|
| 17 | + * @param string $stubName |
|
| 18 | + */ |
|
| 16 | 19 | public function __construct($scaffolderConfig, $modelData = null, $stubName = null) |
| 17 | 20 | { |
| 18 | 21 | if ($stubName) |
@@ -24,7 +27,7 @@ discard block |
||
| 24 | 27 | /** |
| 25 | 28 | * Replace and store the Stub. |
| 26 | 29 | * |
| 27 | - * @return string |
|
| 30 | + * @return ControllerCompiler |
|
| 28 | 31 | */ |
| 29 | 32 | public function replaceAndStore() |
| 30 | 33 | { |
@@ -49,7 +52,7 @@ discard block |
||
| 49 | 52 | * Get output filename |
| 50 | 53 | * |
| 51 | 54 | * |
| 52 | - * @return $this |
|
| 55 | + * @return string |
|
| 53 | 56 | */ |
| 54 | 57 | protected function getOutputFilename() |
| 55 | 58 | { |
@@ -474,6 +477,10 @@ discard block |
||
| 474 | 477 | * @return $this |
| 475 | 478 | */ |
| 476 | 479 | private $conditionsStub = []; |
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @return string |
|
| 483 | + */ |
|
| 477 | 484 | private function getConditionStubByField($field){ |
| 478 | 485 | |
| 479 | 486 | if($field->index == 'primary'){ |
@@ -10,437 +10,437 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | class ControllerCompiler extends AbstractCompiler |
| 12 | 12 | { |
| 13 | - protected $cachePrefix = 'controller_'; |
|
| 14 | - protected $stubFilename = 'Controller/Controller.php' ; |
|
| 13 | + protected $cachePrefix = 'controller_'; |
|
| 14 | + protected $stubFilename = 'Controller/Controller.php' ; |
|
| 15 | 15 | |
| 16 | - public function __construct($scaffolderConfig, $modelData = null, $stubName = null) |
|
| 17 | - { |
|
| 18 | - if ($stubName) |
|
| 19 | - $this->stubFilename = $stubName; |
|
| 20 | - $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
|
| 21 | - parent::__construct($scaffolderConfig, $modelData); |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Replace and store the Stub. |
|
| 26 | - * |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function replaceAndStore() |
|
| 30 | - { |
|
| 16 | + public function __construct($scaffolderConfig, $modelData = null, $stubName = null) |
|
| 17 | + { |
|
| 18 | + if ($stubName) |
|
| 19 | + $this->stubFilename = $stubName; |
|
| 20 | + $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
|
| 21 | + parent::__construct($scaffolderConfig, $modelData); |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Replace and store the Stub. |
|
| 26 | + * |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function replaceAndStore() |
|
| 30 | + { |
|
| 31 | 31 | |
| 32 | - return $this->replacePrimaryKey() |
|
| 33 | - ->replaceEagerCode() |
|
| 34 | - ->replaceUniqueRules() |
|
| 35 | - ->replaceSearchConditions() |
|
| 36 | - ->replaceSimpleFilter() |
|
| 37 | - ->replaceSortConditions() |
|
| 38 | - ->replaceRoutePrefix() |
|
| 39 | - ->replaceReverseRelationships() |
|
| 40 | - ->replaceCheckbox() |
|
| 41 | - ->replaceEnum() |
|
| 42 | - ->replaceRelationshipTables() |
|
| 43 | - ->store(new FileToCompile(false, $this->modelData->modelHash)); |
|
| 32 | + return $this->replacePrimaryKey() |
|
| 33 | + ->replaceEagerCode() |
|
| 34 | + ->replaceUniqueRules() |
|
| 35 | + ->replaceSearchConditions() |
|
| 36 | + ->replaceSimpleFilter() |
|
| 37 | + ->replaceSortConditions() |
|
| 38 | + ->replaceRoutePrefix() |
|
| 39 | + ->replaceReverseRelationships() |
|
| 40 | + ->replaceCheckbox() |
|
| 41 | + ->replaceEnum() |
|
| 42 | + ->replaceRelationshipTables() |
|
| 43 | + ->store(new FileToCompile(false, $this->modelData->modelHash)); |
|
| 44 | 44 | |
| 45 | - } |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Get output filename |
|
| 50 | - * |
|
| 51 | - * |
|
| 52 | - * @return $this |
|
| 53 | - */ |
|
| 54 | - protected function getOutputFilename() |
|
| 55 | - { |
|
| 56 | - |
|
| 57 | - return PathParser::parse($this->scaffolderConfig->generator->paths->controllers) . $this->modelName . 'Controller.php'; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Replace eager code for each foreing key with eager = true |
|
| 62 | - * |
|
| 63 | - * @return $this |
|
| 64 | - */ |
|
| 65 | - private function replaceEagerCode() |
|
| 66 | - { |
|
| 67 | - $storeCommands = $updateCommands = $ruleCommands = $useCommands = ''; |
|
| 68 | - $eagerConditions = $eagerJoins = ''; |
|
| 69 | - |
|
| 70 | - $storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php'); |
|
| 71 | - $updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php'); |
|
| 72 | - $rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php'); |
|
| 73 | - $useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php'); |
|
| 74 | - $joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php'); |
|
| 75 | - |
|
| 76 | - foreach ($this->modelData->fields as $field) |
|
| 77 | - { |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Get output filename |
|
| 50 | + * |
|
| 51 | + * |
|
| 52 | + * @return $this |
|
| 53 | + */ |
|
| 54 | + protected function getOutputFilename() |
|
| 55 | + { |
|
| 56 | + |
|
| 57 | + return PathParser::parse($this->scaffolderConfig->generator->paths->controllers) . $this->modelName . 'Controller.php'; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Replace eager code for each foreing key with eager = true |
|
| 62 | + * |
|
| 63 | + * @return $this |
|
| 64 | + */ |
|
| 65 | + private function replaceEagerCode() |
|
| 66 | + { |
|
| 67 | + $storeCommands = $updateCommands = $ruleCommands = $useCommands = ''; |
|
| 68 | + $eagerConditions = $eagerJoins = ''; |
|
| 69 | + |
|
| 70 | + $storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php'); |
|
| 71 | + $updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php'); |
|
| 72 | + $rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php'); |
|
| 73 | + $useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php'); |
|
| 74 | + $joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php'); |
|
| 75 | + |
|
| 76 | + foreach ($this->modelData->fields as $field) |
|
| 77 | + { |
|
| 78 | 78 | |
| 79 | - // Check foreign key |
|
| 80 | - if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager) |
|
| 81 | - { |
|
| 82 | - |
|
| 83 | - $storeCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal)); |
|
| 84 | - $updateCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ; |
|
| 85 | - $ruleCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ; |
|
| 86 | - $useCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ; |
|
| 87 | - $eagerJoins .= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ; |
|
| 88 | - |
|
| 89 | - // search eager fields |
|
| 90 | - $foreignModelData = $this->getModelData($field->foreignKey->table); |
|
| 91 | - $foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData); |
|
| 92 | - $foreignControllerCompiler->setEagerTable($this->modelData->tableName); |
|
| 93 | - $eagerConditions .= $foreignControllerCompiler->getSearchConditions(); |
|
| 94 | - $eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules(); |
|
| 95 | - $eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules); |
|
| 96 | - $eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules); |
|
| 97 | - $ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $this->stub = str_replace('{{store_eager_objects}}', $storeCommands, $this->stub); |
|
| 103 | - $this->stub = str_replace('{{update_eager_objects}}', $updateCommands, $this->stub); |
|
| 104 | - $this->stub = str_replace('{{rules_eager}}', $ruleCommands, $this->stub); |
|
| 105 | - $this->stub = str_replace('{{eager_use_classes}}', $useCommands, $this->stub); |
|
| 106 | - $this->stub = str_replace('{{eager_joins}}', $eagerJoins, $this->stub); |
|
| 107 | - $this->stub = str_replace('{{eager_conditions}}', $eagerConditions, $this->stub); |
|
| 108 | - $this->stub = str_replace('{{eager_table}}', $this->eagerTable, $this->stub); |
|
| 79 | + // Check foreign key |
|
| 80 | + if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager) |
|
| 81 | + { |
|
| 82 | + |
|
| 83 | + $storeCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal)); |
|
| 84 | + $updateCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ; |
|
| 85 | + $ruleCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ; |
|
| 86 | + $useCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ; |
|
| 87 | + $eagerJoins .= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ; |
|
| 88 | + |
|
| 89 | + // search eager fields |
|
| 90 | + $foreignModelData = $this->getModelData($field->foreignKey->table); |
|
| 91 | + $foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData); |
|
| 92 | + $foreignControllerCompiler->setEagerTable($this->modelData->tableName); |
|
| 93 | + $eagerConditions .= $foreignControllerCompiler->getSearchConditions(); |
|
| 94 | + $eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules(); |
|
| 95 | + $eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules); |
|
| 96 | + $eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules); |
|
| 97 | + $ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $this->stub = str_replace('{{store_eager_objects}}', $storeCommands, $this->stub); |
|
| 103 | + $this->stub = str_replace('{{update_eager_objects}}', $updateCommands, $this->stub); |
|
| 104 | + $this->stub = str_replace('{{rules_eager}}', $ruleCommands, $this->stub); |
|
| 105 | + $this->stub = str_replace('{{eager_use_classes}}', $useCommands, $this->stub); |
|
| 106 | + $this->stub = str_replace('{{eager_joins}}', $eagerJoins, $this->stub); |
|
| 107 | + $this->stub = str_replace('{{eager_conditions}}', $eagerConditions, $this->stub); |
|
| 108 | + $this->stub = str_replace('{{eager_table}}', $this->eagerTable, $this->stub); |
|
| 109 | 109 | |
| 110 | 110 | |
| 111 | 111 | |
| 112 | - return $this; |
|
| 113 | - } |
|
| 112 | + return $this; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | 115 | |
| 116 | - public function replaceSortConditions() { |
|
| 117 | - $joinSorts = ''; |
|
| 116 | + public function replaceSortConditions() { |
|
| 117 | + $joinSorts = ''; |
|
| 118 | 118 | |
| 119 | - foreach ($this->modelData->fields as $field) { |
|
| 120 | - if($field->foreignKey){ |
|
| 121 | - $joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php'); |
|
| 122 | - $joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub); |
|
| 123 | - $joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub); |
|
| 124 | - $joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub); |
|
| 125 | - $joinSorts .= $joinSortStub; |
|
| 119 | + foreach ($this->modelData->fields as $field) { |
|
| 120 | + if($field->foreignKey){ |
|
| 121 | + $joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php'); |
|
| 122 | + $joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub); |
|
| 123 | + $joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub); |
|
| 124 | + $joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub); |
|
| 125 | + $joinSorts .= $joinSortStub; |
|
| 126 | 126 | |
| 127 | - } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | |
| 130 | 130 | |
| 131 | - } |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | 133 | |
| 134 | - $this->stub = str_replace('{{relationship_tables_joins_sort}}', $joinSorts, $this->stub); |
|
| 134 | + $this->stub = str_replace('{{relationship_tables_joins_sort}}', $joinSorts, $this->stub); |
|
| 135 | 135 | |
| 136 | - return $this; |
|
| 137 | - } |
|
| 136 | + return $this; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - public function replaceUniqueRules() { |
|
| 140 | - $uniqueRules = ''; |
|
| 139 | + public function replaceUniqueRules() { |
|
| 140 | + $uniqueRules = ''; |
|
| 141 | 141 | |
| 142 | - foreach ($this->modelData->fields as $field) { |
|
| 143 | - if (strpos($field->validations, 'unique')) { |
|
| 144 | - $rule = sprintf('$rules["%s"] = $rules["%s"] . \',%s,\' . $id;', $field->name, $field->name, $field->name); |
|
| 145 | - $uniqueRules .= $rule . "\n"; |
|
| 146 | - } |
|
| 147 | - } |
|
| 142 | + foreach ($this->modelData->fields as $field) { |
|
| 143 | + if (strpos($field->validations, 'unique')) { |
|
| 144 | + $rule = sprintf('$rules["%s"] = $rules["%s"] . \',%s,\' . $id;', $field->name, $field->name, $field->name); |
|
| 145 | + $uniqueRules .= $rule . "\n"; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - $this->stub = str_replace('{{unique_rules}}', $uniqueRules, $this->stub); |
|
| 149 | + $this->stub = str_replace('{{unique_rules}}', $uniqueRules, $this->stub); |
|
| 150 | 150 | |
| 151 | - return $this; |
|
| 152 | - } |
|
| 151 | + return $this; |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - public function getEagerUniqueRules() { |
|
| 155 | - $uniqueRules = ''; |
|
| 154 | + public function getEagerUniqueRules() { |
|
| 155 | + $uniqueRules = ''; |
|
| 156 | 156 | |
| 157 | - foreach ($this->modelData->fields as $field) { |
|
| 158 | - if (strpos($field->validations, 'unique')) { |
|
| 159 | - $rule = sprintf('$rules["%s.%s"] .= \',%s,\' . ${{class_name_lw}}->{{field}};', $this->modelData->tableName, $field->name, $field->name); |
|
| 160 | - $uniqueRules .= $rule . "\n"; |
|
| 161 | - } |
|
| 162 | - } |
|
| 157 | + foreach ($this->modelData->fields as $field) { |
|
| 158 | + if (strpos($field->validations, 'unique')) { |
|
| 159 | + $rule = sprintf('$rules["%s.%s"] .= \',%s,\' . ${{class_name_lw}}->{{field}};', $this->modelData->tableName, $field->name, $field->name); |
|
| 160 | + $uniqueRules .= $rule . "\n"; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - return $uniqueRules; |
|
| 165 | - } |
|
| 164 | + return $uniqueRules; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Replace search conditions |
|
| 169 | - * |
|
| 170 | - * @return $this |
|
| 171 | - */ |
|
| 172 | - private function replaceSearchConditions(){ |
|
| 167 | + /** |
|
| 168 | + * Replace search conditions |
|
| 169 | + * |
|
| 170 | + * @return $this |
|
| 171 | + */ |
|
| 172 | + private function replaceSearchConditions(){ |
|
| 173 | 173 | |
| 174 | - $searchConditions = $this->getSearchConditions(); |
|
| 174 | + $searchConditions = $this->getSearchConditions(); |
|
| 175 | 175 | |
| 176 | - $this->stub = str_replace('{{conditions}}', $searchConditions, $this->stub); |
|
| 176 | + $this->stub = str_replace('{{conditions}}', $searchConditions, $this->stub); |
|
| 177 | 177 | |
| 178 | - return $this; |
|
| 179 | - } |
|
| 178 | + return $this; |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * get search conditions |
|
| 183 | - * |
|
| 184 | - * @return $this |
|
| 185 | - */ |
|
| 186 | - public function getSearchConditions(){ |
|
| 181 | + /** |
|
| 182 | + * get search conditions |
|
| 183 | + * |
|
| 184 | + * @return $this |
|
| 185 | + */ |
|
| 186 | + public function getSearchConditions(){ |
|
| 187 | 187 | |
| 188 | - $fieldConditions = ''; |
|
| 188 | + $fieldConditions = ''; |
|
| 189 | 189 | |
| 190 | - $searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php'); |
|
| 190 | + $searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php'); |
|
| 191 | 191 | |
| 192 | - foreach ($this->modelData->fields as $field) |
|
| 193 | - { |
|
| 192 | + foreach ($this->modelData->fields as $field) |
|
| 193 | + { |
|
| 194 | 194 | |
| 195 | - $fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ; |
|
| 195 | + $fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ; |
|
| 196 | 196 | |
| 197 | - } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - // replace all field conditions |
|
| 200 | - $searchConditions = str_replace('{{field_conditions}}', $fieldConditions, $searchConditions); |
|
| 199 | + // replace all field conditions |
|
| 200 | + $searchConditions = str_replace('{{field_conditions}}', $fieldConditions, $searchConditions); |
|
| 201 | 201 | |
| 202 | - // replace table name |
|
| 203 | - $searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions); |
|
| 202 | + // replace table name |
|
| 203 | + $searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions); |
|
| 204 | 204 | |
| 205 | - return $searchConditions ; |
|
| 205 | + return $searchConditions ; |
|
| 206 | 206 | |
| 207 | - } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * Replace simple filter |
|
| 212 | - * |
|
| 213 | - * @return $this |
|
| 214 | - */ |
|
| 215 | - private function replaceSimpleFilter(){ |
|
| 216 | - $i = 0; |
|
| 210 | + /** |
|
| 211 | + * Replace simple filter |
|
| 212 | + * |
|
| 213 | + * @return $this |
|
| 214 | + */ |
|
| 215 | + private function replaceSimpleFilter(){ |
|
| 216 | + $i = 0; |
|
| 217 | 217 | |
| 218 | - $stubSimpleFilter = ''; |
|
| 218 | + $stubSimpleFilter = ''; |
|
| 219 | 219 | |
| 220 | - foreach ($this->modelData->fields as $field) |
|
| 221 | - { |
|
| 222 | - //var_dump($field->name); |
|
| 220 | + foreach ($this->modelData->fields as $field) |
|
| 221 | + { |
|
| 222 | + //var_dump($field->name); |
|
| 223 | 223 | |
| 224 | - if($field->index == 'primary'){ |
|
| 225 | - $dbType = 'primaryKey' ; |
|
| 226 | - } |
|
| 227 | - elseif($field->foreignKey){ |
|
| 228 | - $dbType = 'primary' ; |
|
| 229 | - } |
|
| 230 | - elseif($field->type->db == 'enum'){ |
|
| 231 | - $dbType = 'primary' ; |
|
| 232 | - } |
|
| 233 | - elseif($field->type->db == 'boolean'){ |
|
| 234 | - $dbType = 'primary' ; |
|
| 235 | - } |
|
| 236 | - elseif($field->type->db == 'text'){ |
|
| 237 | - $dbType = 'string' ; |
|
| 238 | - } |
|
| 239 | - else { |
|
| 240 | - $dbType = $field->type->db ; |
|
| 241 | - } |
|
| 224 | + if($field->index == 'primary'){ |
|
| 225 | + $dbType = 'primaryKey' ; |
|
| 226 | + } |
|
| 227 | + elseif($field->foreignKey){ |
|
| 228 | + $dbType = 'primary' ; |
|
| 229 | + } |
|
| 230 | + elseif($field->type->db == 'enum'){ |
|
| 231 | + $dbType = 'primary' ; |
|
| 232 | + } |
|
| 233 | + elseif($field->type->db == 'boolean'){ |
|
| 234 | + $dbType = 'primary' ; |
|
| 235 | + } |
|
| 236 | + elseif($field->type->db == 'text'){ |
|
| 237 | + $dbType = 'string' ; |
|
| 238 | + } |
|
| 239 | + else { |
|
| 240 | + $dbType = $field->type->db ; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - if($dbType == 'primaryKey') |
|
| 244 | - { |
|
| 245 | - $stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - if($dbType == 'primary') |
|
| 249 | - { |
|
| 250 | - $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - if($dbType == 'string') |
|
| 254 | - { |
|
| 255 | - $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number') |
|
| 259 | - { |
|
| 260 | - $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - } |
|
| 264 | - $stubSimpleFilter .= ';'; |
|
| 265 | - $this->stub = str_replace('{{simple_filter}}', $stubSimpleFilter, $this->stub); |
|
| 266 | - |
|
| 267 | - return $this; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * replace reverse relationships |
|
| 273 | - * |
|
| 274 | - * @return $this |
|
| 275 | - */ |
|
| 276 | - public function replaceReverseRelationships(){ |
|
| 277 | - |
|
| 278 | - $functions = ''; |
|
| 279 | - |
|
| 280 | - $method = File::get($this->stubsDirectory . '/Controller/ControllerReverseRelationship.php'); |
|
| 281 | - |
|
| 282 | - foreach ($this->modelData->reverseRelationships as $relationship) |
|
| 283 | - { |
|
| 284 | - $functionName = ''; |
|
| 285 | - if ($relationship->type == "hasOne") |
|
| 286 | - $functionName = strtolower($relationship->modelName); |
|
| 287 | - elseif ($relationship->type == "belongsToMany") |
|
| 288 | - $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); |
|
| 289 | - else |
|
| 290 | - $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 291 | - |
|
| 292 | - $replacedMethod = ''; |
|
| 293 | - $replacedMethod = str_replace('{{function_name}}', $functionName, $method); |
|
| 294 | - $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod); |
|
| 295 | - $replacedMethod = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $replacedMethod); |
|
| 296 | - |
|
| 297 | - $functions .= $replacedMethod; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - $this->stub = str_replace('{{reverseRelationships}}', $functions, $this->stub); |
|
| 301 | - |
|
| 302 | - return $this; |
|
| 303 | - |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * replace enum fields |
|
| 308 | - * |
|
| 309 | - * @return $this |
|
| 310 | - */ |
|
| 311 | - public function replaceEnum(){ |
|
| 312 | - |
|
| 313 | - $functions = ''; |
|
| 314 | - |
|
| 315 | - $method = File::get($this->stubsDirectory . '/Controller/ControllerEnum.php'); |
|
| 316 | - |
|
| 317 | - foreach ($this->modelData->fields as $field) |
|
| 318 | - { |
|
| 319 | - if ($field->type->db == "enum") { |
|
| 320 | - $replacedMethod = ''; |
|
| 321 | - $replacedMethod = str_replace('{{field_name_uc}}', CamelCase::convertToCamelCase($field->name), $method); |
|
| 322 | - $replacedMethod = str_replace('{{field_name}}', $field->name, $replacedMethod); |
|
| 323 | - $replacedMethod = str_replace('{{model_name}}', $this->modelData->modelName, $replacedMethod); |
|
| 243 | + if($dbType == 'primaryKey') |
|
| 244 | + { |
|
| 245 | + $stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + if($dbType == 'primary') |
|
| 249 | + { |
|
| 250 | + $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + if($dbType == 'string') |
|
| 254 | + { |
|
| 255 | + $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number') |
|
| 259 | + { |
|
| 260 | + $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + } |
|
| 264 | + $stubSimpleFilter .= ';'; |
|
| 265 | + $this->stub = str_replace('{{simple_filter}}', $stubSimpleFilter, $this->stub); |
|
| 266 | + |
|
| 267 | + return $this; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * replace reverse relationships |
|
| 273 | + * |
|
| 274 | + * @return $this |
|
| 275 | + */ |
|
| 276 | + public function replaceReverseRelationships(){ |
|
| 277 | + |
|
| 278 | + $functions = ''; |
|
| 279 | + |
|
| 280 | + $method = File::get($this->stubsDirectory . '/Controller/ControllerReverseRelationship.php'); |
|
| 281 | + |
|
| 282 | + foreach ($this->modelData->reverseRelationships as $relationship) |
|
| 283 | + { |
|
| 284 | + $functionName = ''; |
|
| 285 | + if ($relationship->type == "hasOne") |
|
| 286 | + $functionName = strtolower($relationship->modelName); |
|
| 287 | + elseif ($relationship->type == "belongsToMany") |
|
| 288 | + $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); |
|
| 289 | + else |
|
| 290 | + $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 291 | + |
|
| 292 | + $replacedMethod = ''; |
|
| 293 | + $replacedMethod = str_replace('{{function_name}}', $functionName, $method); |
|
| 294 | + $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod); |
|
| 295 | + $replacedMethod = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $replacedMethod); |
|
| 296 | + |
|
| 297 | + $functions .= $replacedMethod; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + $this->stub = str_replace('{{reverseRelationships}}', $functions, $this->stub); |
|
| 301 | + |
|
| 302 | + return $this; |
|
| 303 | + |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * replace enum fields |
|
| 308 | + * |
|
| 309 | + * @return $this |
|
| 310 | + */ |
|
| 311 | + public function replaceEnum(){ |
|
| 312 | + |
|
| 313 | + $functions = ''; |
|
| 314 | + |
|
| 315 | + $method = File::get($this->stubsDirectory . '/Controller/ControllerEnum.php'); |
|
| 316 | + |
|
| 317 | + foreach ($this->modelData->fields as $field) |
|
| 318 | + { |
|
| 319 | + if ($field->type->db == "enum") { |
|
| 320 | + $replacedMethod = ''; |
|
| 321 | + $replacedMethod = str_replace('{{field_name_uc}}', CamelCase::convertToCamelCase($field->name), $method); |
|
| 322 | + $replacedMethod = str_replace('{{field_name}}', $field->name, $replacedMethod); |
|
| 323 | + $replacedMethod = str_replace('{{model_name}}', $this->modelData->modelName, $replacedMethod); |
|
| 324 | 324 | |
| 325 | - $functions .= $replacedMethod; |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - $this->stub = str_replace('{{enum}}', $functions, $this->stub); |
|
| 330 | - |
|
| 331 | - return $this; |
|
| 332 | - |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * replace relationship tables |
|
| 337 | - * |
|
| 338 | - * @return $this |
|
| 339 | - */ |
|
| 340 | - public function replaceRelationshipTables() { |
|
| 341 | - |
|
| 342 | - $functions = ""; |
|
| 343 | - $functionsCall = ""; |
|
| 344 | - $removeAll = ""; |
|
| 345 | - $removeAllCall = ""; |
|
| 346 | - $includes = ""; |
|
| 347 | - $joins = ""; |
|
| 348 | - $joinSorts = ""; |
|
| 349 | - |
|
| 350 | - $method = File::get($this->stubsDirectory . '/Controller/ControllerRelationshipTable.php'); |
|
| 351 | - |
|
| 352 | - foreach ($this->modelData->reverseRelationships as $relationship) { |
|
| 353 | - |
|
| 354 | - if ($relationship->type == "belongsToMany") { |
|
| 355 | - $relatedTablePluralized = CamelCase::pluralize($relationship->relatedTable); |
|
| 356 | - $relatedTablePluralizedUc = CamelCase::pluralize(CamelCase::convertToCamelCase($relationship->relatedTable)); |
|
| 357 | - |
|
| 358 | - $replacedMethod = ''; |
|
| 359 | - $replacedMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $method); |
|
| 360 | - $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod); |
|
| 361 | - $replacedMethod = str_replace('{{related_table_pl}}', $relatedTablePluralized, $replacedMethod); |
|
| 362 | - $replacedMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $replacedMethod); |
|
| 363 | - $replacedMethod = str_replace('{{related_field}}', $relationship->relatedField, $replacedMethod); |
|
| 364 | - $replacedMethod = str_replace('{{foreign_table_lw}}', strtolower($relationship->modelName), $replacedMethod); |
|
| 365 | - $replacedMethod = str_replace('{{foreign_table}}', $relationship->modelName, $replacedMethod); |
|
| 366 | - |
|
| 367 | - $functions .= $replacedMethod; |
|
| 368 | - |
|
| 369 | - $methodCall = 'if (array_key_exists(\'{{related_table_pl}}\', $vars))'; |
|
| 370 | - $methodCall .= "\n\t\t\t"; |
|
| 371 | - $methodCall .= '$this->save{{related_table_pl_uc}}($vars, ${{class_name_lw}});'; |
|
| 372 | - $methodCall = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $methodCall); |
|
| 373 | - $methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall); |
|
| 374 | - $methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall); |
|
| 375 | - |
|
| 376 | - $functionsCall .= $methodCall . "\n\t\t"; |
|
| 325 | + $functions .= $replacedMethod; |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + $this->stub = str_replace('{{enum}}', $functions, $this->stub); |
|
| 330 | + |
|
| 331 | + return $this; |
|
| 332 | + |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * replace relationship tables |
|
| 337 | + * |
|
| 338 | + * @return $this |
|
| 339 | + */ |
|
| 340 | + public function replaceRelationshipTables() { |
|
| 341 | + |
|
| 342 | + $functions = ""; |
|
| 343 | + $functionsCall = ""; |
|
| 344 | + $removeAll = ""; |
|
| 345 | + $removeAllCall = ""; |
|
| 346 | + $includes = ""; |
|
| 347 | + $joins = ""; |
|
| 348 | + $joinSorts = ""; |
|
| 349 | + |
|
| 350 | + $method = File::get($this->stubsDirectory . '/Controller/ControllerRelationshipTable.php'); |
|
| 351 | + |
|
| 352 | + foreach ($this->modelData->reverseRelationships as $relationship) { |
|
| 353 | + |
|
| 354 | + if ($relationship->type == "belongsToMany") { |
|
| 355 | + $relatedTablePluralized = CamelCase::pluralize($relationship->relatedTable); |
|
| 356 | + $relatedTablePluralizedUc = CamelCase::pluralize(CamelCase::convertToCamelCase($relationship->relatedTable)); |
|
| 357 | + |
|
| 358 | + $replacedMethod = ''; |
|
| 359 | + $replacedMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $method); |
|
| 360 | + $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod); |
|
| 361 | + $replacedMethod = str_replace('{{related_table_pl}}', $relatedTablePluralized, $replacedMethod); |
|
| 362 | + $replacedMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $replacedMethod); |
|
| 363 | + $replacedMethod = str_replace('{{related_field}}', $relationship->relatedField, $replacedMethod); |
|
| 364 | + $replacedMethod = str_replace('{{foreign_table_lw}}', strtolower($relationship->modelName), $replacedMethod); |
|
| 365 | + $replacedMethod = str_replace('{{foreign_table}}', $relationship->modelName, $replacedMethod); |
|
| 366 | + |
|
| 367 | + $functions .= $replacedMethod; |
|
| 368 | + |
|
| 369 | + $methodCall = 'if (array_key_exists(\'{{related_table_pl}}\', $vars))'; |
|
| 370 | + $methodCall .= "\n\t\t\t"; |
|
| 371 | + $methodCall .= '$this->save{{related_table_pl_uc}}($vars, ${{class_name_lw}});'; |
|
| 372 | + $methodCall = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $methodCall); |
|
| 373 | + $methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall); |
|
| 374 | + $methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall); |
|
| 375 | + |
|
| 376 | + $functionsCall .= $methodCall . "\n\t\t"; |
|
| 377 | 377 | |
| 378 | - $removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php'); |
|
| 379 | - $removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod); |
|
| 380 | - $removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod); |
|
| 381 | - $removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod); |
|
| 382 | - $removeAllMethod = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $removeAllMethod); |
|
| 378 | + $removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php'); |
|
| 379 | + $removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod); |
|
| 380 | + $removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod); |
|
| 381 | + $removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod); |
|
| 382 | + $removeAllMethod = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $removeAllMethod); |
|
| 383 | 383 | |
| 384 | - $removeAll .= $removeAllMethod; |
|
| 384 | + $removeAll .= $removeAllMethod; |
|
| 385 | 385 | |
| 386 | - $removeAllCallMethod = '$this->deleteAll{{related_table_pl_uc}}(${{class_name_lw}}[\'id\']);'; |
|
| 387 | - $removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod); |
|
| 388 | - $removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod); |
|
| 386 | + $removeAllCallMethod = '$this->deleteAll{{related_table_pl_uc}}(${{class_name_lw}}[\'id\']);'; |
|
| 387 | + $removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod); |
|
| 388 | + $removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod); |
|
| 389 | 389 | |
| 390 | - $removeAllCall .= $removeAllCallMethod . "\n\t\t"; |
|
| 390 | + $removeAllCall .= $removeAllCallMethod . "\n\t\t"; |
|
| 391 | 391 | |
| 392 | - $joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php'); |
|
| 393 | - $joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub); |
|
| 394 | - $joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub); |
|
| 395 | - $joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub); |
|
| 396 | - $joinRelationshipTableStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $joinRelationshipTableStub); |
|
| 397 | - $joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub); |
|
| 398 | - $joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub); |
|
| 392 | + $joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php'); |
|
| 393 | + $joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub); |
|
| 394 | + $joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub); |
|
| 395 | + $joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub); |
|
| 396 | + $joinRelationshipTableStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $joinRelationshipTableStub); |
|
| 397 | + $joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub); |
|
| 398 | + $joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub); |
|
| 399 | 399 | |
| 400 | - $joins .= $joinRelationshipTableStub . "\n"; |
|
| 400 | + $joins .= $joinRelationshipTableStub . "\n"; |
|
| 401 | 401 | |
| 402 | - $use = 'use App\Models\{{foreign_table}};'; |
|
| 403 | - $use = str_replace('{{foreign_table}}', $relationship->modelName, $use); |
|
| 402 | + $use = 'use App\Models\{{foreign_table}};'; |
|
| 403 | + $use = str_replace('{{foreign_table}}', $relationship->modelName, $use); |
|
| 404 | 404 | |
| 405 | - $includes .= $use . "\n"; |
|
| 406 | - } |
|
| 407 | - } |
|
| 405 | + $includes .= $use . "\n"; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | - $this->stub = str_replace('{{relationship_tables_store}}', $functions, $this->stub); |
|
| 409 | + $this->stub = str_replace('{{relationship_tables_store}}', $functions, $this->stub); |
|
| 410 | 410 | |
| 411 | - $this->stub = str_replace('{{relationship_tables_call}}', $functionsCall, $this->stub); |
|
| 411 | + $this->stub = str_replace('{{relationship_tables_call}}', $functionsCall, $this->stub); |
|
| 412 | 412 | |
| 413 | - $this->stub = str_replace('{{remove_relationship_objects}}', $removeAll, $this->stub); |
|
| 413 | + $this->stub = str_replace('{{remove_relationship_objects}}', $removeAll, $this->stub); |
|
| 414 | 414 | |
| 415 | - $this->stub = str_replace('{{remove_relationship_objects_call}}', $removeAllCall, $this->stub); |
|
| 415 | + $this->stub = str_replace('{{remove_relationship_objects_call}}', $removeAllCall, $this->stub); |
|
| 416 | 416 | |
| 417 | - $this->stub = str_replace('{{relationship_tables_classes}}', $includes, $this->stub); |
|
| 417 | + $this->stub = str_replace('{{relationship_tables_classes}}', $includes, $this->stub); |
|
| 418 | 418 | |
| 419 | - $this->stub = str_replace('{{relationship_tables_joins}}', $joins, $this->stub); |
|
| 419 | + $this->stub = str_replace('{{relationship_tables_joins}}', $joins, $this->stub); |
|
| 420 | 420 | |
| 421 | 421 | |
| 422 | 422 | |
| 423 | - return $this; |
|
| 423 | + return $this; |
|
| 424 | 424 | |
| 425 | - } |
|
| 425 | + } |
|
| 426 | 426 | |
| 427 | 427 | |
| 428 | - /** |
|
| 429 | - * replace checkbox fields |
|
| 430 | - * |
|
| 431 | - * @return $this |
|
| 432 | - */ |
|
| 433 | - public function replaceCheckbox(){ |
|
| 428 | + /** |
|
| 429 | + * replace checkbox fields |
|
| 430 | + * |
|
| 431 | + * @return $this |
|
| 432 | + */ |
|
| 433 | + public function replaceCheckbox(){ |
|
| 434 | 434 | |
| 435 | - $method = File::get($this->stubsDirectory . '/Controller/ControllerCheckbox.php'); |
|
| 436 | - $key = false; |
|
| 435 | + $method = File::get($this->stubsDirectory . '/Controller/ControllerCheckbox.php'); |
|
| 436 | + $key = false; |
|
| 437 | 437 | |
| 438 | - $method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method); |
|
| 439 | - $method = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $method); |
|
| 440 | - $method = str_replace('{{model_name}}', $this->modelData->modelName, $method); |
|
| 441 | - $this->stub = str_replace('{{checkbox}}', $method, $this->stub); |
|
| 438 | + $method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method); |
|
| 439 | + $method = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $method); |
|
| 440 | + $method = str_replace('{{model_name}}', $this->modelData->modelName, $method); |
|
| 441 | + $this->stub = str_replace('{{checkbox}}', $method, $this->stub); |
|
| 442 | 442 | |
| 443 | - /*foreach ($this->modelData->fields as $field) |
|
| 443 | + /*foreach ($this->modelData->fields as $field) |
|
| 444 | 444 | { |
| 445 | 445 | if ($field->type->ui == "checkbox") { |
| 446 | 446 | |
@@ -461,49 +461,49 @@ discard block |
||
| 461 | 461 | }*/ |
| 462 | 462 | |
| 463 | 463 | |
| 464 | - return $this; |
|
| 464 | + return $this; |
|
| 465 | 465 | |
| 466 | - } |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | 468 | |
| 469 | - /** |
|
| 470 | - * get search conditions stub by db type |
|
| 471 | - * |
|
| 472 | - * @param string $field |
|
| 473 | - * |
|
| 474 | - * @return $this |
|
| 475 | - */ |
|
| 476 | - private $conditionsStub = []; |
|
| 477 | - private function getConditionStubByField($field){ |
|
| 469 | + /** |
|
| 470 | + * get search conditions stub by db type |
|
| 471 | + * |
|
| 472 | + * @param string $field |
|
| 473 | + * |
|
| 474 | + * @return $this |
|
| 475 | + */ |
|
| 476 | + private $conditionsStub = []; |
|
| 477 | + private function getConditionStubByField($field){ |
|
| 478 | 478 | |
| 479 | - if($field->index == 'primary'){ |
|
| 480 | - $dbType = 'primary' ; |
|
| 481 | - } |
|
| 482 | - elseif($field->foreignKey){ |
|
| 483 | - $dbType = 'primary' ; |
|
| 484 | - } |
|
| 485 | - elseif($field->type->db == 'enum'){ |
|
| 486 | - $dbType = 'primary' ; |
|
| 487 | - } |
|
| 488 | - elseif($field->type->db == 'boolean'){ |
|
| 489 | - $dbType = 'primary' ; |
|
| 490 | - } |
|
| 491 | - elseif($field->type->db == 'text'){ |
|
| 492 | - $dbType = 'string' ; |
|
| 493 | - } |
|
| 494 | - else { |
|
| 495 | - $dbType = $field->type->db ; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - if(array_key_exists($dbType, $this->conditionsStub)){ |
|
| 499 | - return $this->conditionsStub[$dbType]; |
|
| 500 | - } |
|
| 501 | - else { |
|
| 502 | - $this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');; |
|
| 503 | - |
|
| 504 | - return $this->conditionsStub[$dbType]; |
|
| 505 | - } |
|
| 506 | - } |
|
| 479 | + if($field->index == 'primary'){ |
|
| 480 | + $dbType = 'primary' ; |
|
| 481 | + } |
|
| 482 | + elseif($field->foreignKey){ |
|
| 483 | + $dbType = 'primary' ; |
|
| 484 | + } |
|
| 485 | + elseif($field->type->db == 'enum'){ |
|
| 486 | + $dbType = 'primary' ; |
|
| 487 | + } |
|
| 488 | + elseif($field->type->db == 'boolean'){ |
|
| 489 | + $dbType = 'primary' ; |
|
| 490 | + } |
|
| 491 | + elseif($field->type->db == 'text'){ |
|
| 492 | + $dbType = 'string' ; |
|
| 493 | + } |
|
| 494 | + else { |
|
| 495 | + $dbType = $field->type->db ; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + if(array_key_exists($dbType, $this->conditionsStub)){ |
|
| 499 | + return $this->conditionsStub[$dbType]; |
|
| 500 | + } |
|
| 501 | + else { |
|
| 502 | + $this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');; |
|
| 503 | + |
|
| 504 | + return $this->conditionsStub[$dbType]; |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | 507 | |
| 508 | 508 | |
| 509 | 509 | |
@@ -11,13 +11,13 @@ discard block |
||
| 11 | 11 | class ControllerCompiler extends AbstractCompiler |
| 12 | 12 | { |
| 13 | 13 | protected $cachePrefix = 'controller_'; |
| 14 | - protected $stubFilename = 'Controller/Controller.php' ; |
|
| 14 | + protected $stubFilename = 'Controller/Controller.php'; |
|
| 15 | 15 | |
| 16 | 16 | public function __construct($scaffolderConfig, $modelData = null, $stubName = null) |
| 17 | 17 | { |
| 18 | 18 | if ($stubName) |
| 19 | 19 | $this->stubFilename = $stubName; |
| 20 | - $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
|
| 20 | + $this->stubsDirectory = __DIR__.'/../../../../stubs/Api/'; |
|
| 21 | 21 | parent::__construct($scaffolderConfig, $modelData); |
| 22 | 22 | } |
| 23 | 23 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | protected function getOutputFilename() |
| 55 | 55 | { |
| 56 | 56 | |
| 57 | - return PathParser::parse($this->scaffolderConfig->generator->paths->controllers) . $this->modelName . 'Controller.php'; |
|
| 57 | + return PathParser::parse($this->scaffolderConfig->generator->paths->controllers).$this->modelName.'Controller.php'; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -67,11 +67,11 @@ discard block |
||
| 67 | 67 | $storeCommands = $updateCommands = $ruleCommands = $useCommands = ''; |
| 68 | 68 | $eagerConditions = $eagerJoins = ''; |
| 69 | 69 | |
| 70 | - $storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php'); |
|
| 71 | - $updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php'); |
|
| 72 | - $rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php'); |
|
| 73 | - $useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php'); |
|
| 74 | - $joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php'); |
|
| 70 | + $storeEagerStubOriginal = File::get($this->stubsDirectory.'StoreEager.php'); |
|
| 71 | + $updateEagerStubOriginal = File::get($this->stubsDirectory.'UpdateEager.php'); |
|
| 72 | + $rulesEagerStubOriginal = File::get($this->stubsDirectory.'RulesEager.php'); |
|
| 73 | + $useEagerStubOriginal = File::get($this->stubsDirectory.'UseEager.php'); |
|
| 74 | + $joinEagerStubOriginal = File::get($this->stubsDirectory.'SearchConditions/JoinEager.php'); |
|
| 75 | 75 | |
| 76 | 76 | foreach ($this->modelData->fields as $field) |
| 77 | 77 | { |
@@ -81,20 +81,20 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | |
| 83 | 83 | $storeCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal)); |
| 84 | - $updateCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ; |
|
| 85 | - $ruleCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ; |
|
| 86 | - $useCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ; |
|
| 87 | - $eagerJoins .= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ; |
|
| 84 | + $updateCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)); |
|
| 85 | + $ruleCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)); |
|
| 86 | + $useCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)); |
|
| 87 | + $eagerJoins .= $this->replaceForeingStrings($field, $joinEagerStubOriginal); |
|
| 88 | 88 | |
| 89 | 89 | // search eager fields |
| 90 | 90 | $foreignModelData = $this->getModelData($field->foreignKey->table); |
| 91 | 91 | $foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData); |
| 92 | 92 | $foreignControllerCompiler->setEagerTable($this->modelData->tableName); |
| 93 | - $eagerConditions .= $foreignControllerCompiler->getSearchConditions(); |
|
| 93 | + $eagerConditions .= $foreignControllerCompiler->getSearchConditions(); |
|
| 94 | 94 | $eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules(); |
| 95 | 95 | $eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules); |
| 96 | 96 | $eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules); |
| 97 | - $ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ; |
|
| 97 | + $ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | } |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | |
| 116 | - public function replaceSortConditions() { |
|
| 116 | + public function replaceSortConditions() { |
|
| 117 | 117 | $joinSorts = ''; |
| 118 | 118 | |
| 119 | 119 | foreach ($this->modelData->fields as $field) { |
| 120 | - if($field->foreignKey){ |
|
| 121 | - $joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php'); |
|
| 120 | + if ($field->foreignKey) { |
|
| 121 | + $joinSortStub = File::get($this->stubsDirectory.'SearchConditions/JoinSort.php'); |
|
| 122 | 122 | $joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub); |
| 123 | 123 | $joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub); |
| 124 | 124 | $joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub); |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | foreach ($this->modelData->fields as $field) { |
| 143 | 143 | if (strpos($field->validations, 'unique')) { |
| 144 | 144 | $rule = sprintf('$rules["%s"] = $rules["%s"] . \',%s,\' . $id;', $field->name, $field->name, $field->name); |
| 145 | - $uniqueRules .= $rule . "\n"; |
|
| 145 | + $uniqueRules .= $rule."\n"; |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | foreach ($this->modelData->fields as $field) { |
| 158 | 158 | if (strpos($field->validations, 'unique')) { |
| 159 | 159 | $rule = sprintf('$rules["%s.%s"] .= \',%s,\' . ${{class_name_lw}}->{{field}};', $this->modelData->tableName, $field->name, $field->name); |
| 160 | - $uniqueRules .= $rule . "\n"; |
|
| 160 | + $uniqueRules .= $rule."\n"; |
|
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * |
| 170 | 170 | * @return $this |
| 171 | 171 | */ |
| 172 | - private function replaceSearchConditions(){ |
|
| 172 | + private function replaceSearchConditions() { |
|
| 173 | 173 | |
| 174 | 174 | $searchConditions = $this->getSearchConditions(); |
| 175 | 175 | |
@@ -183,16 +183,16 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @return $this |
| 185 | 185 | */ |
| 186 | - public function getSearchConditions(){ |
|
| 186 | + public function getSearchConditions() { |
|
| 187 | 187 | |
| 188 | 188 | $fieldConditions = ''; |
| 189 | 189 | |
| 190 | - $searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php'); |
|
| 190 | + $searchConditions = File::get($this->stubsDirectory.'/SearchConditions/Conditions.php'); |
|
| 191 | 191 | |
| 192 | 192 | foreach ($this->modelData->fields as $field) |
| 193 | 193 | { |
| 194 | 194 | |
| 195 | - $fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ; |
|
| 195 | + $fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)); |
|
| 196 | 196 | |
| 197 | 197 | } |
| 198 | 198 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | // replace table name |
| 203 | 203 | $searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions); |
| 204 | 204 | |
| 205 | - return $searchConditions ; |
|
| 205 | + return $searchConditions; |
|
| 206 | 206 | |
| 207 | 207 | } |
| 208 | 208 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * |
| 213 | 213 | * @return $this |
| 214 | 214 | */ |
| 215 | - private function replaceSimpleFilter(){ |
|
| 215 | + private function replaceSimpleFilter() { |
|
| 216 | 216 | $i = 0; |
| 217 | 217 | |
| 218 | 218 | $stubSimpleFilter = ''; |
@@ -221,41 +221,41 @@ discard block |
||
| 221 | 221 | { |
| 222 | 222 | //var_dump($field->name); |
| 223 | 223 | |
| 224 | - if($field->index == 'primary'){ |
|
| 225 | - $dbType = 'primaryKey' ; |
|
| 224 | + if ($field->index == 'primary') { |
|
| 225 | + $dbType = 'primaryKey'; |
|
| 226 | 226 | } |
| 227 | - elseif($field->foreignKey){ |
|
| 228 | - $dbType = 'primary' ; |
|
| 227 | + elseif ($field->foreignKey) { |
|
| 228 | + $dbType = 'primary'; |
|
| 229 | 229 | } |
| 230 | - elseif($field->type->db == 'enum'){ |
|
| 231 | - $dbType = 'primary' ; |
|
| 230 | + elseif ($field->type->db == 'enum') { |
|
| 231 | + $dbType = 'primary'; |
|
| 232 | 232 | } |
| 233 | - elseif($field->type->db == 'boolean'){ |
|
| 234 | - $dbType = 'primary' ; |
|
| 233 | + elseif ($field->type->db == 'boolean') { |
|
| 234 | + $dbType = 'primary'; |
|
| 235 | 235 | } |
| 236 | - elseif($field->type->db == 'text'){ |
|
| 237 | - $dbType = 'string' ; |
|
| 236 | + elseif ($field->type->db == 'text') { |
|
| 237 | + $dbType = 'string'; |
|
| 238 | 238 | } |
| 239 | 239 | else { |
| 240 | - $dbType = $field->type->db ; |
|
| 240 | + $dbType = $field->type->db; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if($dbType == 'primaryKey') |
|
| 243 | + if ($dbType == 'primaryKey') |
|
| 244 | 244 | { |
| 245 | 245 | $stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - if($dbType == 'primary') |
|
| 248 | + if ($dbType == 'primary') |
|
| 249 | 249 | { |
| 250 | 250 | $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if($dbType == 'string') |
|
| 253 | + if ($dbType == 'string') |
|
| 254 | 254 | { |
| 255 | 255 | $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number') |
|
| 258 | + if ($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number') |
|
| 259 | 259 | { |
| 260 | 260 | $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
| 261 | 261 | } |
@@ -273,11 +273,11 @@ discard block |
||
| 273 | 273 | * |
| 274 | 274 | * @return $this |
| 275 | 275 | */ |
| 276 | - public function replaceReverseRelationships(){ |
|
| 276 | + public function replaceReverseRelationships() { |
|
| 277 | 277 | |
| 278 | 278 | $functions = ''; |
| 279 | 279 | |
| 280 | - $method = File::get($this->stubsDirectory . '/Controller/ControllerReverseRelationship.php'); |
|
| 280 | + $method = File::get($this->stubsDirectory.'/Controller/ControllerReverseRelationship.php'); |
|
| 281 | 281 | |
| 282 | 282 | foreach ($this->modelData->reverseRelationships as $relationship) |
| 283 | 283 | { |
@@ -308,11 +308,11 @@ discard block |
||
| 308 | 308 | * |
| 309 | 309 | * @return $this |
| 310 | 310 | */ |
| 311 | - public function replaceEnum(){ |
|
| 311 | + public function replaceEnum() { |
|
| 312 | 312 | |
| 313 | 313 | $functions = ''; |
| 314 | 314 | |
| 315 | - $method = File::get($this->stubsDirectory . '/Controller/ControllerEnum.php'); |
|
| 315 | + $method = File::get($this->stubsDirectory.'/Controller/ControllerEnum.php'); |
|
| 316 | 316 | |
| 317 | 317 | foreach ($this->modelData->fields as $field) |
| 318 | 318 | { |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | $joins = ""; |
| 348 | 348 | $joinSorts = ""; |
| 349 | 349 | |
| 350 | - $method = File::get($this->stubsDirectory . '/Controller/ControllerRelationshipTable.php'); |
|
| 350 | + $method = File::get($this->stubsDirectory.'/Controller/ControllerRelationshipTable.php'); |
|
| 351 | 351 | |
| 352 | 352 | foreach ($this->modelData->reverseRelationships as $relationship) { |
| 353 | 353 | |
@@ -373,9 +373,9 @@ discard block |
||
| 373 | 373 | $methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall); |
| 374 | 374 | $methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall); |
| 375 | 375 | |
| 376 | - $functionsCall .= $methodCall . "\n\t\t"; |
|
| 376 | + $functionsCall .= $methodCall."\n\t\t"; |
|
| 377 | 377 | |
| 378 | - $removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php'); |
|
| 378 | + $removeAllMethod = File::get($this->stubsDirectory.'/Controller/ControllerRemoveAll.php'); |
|
| 379 | 379 | $removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod); |
| 380 | 380 | $removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod); |
| 381 | 381 | $removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod); |
@@ -387,9 +387,9 @@ discard block |
||
| 387 | 387 | $removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod); |
| 388 | 388 | $removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod); |
| 389 | 389 | |
| 390 | - $removeAllCall .= $removeAllCallMethod . "\n\t\t"; |
|
| 390 | + $removeAllCall .= $removeAllCallMethod."\n\t\t"; |
|
| 391 | 391 | |
| 392 | - $joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php'); |
|
| 392 | + $joinRelationshipTableStub = File::get($this->stubsDirectory.'SearchConditions/joinRelationshipTable.php'); |
|
| 393 | 393 | $joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub); |
| 394 | 394 | $joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub); |
| 395 | 395 | $joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub); |
@@ -397,12 +397,12 @@ discard block |
||
| 397 | 397 | $joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub); |
| 398 | 398 | $joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub); |
| 399 | 399 | |
| 400 | - $joins .= $joinRelationshipTableStub . "\n"; |
|
| 400 | + $joins .= $joinRelationshipTableStub."\n"; |
|
| 401 | 401 | |
| 402 | 402 | $use = 'use App\Models\{{foreign_table}};'; |
| 403 | 403 | $use = str_replace('{{foreign_table}}', $relationship->modelName, $use); |
| 404 | 404 | |
| 405 | - $includes .= $use . "\n"; |
|
| 405 | + $includes .= $use."\n"; |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
@@ -430,9 +430,9 @@ discard block |
||
| 430 | 430 | * |
| 431 | 431 | * @return $this |
| 432 | 432 | */ |
| 433 | - public function replaceCheckbox(){ |
|
| 433 | + public function replaceCheckbox() { |
|
| 434 | 434 | |
| 435 | - $method = File::get($this->stubsDirectory . '/Controller/ControllerCheckbox.php'); |
|
| 435 | + $method = File::get($this->stubsDirectory.'/Controller/ControllerCheckbox.php'); |
|
| 436 | 436 | $key = false; |
| 437 | 437 | |
| 438 | 438 | $method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method); |
@@ -474,32 +474,32 @@ discard block |
||
| 474 | 474 | * @return $this |
| 475 | 475 | */ |
| 476 | 476 | private $conditionsStub = []; |
| 477 | - private function getConditionStubByField($field){ |
|
| 477 | + private function getConditionStubByField($field) { |
|
| 478 | 478 | |
| 479 | - if($field->index == 'primary'){ |
|
| 480 | - $dbType = 'primary' ; |
|
| 479 | + if ($field->index == 'primary') { |
|
| 480 | + $dbType = 'primary'; |
|
| 481 | 481 | } |
| 482 | - elseif($field->foreignKey){ |
|
| 483 | - $dbType = 'primary' ; |
|
| 482 | + elseif ($field->foreignKey) { |
|
| 483 | + $dbType = 'primary'; |
|
| 484 | 484 | } |
| 485 | - elseif($field->type->db == 'enum'){ |
|
| 486 | - $dbType = 'primary' ; |
|
| 485 | + elseif ($field->type->db == 'enum') { |
|
| 486 | + $dbType = 'primary'; |
|
| 487 | 487 | } |
| 488 | - elseif($field->type->db == 'boolean'){ |
|
| 489 | - $dbType = 'primary' ; |
|
| 488 | + elseif ($field->type->db == 'boolean') { |
|
| 489 | + $dbType = 'primary'; |
|
| 490 | 490 | } |
| 491 | - elseif($field->type->db == 'text'){ |
|
| 492 | - $dbType = 'string' ; |
|
| 491 | + elseif ($field->type->db == 'text') { |
|
| 492 | + $dbType = 'string'; |
|
| 493 | 493 | } |
| 494 | 494 | else { |
| 495 | - $dbType = $field->type->db ; |
|
| 495 | + $dbType = $field->type->db; |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | - if(array_key_exists($dbType, $this->conditionsStub)){ |
|
| 498 | + if (array_key_exists($dbType, $this->conditionsStub)) { |
|
| 499 | 499 | return $this->conditionsStub[$dbType]; |
| 500 | 500 | } |
| 501 | 501 | else { |
| 502 | - $this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');; |
|
| 502 | + $this->conditionsStub[$dbType] = File::get($this->stubsDirectory.'SearchConditions/'.ucwords($dbType).'.php'); ; |
|
| 503 | 503 | |
| 504 | 504 | return $this->conditionsStub[$dbType]; |
| 505 | 505 | } |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public function __construct($scaffolderConfig, $modelData = null, $stubName = null) |
| 17 | 17 | { |
| 18 | - if ($stubName) |
|
| 19 | - $this->stubFilename = $stubName; |
|
| 18 | + if ($stubName) { |
|
| 19 | + $this->stubFilename = $stubName; |
|
| 20 | + } |
|
| 20 | 21 | $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
| 21 | 22 | parent::__construct($scaffolderConfig, $modelData); |
| 22 | 23 | } |
@@ -223,20 +224,15 @@ discard block |
||
| 223 | 224 | |
| 224 | 225 | if($field->index == 'primary'){ |
| 225 | 226 | $dbType = 'primaryKey' ; |
| 226 | - } |
|
| 227 | - elseif($field->foreignKey){ |
|
| 227 | + } elseif($field->foreignKey){ |
|
| 228 | 228 | $dbType = 'primary' ; |
| 229 | - } |
|
| 230 | - elseif($field->type->db == 'enum'){ |
|
| 229 | + } elseif($field->type->db == 'enum'){ |
|
| 231 | 230 | $dbType = 'primary' ; |
| 232 | - } |
|
| 233 | - elseif($field->type->db == 'boolean'){ |
|
| 231 | + } elseif($field->type->db == 'boolean'){ |
|
| 234 | 232 | $dbType = 'primary' ; |
| 235 | - } |
|
| 236 | - elseif($field->type->db == 'text'){ |
|
| 233 | + } elseif($field->type->db == 'text'){ |
|
| 237 | 234 | $dbType = 'string' ; |
| 238 | - } |
|
| 239 | - else { |
|
| 235 | + } else { |
|
| 240 | 236 | $dbType = $field->type->db ; |
| 241 | 237 | } |
| 242 | 238 | |
@@ -282,12 +278,13 @@ discard block |
||
| 282 | 278 | foreach ($this->modelData->reverseRelationships as $relationship) |
| 283 | 279 | { |
| 284 | 280 | $functionName = ''; |
| 285 | - if ($relationship->type == "hasOne") |
|
| 286 | - $functionName = strtolower($relationship->modelName); |
|
| 287 | - elseif ($relationship->type == "belongsToMany") |
|
| 288 | - $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); |
|
| 289 | - else |
|
| 290 | - $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 281 | + if ($relationship->type == "hasOne") { |
|
| 282 | + $functionName = strtolower($relationship->modelName); |
|
| 283 | + } elseif ($relationship->type == "belongsToMany") { |
|
| 284 | + $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); |
|
| 285 | + } else { |
|
| 286 | + $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 287 | + } |
|
| 291 | 288 | |
| 292 | 289 | $replacedMethod = ''; |
| 293 | 290 | $replacedMethod = str_replace('{{function_name}}', $functionName, $method); |
@@ -478,27 +475,21 @@ discard block |
||
| 478 | 475 | |
| 479 | 476 | if($field->index == 'primary'){ |
| 480 | 477 | $dbType = 'primary' ; |
| 481 | - } |
|
| 482 | - elseif($field->foreignKey){ |
|
| 478 | + } elseif($field->foreignKey){ |
|
| 483 | 479 | $dbType = 'primary' ; |
| 484 | - } |
|
| 485 | - elseif($field->type->db == 'enum'){ |
|
| 480 | + } elseif($field->type->db == 'enum'){ |
|
| 486 | 481 | $dbType = 'primary' ; |
| 487 | - } |
|
| 488 | - elseif($field->type->db == 'boolean'){ |
|
| 482 | + } elseif($field->type->db == 'boolean'){ |
|
| 489 | 483 | $dbType = 'primary' ; |
| 490 | - } |
|
| 491 | - elseif($field->type->db == 'text'){ |
|
| 484 | + } elseif($field->type->db == 'text'){ |
|
| 492 | 485 | $dbType = 'string' ; |
| 493 | - } |
|
| 494 | - else { |
|
| 486 | + } else { |
|
| 495 | 487 | $dbType = $field->type->db ; |
| 496 | 488 | } |
| 497 | 489 | |
| 498 | 490 | if(array_key_exists($dbType, $this->conditionsStub)){ |
| 499 | 491 | return $this->conditionsStub[$dbType]; |
| 500 | - } |
|
| 501 | - else { |
|
| 492 | + } else { |
|
| 502 | 493 | $this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');; |
| 503 | 494 | |
| 504 | 495 | return $this->conditionsStub[$dbType]; |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * Replace and store the Stub. |
| 29 | 29 | * |
| 30 | - * @return string |
|
| 30 | + * @return MigrationCompiler |
|
| 31 | 31 | */ |
| 32 | 32 | public function replaceAndStore() |
| 33 | 33 | { |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * Get output filename |
| 42 | 42 | * |
| 43 | 43 | * |
| 44 | - * @return $this |
|
| 44 | + * @return string |
|
| 45 | 45 | */ |
| 46 | 46 | protected function getOutputFilename() |
| 47 | 47 | { |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | namespace Scaffolder\Compilers\Core; |
| 4 | 4 | |
| 5 | 5 | use Carbon\Carbon; |
| 6 | -use Illuminate\Support\Facades\File; |
|
| 7 | 6 | use Scaffolder\Compilers\AbstractCompiler; |
| 8 | 7 | use Scaffolder\Compilers\Support\FileToCompile; |
| 9 | 8 | use Scaffolder\Compilers\Support\PathParser; |
@@ -10,130 +10,130 @@ |
||
| 10 | 10 | |
| 11 | 11 | class MigrationCompiler extends AbstractCompiler |
| 12 | 12 | { |
| 13 | - private $date; |
|
| 13 | + private $date; |
|
| 14 | 14 | |
| 15 | - protected $cachePrefix = 'migration_'; |
|
| 16 | - protected $stubFilename = 'Migration.php' ; |
|
| 15 | + protected $cachePrefix = 'migration_'; |
|
| 16 | + protected $stubFilename = 'Migration.php' ; |
|
| 17 | 17 | |
| 18 | - public function __construct($scaffolderConfig, $modelData = null) |
|
| 19 | - { |
|
| 20 | - $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
|
| 18 | + public function __construct($scaffolderConfig, $modelData = null) |
|
| 19 | + { |
|
| 20 | + $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
|
| 21 | 21 | |
| 22 | - parent::__construct($scaffolderConfig, $modelData); |
|
| 22 | + parent::__construct($scaffolderConfig, $modelData); |
|
| 23 | 23 | |
| 24 | - $this->date = Carbon::now(); |
|
| 25 | - } |
|
| 24 | + $this->date = Carbon::now(); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Replace and store the Stub. |
|
| 29 | - * |
|
| 30 | - * @return string |
|
| 31 | - */ |
|
| 32 | - public function replaceAndStore() |
|
| 33 | - { |
|
| 27 | + /** |
|
| 28 | + * Replace and store the Stub. |
|
| 29 | + * |
|
| 30 | + * @return string |
|
| 31 | + */ |
|
| 32 | + public function replaceAndStore() |
|
| 33 | + { |
|
| 34 | 34 | |
| 35 | - return $this->addFields() |
|
| 36 | - ->store(new FileToCompile(false, $this->modelData->modelHash)); |
|
| 35 | + return $this->addFields() |
|
| 36 | + ->store(new FileToCompile(false, $this->modelData->modelHash)); |
|
| 37 | 37 | |
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Get output filename |
|
| 42 | - * |
|
| 43 | - * |
|
| 44 | - * @return $this |
|
| 45 | - */ |
|
| 46 | - protected function getOutputFilename() |
|
| 47 | - { |
|
| 48 | - |
|
| 49 | - return PathParser::parse($this->scaffolderConfig->generator->paths->migrations) . $this->date->format('Y_m_d_') . str_pad($this->modelData->migrationOrder, 2, 0, STR_PAD_LEFT) . '_create_' . strtolower($this->modelName) . '_table.php'; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Add fields. |
|
| 54 | - * |
|
| 55 | - * @param $modelData |
|
| 56 | - * |
|
| 57 | - * @return $this |
|
| 58 | - */ |
|
| 59 | - private function addFields() |
|
| 60 | - { |
|
| 61 | - // Default primary key |
|
| 62 | - $fields = "\t\t\t\$table->increments('id');" . PHP_EOL . PHP_EOL; |
|
| 63 | - |
|
| 64 | - // Check primary key |
|
| 65 | - # TODO FIX, primary |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Get output filename |
|
| 42 | + * |
|
| 43 | + * |
|
| 44 | + * @return $this |
|
| 45 | + */ |
|
| 46 | + protected function getOutputFilename() |
|
| 47 | + { |
|
| 48 | + |
|
| 49 | + return PathParser::parse($this->scaffolderConfig->generator->paths->migrations) . $this->date->format('Y_m_d_') . str_pad($this->modelData->migrationOrder, 2, 0, STR_PAD_LEFT) . '_create_' . strtolower($this->modelName) . '_table.php'; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Add fields. |
|
| 54 | + * |
|
| 55 | + * @param $modelData |
|
| 56 | + * |
|
| 57 | + * @return $this |
|
| 58 | + */ |
|
| 59 | + private function addFields() |
|
| 60 | + { |
|
| 61 | + // Default primary key |
|
| 62 | + $fields = "\t\t\t\$table->increments('id');" . PHP_EOL . PHP_EOL; |
|
| 63 | + |
|
| 64 | + // Check primary key |
|
| 65 | + # TODO FIX, primary |
|
| 66 | 66 | |
| 67 | - foreach ($this->modelData->fields as $field) |
|
| 68 | - { |
|
| 69 | - $parsedModifiers = ''; |
|
| 70 | - |
|
| 71 | - if($field->index == "primary") |
|
| 72 | - continue ; |
|
| 73 | - if($this->modelData->timeStamps && $field->name == "created_at") |
|
| 74 | - continue ; |
|
| 75 | - if($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 76 | - continue ; |
|
| 77 | - |
|
| 78 | - // Check modifiers |
|
| 79 | - if (!empty($field->modifiers)) |
|
| 80 | - { |
|
| 81 | - $modifiersArray = explode(':', $field->modifiers); |
|
| 82 | - |
|
| 83 | - foreach ($modifiersArray as $modifier) |
|
| 84 | - { |
|
| 85 | - $modifierAndValue = explode(',', $modifier); |
|
| 86 | - |
|
| 87 | - if (count($modifierAndValue) == 2) |
|
| 88 | - { |
|
| 89 | - $parsedModifiers .= '->' . $modifierAndValue[0] . '(' . $modifierAndValue[1] . ')'; |
|
| 90 | - } |
|
| 91 | - else |
|
| 92 | - { |
|
| 93 | - $parsedModifiers .= '->' . $modifierAndValue[0] . '()'; |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // Check foreign key for unsigned modifier |
|
| 99 | - if ($field->foreignKey) |
|
| 100 | - { |
|
| 101 | - $parsedModifiers .= '->unsigned()'; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // Check indexes |
|
| 105 | - if ($field->index != 'none') |
|
| 106 | - { |
|
| 107 | - $fields .= sprintf("\t\t\t\$table->%s('%s')%s->%s();" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers, $field->index); |
|
| 108 | - } |
|
| 109 | - else |
|
| 110 | - { |
|
| 111 | - if ($field->type->db == "enum") { |
|
| 112 | - $items = ''; |
|
| 113 | - foreach ($field->options as $key => $option) { |
|
| 114 | - $items .= "'" . $option . "'"; |
|
| 115 | - if ($key < (count($field->options) - 1)) |
|
| 116 | - $items .= ", "; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $fields .= sprintf("\t\t\t\$table->%s('%s', array(%s));" . PHP_EOL, $field->type->db, $field->name, $items); |
|
| 120 | - } |
|
| 121 | - else |
|
| 122 | - $fields .= sprintf("\t\t\t\$table->%s('%s')%s;" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - // Check foreign key |
|
| 126 | - if ($field->foreignKey) |
|
| 127 | - { |
|
| 128 | - $fields .= sprintf("\t\t\t\$table->foreign('%s')->references('%s')->on('%s');" . PHP_EOL . PHP_EOL, $field->name, $field->foreignKey->field, $field->foreignKey->table); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if($this->modelData->timeStamps) |
|
| 133 | - $fields .= PHP_EOL . "\t\t\t\$table->timestamps();" . PHP_EOL; |
|
| 134 | - |
|
| 135 | - $this->stub = str_replace('{{fields}}', $fields, $this->stub); |
|
| 136 | - |
|
| 137 | - return $this; |
|
| 138 | - } |
|
| 67 | + foreach ($this->modelData->fields as $field) |
|
| 68 | + { |
|
| 69 | + $parsedModifiers = ''; |
|
| 70 | + |
|
| 71 | + if($field->index == "primary") |
|
| 72 | + continue ; |
|
| 73 | + if($this->modelData->timeStamps && $field->name == "created_at") |
|
| 74 | + continue ; |
|
| 75 | + if($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 76 | + continue ; |
|
| 77 | + |
|
| 78 | + // Check modifiers |
|
| 79 | + if (!empty($field->modifiers)) |
|
| 80 | + { |
|
| 81 | + $modifiersArray = explode(':', $field->modifiers); |
|
| 82 | + |
|
| 83 | + foreach ($modifiersArray as $modifier) |
|
| 84 | + { |
|
| 85 | + $modifierAndValue = explode(',', $modifier); |
|
| 86 | + |
|
| 87 | + if (count($modifierAndValue) == 2) |
|
| 88 | + { |
|
| 89 | + $parsedModifiers .= '->' . $modifierAndValue[0] . '(' . $modifierAndValue[1] . ')'; |
|
| 90 | + } |
|
| 91 | + else |
|
| 92 | + { |
|
| 93 | + $parsedModifiers .= '->' . $modifierAndValue[0] . '()'; |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // Check foreign key for unsigned modifier |
|
| 99 | + if ($field->foreignKey) |
|
| 100 | + { |
|
| 101 | + $parsedModifiers .= '->unsigned()'; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // Check indexes |
|
| 105 | + if ($field->index != 'none') |
|
| 106 | + { |
|
| 107 | + $fields .= sprintf("\t\t\t\$table->%s('%s')%s->%s();" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers, $field->index); |
|
| 108 | + } |
|
| 109 | + else |
|
| 110 | + { |
|
| 111 | + if ($field->type->db == "enum") { |
|
| 112 | + $items = ''; |
|
| 113 | + foreach ($field->options as $key => $option) { |
|
| 114 | + $items .= "'" . $option . "'"; |
|
| 115 | + if ($key < (count($field->options) - 1)) |
|
| 116 | + $items .= ", "; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $fields .= sprintf("\t\t\t\$table->%s('%s', array(%s));" . PHP_EOL, $field->type->db, $field->name, $items); |
|
| 120 | + } |
|
| 121 | + else |
|
| 122 | + $fields .= sprintf("\t\t\t\$table->%s('%s')%s;" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + // Check foreign key |
|
| 126 | + if ($field->foreignKey) |
|
| 127 | + { |
|
| 128 | + $fields .= sprintf("\t\t\t\$table->foreign('%s')->references('%s')->on('%s');" . PHP_EOL . PHP_EOL, $field->name, $field->foreignKey->field, $field->foreignKey->table); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if($this->modelData->timeStamps) |
|
| 133 | + $fields .= PHP_EOL . "\t\t\t\$table->timestamps();" . PHP_EOL; |
|
| 134 | + |
|
| 135 | + $this->stub = str_replace('{{fields}}', $fields, $this->stub); |
|
| 136 | + |
|
| 137 | + return $this; |
|
| 138 | + } |
|
| 139 | 139 | } |
| 140 | 140 | \ No newline at end of file |
@@ -13,11 +13,11 @@ discard block |
||
| 13 | 13 | private $date; |
| 14 | 14 | |
| 15 | 15 | protected $cachePrefix = 'migration_'; |
| 16 | - protected $stubFilename = 'Migration.php' ; |
|
| 16 | + protected $stubFilename = 'Migration.php'; |
|
| 17 | 17 | |
| 18 | 18 | public function __construct($scaffolderConfig, $modelData = null) |
| 19 | 19 | { |
| 20 | - $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
|
| 20 | + $this->stubsDirectory = __DIR__.'/../../../../stubs/Api/'; |
|
| 21 | 21 | |
| 22 | 22 | parent::__construct($scaffolderConfig, $modelData); |
| 23 | 23 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | protected function getOutputFilename() |
| 47 | 47 | { |
| 48 | 48 | |
| 49 | - return PathParser::parse($this->scaffolderConfig->generator->paths->migrations) . $this->date->format('Y_m_d_') . str_pad($this->modelData->migrationOrder, 2, 0, STR_PAD_LEFT) . '_create_' . strtolower($this->modelName) . '_table.php'; |
|
| 49 | + return PathParser::parse($this->scaffolderConfig->generator->paths->migrations).$this->date->format('Y_m_d_').str_pad($this->modelData->migrationOrder, 2, 0, STR_PAD_LEFT).'_create_'.strtolower($this->modelName).'_table.php'; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | private function addFields() |
| 60 | 60 | { |
| 61 | 61 | // Default primary key |
| 62 | - $fields = "\t\t\t\$table->increments('id');" . PHP_EOL . PHP_EOL; |
|
| 62 | + $fields = "\t\t\t\$table->increments('id');".PHP_EOL.PHP_EOL; |
|
| 63 | 63 | |
| 64 | 64 | // Check primary key |
| 65 | 65 | # TODO FIX, primary |
@@ -68,12 +68,12 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | $parsedModifiers = ''; |
| 70 | 70 | |
| 71 | - if($field->index == "primary") |
|
| 72 | - continue ; |
|
| 73 | - if($this->modelData->timeStamps && $field->name == "created_at") |
|
| 74 | - continue ; |
|
| 75 | - if($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 76 | - continue ; |
|
| 71 | + if ($field->index == "primary") |
|
| 72 | + continue; |
|
| 73 | + if ($this->modelData->timeStamps && $field->name == "created_at") |
|
| 74 | + continue; |
|
| 75 | + if ($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 76 | + continue; |
|
| 77 | 77 | |
| 78 | 78 | // Check modifiers |
| 79 | 79 | if (!empty($field->modifiers)) |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | if (count($modifierAndValue) == 2) |
| 88 | 88 | { |
| 89 | - $parsedModifiers .= '->' . $modifierAndValue[0] . '(' . $modifierAndValue[1] . ')'; |
|
| 89 | + $parsedModifiers .= '->'.$modifierAndValue[0].'('.$modifierAndValue[1].')'; |
|
| 90 | 90 | } |
| 91 | 91 | else |
| 92 | 92 | { |
| 93 | - $parsedModifiers .= '->' . $modifierAndValue[0] . '()'; |
|
| 93 | + $parsedModifiers .= '->'.$modifierAndValue[0].'()'; |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -104,33 +104,33 @@ discard block |
||
| 104 | 104 | // Check indexes |
| 105 | 105 | if ($field->index != 'none') |
| 106 | 106 | { |
| 107 | - $fields .= sprintf("\t\t\t\$table->%s('%s')%s->%s();" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers, $field->index); |
|
| 107 | + $fields .= sprintf("\t\t\t\$table->%s('%s')%s->%s();".PHP_EOL, $field->type->db, $field->name, $parsedModifiers, $field->index); |
|
| 108 | 108 | } |
| 109 | 109 | else |
| 110 | 110 | { |
| 111 | 111 | if ($field->type->db == "enum") { |
| 112 | 112 | $items = ''; |
| 113 | 113 | foreach ($field->options as $key => $option) { |
| 114 | - $items .= "'" . $option . "'"; |
|
| 114 | + $items .= "'".$option."'"; |
|
| 115 | 115 | if ($key < (count($field->options) - 1)) |
| 116 | 116 | $items .= ", "; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $fields .= sprintf("\t\t\t\$table->%s('%s', array(%s));" . PHP_EOL, $field->type->db, $field->name, $items); |
|
| 119 | + $fields .= sprintf("\t\t\t\$table->%s('%s', array(%s));".PHP_EOL, $field->type->db, $field->name, $items); |
|
| 120 | 120 | } |
| 121 | 121 | else |
| 122 | - $fields .= sprintf("\t\t\t\$table->%s('%s')%s;" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers); |
|
| 122 | + $fields .= sprintf("\t\t\t\$table->%s('%s')%s;".PHP_EOL, $field->type->db, $field->name, $parsedModifiers); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // Check foreign key |
| 126 | 126 | if ($field->foreignKey) |
| 127 | 127 | { |
| 128 | - $fields .= sprintf("\t\t\t\$table->foreign('%s')->references('%s')->on('%s');" . PHP_EOL . PHP_EOL, $field->name, $field->foreignKey->field, $field->foreignKey->table); |
|
| 128 | + $fields .= sprintf("\t\t\t\$table->foreign('%s')->references('%s')->on('%s');".PHP_EOL.PHP_EOL, $field->name, $field->foreignKey->field, $field->foreignKey->table); |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if($this->modelData->timeStamps) |
|
| 133 | - $fields .= PHP_EOL . "\t\t\t\$table->timestamps();" . PHP_EOL; |
|
| 132 | + if ($this->modelData->timeStamps) |
|
| 133 | + $fields .= PHP_EOL."\t\t\t\$table->timestamps();".PHP_EOL; |
|
| 134 | 134 | |
| 135 | 135 | $this->stub = str_replace('{{fields}}', $fields, $this->stub); |
| 136 | 136 | |
@@ -68,12 +68,15 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | $parsedModifiers = ''; |
| 70 | 70 | |
| 71 | - if($field->index == "primary") |
|
| 72 | - continue ; |
|
| 73 | - if($this->modelData->timeStamps && $field->name == "created_at") |
|
| 74 | - continue ; |
|
| 75 | - if($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 76 | - continue ; |
|
| 71 | + if($field->index == "primary") { |
|
| 72 | + continue ; |
|
| 73 | + } |
|
| 74 | + if($this->modelData->timeStamps && $field->name == "created_at") { |
|
| 75 | + continue ; |
|
| 76 | + } |
|
| 77 | + if($this->modelData->timeStamps && $field->name == "updated_at") { |
|
| 78 | + continue ; |
|
| 79 | + } |
|
| 77 | 80 | |
| 78 | 81 | // Check modifiers |
| 79 | 82 | if (!empty($field->modifiers)) |
@@ -87,8 +90,7 @@ discard block |
||
| 87 | 90 | if (count($modifierAndValue) == 2) |
| 88 | 91 | { |
| 89 | 92 | $parsedModifiers .= '->' . $modifierAndValue[0] . '(' . $modifierAndValue[1] . ')'; |
| 90 | - } |
|
| 91 | - else |
|
| 93 | + } else |
|
| 92 | 94 | { |
| 93 | 95 | $parsedModifiers .= '->' . $modifierAndValue[0] . '()'; |
| 94 | 96 | } |
@@ -105,21 +107,21 @@ discard block |
||
| 105 | 107 | if ($field->index != 'none') |
| 106 | 108 | { |
| 107 | 109 | $fields .= sprintf("\t\t\t\$table->%s('%s')%s->%s();" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers, $field->index); |
| 108 | - } |
|
| 109 | - else |
|
| 110 | + } else |
|
| 110 | 111 | { |
| 111 | 112 | if ($field->type->db == "enum") { |
| 112 | 113 | $items = ''; |
| 113 | 114 | foreach ($field->options as $key => $option) { |
| 114 | 115 | $items .= "'" . $option . "'"; |
| 115 | - if ($key < (count($field->options) - 1)) |
|
| 116 | - $items .= ", "; |
|
| 116 | + if ($key < (count($field->options) - 1)) { |
|
| 117 | + $items .= ", "; |
|
| 118 | + } |
|
| 117 | 119 | } |
| 118 | 120 | |
| 119 | 121 | $fields .= sprintf("\t\t\t\$table->%s('%s', array(%s));" . PHP_EOL, $field->type->db, $field->name, $items); |
| 122 | + } else { |
|
| 123 | + $fields .= sprintf("\t\t\t\$table->%s('%s')%s;" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers); |
|
| 120 | 124 | } |
| 121 | - else |
|
| 122 | - $fields .= sprintf("\t\t\t\$table->%s('%s')%s;" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers); |
|
| 123 | 125 | } |
| 124 | 126 | |
| 125 | 127 | // Check foreign key |
@@ -129,8 +131,9 @@ discard block |
||
| 129 | 131 | } |
| 130 | 132 | } |
| 131 | 133 | |
| 132 | - if($this->modelData->timeStamps) |
|
| 133 | - $fields .= PHP_EOL . "\t\t\t\$table->timestamps();" . PHP_EOL; |
|
| 134 | + if($this->modelData->timeStamps) { |
|
| 135 | + $fields .= PHP_EOL . "\t\t\t\$table->timestamps();" . PHP_EOL; |
|
| 136 | + } |
|
| 134 | 137 | |
| 135 | 138 | $this->stub = str_replace('{{fields}}', $fields, $this->stub); |
| 136 | 139 | |
@@ -14,6 +14,9 @@ discard block |
||
| 14 | 14 | protected $cachePrefix = 'model_'; |
| 15 | 15 | protected $stubFilename = 'Model/Model.php' ; |
| 16 | 16 | |
| 17 | + /** |
|
| 18 | + * @param string $stubName |
|
| 19 | + */ |
|
| 17 | 20 | public function __construct($scaffolderConfig, $modelData = null, $stubName = null) |
| 18 | 21 | { |
| 19 | 22 | if ($stubName) |
@@ -25,7 +28,7 @@ discard block |
||
| 25 | 28 | /** |
| 26 | 29 | * Replace and store the Stub. |
| 27 | 30 | * |
| 28 | - * @return string |
|
| 31 | + * @return ModelCompiler |
|
| 29 | 32 | */ |
| 30 | 33 | public function replaceAndStore() |
| 31 | 34 | { |
@@ -54,7 +57,7 @@ discard block |
||
| 54 | 57 | * Get output filename |
| 55 | 58 | * |
| 56 | 59 | * |
| 57 | - * @return $this |
|
| 60 | + * @return string |
|
| 58 | 61 | */ |
| 59 | 62 | protected function getOutputFilename() |
| 60 | 63 | { |
@@ -528,6 +531,10 @@ discard block |
||
| 528 | 531 | * @return $this |
| 529 | 532 | */ |
| 530 | 533 | private $conditionsStub = []; |
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * @return string |
|
| 537 | + */ |
|
| 531 | 538 | private function getConditionStubByField($field){ |
| 532 | 539 | |
| 533 | 540 | if($field->index == 'primary'){ |
@@ -6,7 +6,6 @@ |
||
| 6 | 6 | use Scaffolder\Compilers\AbstractCompiler; |
| 7 | 7 | use Scaffolder\Compilers\Support\FileToCompile; |
| 8 | 8 | use Scaffolder\Compilers\Support\PathParser; |
| 9 | -use Scaffolder\Support\Directory; |
|
| 10 | 9 | use Scaffolder\Support\CamelCase; |
| 11 | 10 | |
| 12 | 11 | class ModelCompiler extends AbstractCompiler |
@@ -11,692 +11,692 @@ |
||
| 11 | 11 | |
| 12 | 12 | class ModelCompiler extends AbstractCompiler |
| 13 | 13 | { |
| 14 | - protected $cachePrefix = 'model_'; |
|
| 15 | - protected $stubFilename = 'Model/Model.php' ; |
|
| 16 | - |
|
| 17 | - public function __construct($scaffolderConfig, $modelData = null, $stubName = null) |
|
| 18 | - { |
|
| 19 | - if ($stubName) |
|
| 20 | - $this->stubFilename = $stubName; |
|
| 21 | - $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
|
| 22 | - parent::__construct($scaffolderConfig, $modelData); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Replace and store the Stub. |
|
| 27 | - * |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function replaceAndStore() |
|
| 31 | - { |
|
| 14 | + protected $cachePrefix = 'model_'; |
|
| 15 | + protected $stubFilename = 'Model/Model.php' ; |
|
| 16 | + |
|
| 17 | + public function __construct($scaffolderConfig, $modelData = null, $stubName = null) |
|
| 18 | + { |
|
| 19 | + if ($stubName) |
|
| 20 | + $this->stubFilename = $stubName; |
|
| 21 | + $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
|
| 22 | + parent::__construct($scaffolderConfig, $modelData); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Replace and store the Stub. |
|
| 27 | + * |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function replaceAndStore() |
|
| 31 | + { |
|
| 32 | 32 | |
| 33 | - return $this->replaceNamespace() |
|
| 34 | - ->replaceNamespaceModelExtend() |
|
| 35 | - ->setPrimaryKey() |
|
| 36 | - ->setTimeStamps() |
|
| 37 | - ->addFillable() |
|
| 38 | - ->addEnumFields() |
|
| 39 | - ->addRules() |
|
| 40 | - ->addBelongsTo() |
|
| 41 | - ->addReverseRelationship() |
|
| 42 | - ->replaceEagerCode() |
|
| 43 | - ->replaceRelationshipTables() |
|
| 44 | - ->replaceSearchConditions() |
|
| 45 | - ->replaceSimpleFilter() |
|
| 46 | - ->replaceSortConditions() |
|
| 47 | - ->replaceReverseRelationshipsFunctions() |
|
| 48 | - ->replaceCheckbox() |
|
| 49 | - ->store(new FileToCompile(false, $this->modelData->modelHash)); |
|
| 33 | + return $this->replaceNamespace() |
|
| 34 | + ->replaceNamespaceModelExtend() |
|
| 35 | + ->setPrimaryKey() |
|
| 36 | + ->setTimeStamps() |
|
| 37 | + ->addFillable() |
|
| 38 | + ->addEnumFields() |
|
| 39 | + ->addRules() |
|
| 40 | + ->addBelongsTo() |
|
| 41 | + ->addReverseRelationship() |
|
| 42 | + ->replaceEagerCode() |
|
| 43 | + ->replaceRelationshipTables() |
|
| 44 | + ->replaceSearchConditions() |
|
| 45 | + ->replaceSimpleFilter() |
|
| 46 | + ->replaceSortConditions() |
|
| 47 | + ->replaceReverseRelationshipsFunctions() |
|
| 48 | + ->replaceCheckbox() |
|
| 49 | + ->store(new FileToCompile(false, $this->modelData->modelHash)); |
|
| 50 | 50 | |
| 51 | - } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Get output filename |
|
| 55 | - * |
|
| 56 | - * |
|
| 57 | - * @return $this |
|
| 58 | - */ |
|
| 59 | - protected function getOutputFilename() |
|
| 60 | - { |
|
| 61 | - $folder = PathParser::parse($this->scaffolderConfig->generator->paths->models) ; |
|
| 62 | - |
|
| 63 | - return $folder . $this->modelName . '.php'; |
|
| 64 | - } |
|
| 53 | + /** |
|
| 54 | + * Get output filename |
|
| 55 | + * |
|
| 56 | + * |
|
| 57 | + * @return $this |
|
| 58 | + */ |
|
| 59 | + protected function getOutputFilename() |
|
| 60 | + { |
|
| 61 | + $folder = PathParser::parse($this->scaffolderConfig->generator->paths->models) ; |
|
| 62 | + |
|
| 63 | + return $folder . $this->modelName . '.php'; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Replace the namespace which the model extends |
|
| 70 | - * |
|
| 71 | - * @param $this->scaffolderConfig |
|
| 72 | - * |
|
| 73 | - * @return $this |
|
| 74 | - */ |
|
| 75 | - private function replaceNamespaceModelExtend() |
|
| 76 | - { |
|
| 77 | - $this->stub = str_replace('{{namespace_model_extend}}', $this->scaffolderConfig->generator->inheritance->model, $this->stub); |
|
| 78 | - |
|
| 79 | - return $this; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Add fillable. |
|
| 84 | - * |
|
| 85 | - * @return $this |
|
| 86 | - */ |
|
| 87 | - private function addFillable() |
|
| 88 | - { |
|
| 89 | - $fields = ''; |
|
| 90 | - $firstIteration = true; |
|
| 91 | - |
|
| 92 | - foreach ($this->modelData->fields as $field) |
|
| 93 | - { |
|
| 94 | - if($field->index == "primary") |
|
| 95 | - continue ; |
|
| 96 | - if($this->modelData->timeStamps && $field->name == "created_at") |
|
| 97 | - continue ; |
|
| 98 | - if($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 99 | - continue ; |
|
| 100 | - |
|
| 101 | - if ($firstIteration) |
|
| 102 | - { |
|
| 103 | - $fields .= sprintf("'%s'," . PHP_EOL, $field->name); |
|
| 104 | - $firstIteration = false; |
|
| 105 | - } |
|
| 106 | - else |
|
| 107 | - { |
|
| 108 | - $fields .= sprintf("\t\t'%s'," . PHP_EOL, $field->name); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - $this->stub = str_replace('{{fillable}}', $fields, $this->stub); |
|
| 113 | - |
|
| 114 | - return $this; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - private function addEnumFields() { |
|
| 118 | - |
|
| 119 | - $items = ''; |
|
| 120 | - $arrays = ''; |
|
| 68 | + /** |
|
| 69 | + * Replace the namespace which the model extends |
|
| 70 | + * |
|
| 71 | + * @param $this->scaffolderConfig |
|
| 72 | + * |
|
| 73 | + * @return $this |
|
| 74 | + */ |
|
| 75 | + private function replaceNamespaceModelExtend() |
|
| 76 | + { |
|
| 77 | + $this->stub = str_replace('{{namespace_model_extend}}', $this->scaffolderConfig->generator->inheritance->model, $this->stub); |
|
| 78 | + |
|
| 79 | + return $this; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Add fillable. |
|
| 84 | + * |
|
| 85 | + * @return $this |
|
| 86 | + */ |
|
| 87 | + private function addFillable() |
|
| 88 | + { |
|
| 89 | + $fields = ''; |
|
| 90 | + $firstIteration = true; |
|
| 91 | + |
|
| 92 | + foreach ($this->modelData->fields as $field) |
|
| 93 | + { |
|
| 94 | + if($field->index == "primary") |
|
| 95 | + continue ; |
|
| 96 | + if($this->modelData->timeStamps && $field->name == "created_at") |
|
| 97 | + continue ; |
|
| 98 | + if($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 99 | + continue ; |
|
| 100 | + |
|
| 101 | + if ($firstIteration) |
|
| 102 | + { |
|
| 103 | + $fields .= sprintf("'%s'," . PHP_EOL, $field->name); |
|
| 104 | + $firstIteration = false; |
|
| 105 | + } |
|
| 106 | + else |
|
| 107 | + { |
|
| 108 | + $fields .= sprintf("\t\t'%s'," . PHP_EOL, $field->name); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + $this->stub = str_replace('{{fillable}}', $fields, $this->stub); |
|
| 113 | + |
|
| 114 | + return $this; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + private function addEnumFields() { |
|
| 118 | + |
|
| 119 | + $items = ''; |
|
| 120 | + $arrays = ''; |
|
| 121 | 121 | |
| 122 | - foreach ($this->modelData->fields as $field) { |
|
| 123 | - $enumStub = File::get($this->stubsDirectory . '/Model/ModelEnum.php'); |
|
| 122 | + foreach ($this->modelData->fields as $field) { |
|
| 123 | + $enumStub = File::get($this->stubsDirectory . '/Model/ModelEnum.php'); |
|
| 124 | 124 | |
| 125 | - if ($field->type->db == "enum") { |
|
| 126 | - $items = ''; |
|
| 125 | + if ($field->type->db == "enum") { |
|
| 126 | + $items = ''; |
|
| 127 | 127 | |
| 128 | - foreach ($field->options as $key => $option) { |
|
| 129 | - $items .= "'" . $option . "'"; |
|
| 130 | - if ($key < (count($field->options) - 1)) |
|
| 131 | - $items .= ", "; |
|
| 128 | + foreach ($field->options as $key => $option) { |
|
| 129 | + $items .= "'" . $option . "'"; |
|
| 130 | + if ($key < (count($field->options) - 1)) |
|
| 131 | + $items .= ", "; |
|
| 132 | 132 | |
| 133 | - } |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | |
| 136 | - $enumStub = str_replace('{{field_options}}', $items, $enumStub); |
|
| 137 | - $enumStub = str_replace('{{field_name}}', $field->name, $enumStub); |
|
| 136 | + $enumStub = str_replace('{{field_options}}', $items, $enumStub); |
|
| 137 | + $enumStub = str_replace('{{field_name}}', $field->name, $enumStub); |
|
| 138 | 138 | |
| 139 | - $arrays .= $enumStub; |
|
| 139 | + $arrays .= $enumStub; |
|
| 140 | 140 | |
| 141 | 141 | |
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $this->stub = str_replace('{{enum}}', $arrays, $this->stub); |
|
| 146 | - |
|
| 147 | - return $this; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Set validations. |
|
| 152 | - * |
|
| 153 | - * |
|
| 154 | - * @return $this |
|
| 155 | - */ |
|
| 156 | - private function addRules() |
|
| 157 | - { |
|
| 158 | - $fields = ''; |
|
| 159 | - $firstIteration = true; |
|
| 160 | - |
|
| 161 | - foreach ($this->modelData->fields as $field) |
|
| 162 | - { |
|
| 163 | - if($field->index == "primary") |
|
| 164 | - continue ; |
|
| 165 | - if($this->modelData->timeStamps && $field->name == "created_at") |
|
| 166 | - continue ; |
|
| 167 | - if($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 168 | - continue ; |
|
| 169 | - |
|
| 170 | - if ($firstIteration) |
|
| 171 | - { |
|
| 172 | - $fields .= sprintf("'%s' => '%s'," . PHP_EOL, $field->name, $field->validations); |
|
| 173 | - $firstIteration = false; |
|
| 174 | - } |
|
| 175 | - else |
|
| 176 | - { |
|
| 177 | - $fields .= sprintf("\t\t\t'%s' => '%s'," . PHP_EOL, $field->name, $field->validations); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $fields = str_replace('unique','unique:'.$this->modelData->tableName,$fields); |
|
| 182 | - //var_dump($fields); |
|
| 183 | - |
|
| 184 | - $this->stub = str_replace('{{validations}}', $fields, $this->stub); |
|
| 185 | - |
|
| 186 | - return $this; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Set the timestamps value. |
|
| 191 | - * |
|
| 192 | - */ |
|
| 193 | - private function setTimeStamps() |
|
| 194 | - { |
|
| 195 | - if($this->modelData->timeStamps) |
|
| 196 | - { |
|
| 197 | - $this->stub = str_replace('{{timestamps}}', ' ', $this->stub); |
|
| 198 | - } else { |
|
| 199 | - $this->stub = str_replace('{{timestamps}}', 'public $timestamps = false;', $this->stub); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $this; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Set the primary key. |
|
| 207 | - * |
|
| 208 | - */ |
|
| 209 | - private function setPrimaryKey() |
|
| 210 | - { |
|
| 211 | - $primaryKey = '// Using default primary key' . PHP_EOL; |
|
| 212 | - |
|
| 213 | - $field = $this->getPrimaryKeyField() ; |
|
| 214 | - |
|
| 215 | - $primaryKey = 'protected $primaryKey = \'' . $field->name . '\';' . PHP_EOL; |
|
| 216 | - |
|
| 217 | - $this->stub = str_replace('{{primaryAttribute}}', $primaryKey, $this->stub); |
|
| 218 | - |
|
| 219 | - return $this; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Add belongsTo Relationships. |
|
| 224 | - * |
|
| 225 | - * |
|
| 226 | - * @return $this |
|
| 227 | - */ |
|
| 228 | - private function addBelongsTo() |
|
| 229 | - { |
|
| 230 | - $functions = ''; |
|
| 231 | - |
|
| 232 | - $eagerArray = []; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $this->stub = str_replace('{{enum}}', $arrays, $this->stub); |
|
| 146 | + |
|
| 147 | + return $this; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Set validations. |
|
| 152 | + * |
|
| 153 | + * |
|
| 154 | + * @return $this |
|
| 155 | + */ |
|
| 156 | + private function addRules() |
|
| 157 | + { |
|
| 158 | + $fields = ''; |
|
| 159 | + $firstIteration = true; |
|
| 160 | + |
|
| 161 | + foreach ($this->modelData->fields as $field) |
|
| 162 | + { |
|
| 163 | + if($field->index == "primary") |
|
| 164 | + continue ; |
|
| 165 | + if($this->modelData->timeStamps && $field->name == "created_at") |
|
| 166 | + continue ; |
|
| 167 | + if($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 168 | + continue ; |
|
| 169 | + |
|
| 170 | + if ($firstIteration) |
|
| 171 | + { |
|
| 172 | + $fields .= sprintf("'%s' => '%s'," . PHP_EOL, $field->name, $field->validations); |
|
| 173 | + $firstIteration = false; |
|
| 174 | + } |
|
| 175 | + else |
|
| 176 | + { |
|
| 177 | + $fields .= sprintf("\t\t\t'%s' => '%s'," . PHP_EOL, $field->name, $field->validations); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $fields = str_replace('unique','unique:'.$this->modelData->tableName,$fields); |
|
| 182 | + //var_dump($fields); |
|
| 183 | + |
|
| 184 | + $this->stub = str_replace('{{validations}}', $fields, $this->stub); |
|
| 185 | + |
|
| 186 | + return $this; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Set the timestamps value. |
|
| 191 | + * |
|
| 192 | + */ |
|
| 193 | + private function setTimeStamps() |
|
| 194 | + { |
|
| 195 | + if($this->modelData->timeStamps) |
|
| 196 | + { |
|
| 197 | + $this->stub = str_replace('{{timestamps}}', ' ', $this->stub); |
|
| 198 | + } else { |
|
| 199 | + $this->stub = str_replace('{{timestamps}}', 'public $timestamps = false;', $this->stub); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $this; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Set the primary key. |
|
| 207 | + * |
|
| 208 | + */ |
|
| 209 | + private function setPrimaryKey() |
|
| 210 | + { |
|
| 211 | + $primaryKey = '// Using default primary key' . PHP_EOL; |
|
| 212 | + |
|
| 213 | + $field = $this->getPrimaryKeyField() ; |
|
| 214 | + |
|
| 215 | + $primaryKey = 'protected $primaryKey = \'' . $field->name . '\';' . PHP_EOL; |
|
| 216 | + |
|
| 217 | + $this->stub = str_replace('{{primaryAttribute}}', $primaryKey, $this->stub); |
|
| 218 | + |
|
| 219 | + return $this; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Add belongsTo Relationships. |
|
| 224 | + * |
|
| 225 | + * |
|
| 226 | + * @return $this |
|
| 227 | + */ |
|
| 228 | + private function addBelongsTo() |
|
| 229 | + { |
|
| 230 | + $functions = ''; |
|
| 231 | + |
|
| 232 | + $eagerArray = []; |
|
| 233 | 233 | |
| 234 | - foreach ($this->modelData->fields as $field) |
|
| 235 | - { |
|
| 234 | + foreach ($this->modelData->fields as $field) |
|
| 235 | + { |
|
| 236 | 236 | |
| 237 | - // Check foreign key |
|
| 238 | - if (isset($field->foreignKey->relationship)) |
|
| 239 | - { |
|
| 240 | - $belongsToStub = ""; |
|
| 241 | - $functionName = $field->foreignKey->table; |
|
| 242 | - |
|
| 243 | - if ($field->foreignKey->relationship == "belongsTo") { |
|
| 244 | - $belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsTo.php'); |
|
| 245 | - $belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub); |
|
| 246 | - $belongsToStub = str_replace('{{field}}', $field->name, $belongsToStub); |
|
| 247 | - $belongsToStub = str_replace('{{foreign_field}}', $field->foreignKey->field, $belongsToStub); |
|
| 248 | - } |
|
| 249 | - elseif ($field->foreignKey->relationship == "belongsToMany") { |
|
| 250 | - $belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php'); |
|
| 251 | - $functionName = CamelCase::pluralize($field->foreignKey->table); |
|
| 252 | - $belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub); |
|
| 253 | - $belongsToStub = str_replace('{{foreign_key}}', $field->name, $belongsToStub); |
|
| 254 | - $belongsToStub = str_replace('{{related_field}}', $field->foreignKey->field, $belongsToStub); |
|
| 255 | - $belongsToStub = str_replace('{{table_name}}', $field->foreignKey->table, $belongsToStub); |
|
| 256 | - } |
|
| 237 | + // Check foreign key |
|
| 238 | + if (isset($field->foreignKey->relationship)) |
|
| 239 | + { |
|
| 240 | + $belongsToStub = ""; |
|
| 241 | + $functionName = $field->foreignKey->table; |
|
| 242 | + |
|
| 243 | + if ($field->foreignKey->relationship == "belongsTo") { |
|
| 244 | + $belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsTo.php'); |
|
| 245 | + $belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub); |
|
| 246 | + $belongsToStub = str_replace('{{field}}', $field->name, $belongsToStub); |
|
| 247 | + $belongsToStub = str_replace('{{foreign_field}}', $field->foreignKey->field, $belongsToStub); |
|
| 248 | + } |
|
| 249 | + elseif ($field->foreignKey->relationship == "belongsToMany") { |
|
| 250 | + $belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php'); |
|
| 251 | + $functionName = CamelCase::pluralize($field->foreignKey->table); |
|
| 252 | + $belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub); |
|
| 253 | + $belongsToStub = str_replace('{{foreign_key}}', $field->name, $belongsToStub); |
|
| 254 | + $belongsToStub = str_replace('{{related_field}}', $field->foreignKey->field, $belongsToStub); |
|
| 255 | + $belongsToStub = str_replace('{{table_name}}', $field->foreignKey->table, $belongsToStub); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - $belongsToStub = str_replace('{{foreign_table}}', $functionName, $belongsToStub); |
|
| 259 | - $belongsToStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $belongsToStub); |
|
| 258 | + $belongsToStub = str_replace('{{foreign_table}}', $functionName, $belongsToStub); |
|
| 259 | + $belongsToStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $belongsToStub); |
|
| 260 | 260 | |
| 261 | - $functions .= $belongsToStub ; |
|
| 261 | + $functions .= $belongsToStub ; |
|
| 262 | 262 | |
| 263 | - if(isset($field->foreignKey->eager) && $field->foreignKey->eager){ |
|
| 264 | - array_push($eagerArray, "'".$field->foreignKey->table."'"); |
|
| 265 | - } |
|
| 266 | - } |
|
| 263 | + if(isset($field->foreignKey->eager) && $field->foreignKey->eager){ |
|
| 264 | + array_push($eagerArray, "'".$field->foreignKey->table."'"); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | 268 | |
| 269 | - } |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - $this->stub = str_replace('{{belongsTo}}', $functions, $this->stub); |
|
| 271 | + $this->stub = str_replace('{{belongsTo}}', $functions, $this->stub); |
|
| 272 | 272 | |
| 273 | - $this->stub = str_replace('{{eager}}', join("," , $eagerArray) , $this->stub); |
|
| 273 | + $this->stub = str_replace('{{eager}}', join("," , $eagerArray) , $this->stub); |
|
| 274 | 274 | |
| 275 | - return $this; |
|
| 276 | - } |
|
| 275 | + return $this; |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - private function addReverseRelationship() |
|
| 279 | - { |
|
| 280 | - $functions = ''; |
|
| 278 | + private function addReverseRelationship() |
|
| 279 | + { |
|
| 280 | + $functions = ''; |
|
| 281 | 281 | |
| 282 | - $eagerArray = []; |
|
| 282 | + $eagerArray = []; |
|
| 283 | 283 | |
| 284 | - foreach ($this->modelData->reverseRelationships as $relationship) |
|
| 285 | - { |
|
| 284 | + foreach ($this->modelData->reverseRelationships as $relationship) |
|
| 285 | + { |
|
| 286 | 286 | |
| 287 | - // Check foreign key |
|
| 288 | - if ($relationship->foreignKey) |
|
| 289 | - { |
|
| 290 | - $reverseRelationshipStub = ""; |
|
| 291 | - $functionName = ''; |
|
| 292 | - if ($relationship->type == "hasOne") |
|
| 293 | - $functionName = strtolower($relationship->modelName); |
|
| 294 | - else |
|
| 295 | - $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 287 | + // Check foreign key |
|
| 288 | + if ($relationship->foreignKey) |
|
| 289 | + { |
|
| 290 | + $reverseRelationshipStub = ""; |
|
| 291 | + $functionName = ''; |
|
| 292 | + if ($relationship->type == "hasOne") |
|
| 293 | + $functionName = strtolower($relationship->modelName); |
|
| 294 | + else |
|
| 295 | + $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 296 | 296 | |
| 297 | - if ($relationship->type == "belongsToMany") { |
|
| 298 | - $reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php'); |
|
| 299 | - $reverseRelationshipStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($relationship->relatedTable), $reverseRelationshipOriginalStub); |
|
| 300 | - $reverseRelationshipStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $reverseRelationshipStub); |
|
| 301 | - $reverseRelationshipStub = str_replace('{{table_name}}', $relationship->tableName, $reverseRelationshipStub); |
|
| 302 | - $reverseRelationshipStub = str_replace('{{related_field}}', $relationship->relatedField, $reverseRelationshipStub); |
|
| 303 | - $reverseRelationshipStub = str_replace('{{foreign_table}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $reverseRelationshipStub); |
|
| 304 | - } |
|
| 305 | - else { |
|
| 306 | - $reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelReverseRelationship.php'); |
|
| 307 | - $reverseRelationshipStub = str_replace('{{foreign_model}}', $relationship->modelName, $reverseRelationshipOriginalStub); |
|
| 308 | - $reverseRelationshipStub = str_replace('{{field}}', $relationship->foreignKey, $reverseRelationshipStub); |
|
| 309 | - $reverseRelationshipStub = str_replace('{{foreign_field}}', $relationship->localKey, $reverseRelationshipStub); |
|
| 310 | - $reverseRelationshipStub = str_replace('{{type}}', $relationship->type, $reverseRelationshipStub); |
|
| 311 | - $reverseRelationshipStub = str_replace('{{foreign_table}}', $functionName, $reverseRelationshipStub); |
|
| 312 | - } |
|
| 297 | + if ($relationship->type == "belongsToMany") { |
|
| 298 | + $reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php'); |
|
| 299 | + $reverseRelationshipStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($relationship->relatedTable), $reverseRelationshipOriginalStub); |
|
| 300 | + $reverseRelationshipStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $reverseRelationshipStub); |
|
| 301 | + $reverseRelationshipStub = str_replace('{{table_name}}', $relationship->tableName, $reverseRelationshipStub); |
|
| 302 | + $reverseRelationshipStub = str_replace('{{related_field}}', $relationship->relatedField, $reverseRelationshipStub); |
|
| 303 | + $reverseRelationshipStub = str_replace('{{foreign_table}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $reverseRelationshipStub); |
|
| 304 | + } |
|
| 305 | + else { |
|
| 306 | + $reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelReverseRelationship.php'); |
|
| 307 | + $reverseRelationshipStub = str_replace('{{foreign_model}}', $relationship->modelName, $reverseRelationshipOriginalStub); |
|
| 308 | + $reverseRelationshipStub = str_replace('{{field}}', $relationship->foreignKey, $reverseRelationshipStub); |
|
| 309 | + $reverseRelationshipStub = str_replace('{{foreign_field}}', $relationship->localKey, $reverseRelationshipStub); |
|
| 310 | + $reverseRelationshipStub = str_replace('{{type}}', $relationship->type, $reverseRelationshipStub); |
|
| 311 | + $reverseRelationshipStub = str_replace('{{foreign_table}}', $functionName, $reverseRelationshipStub); |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - $reverseRelationshipStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $reverseRelationshipStub); |
|
| 314 | + $reverseRelationshipStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $reverseRelationshipStub); |
|
| 315 | 315 | |
| 316 | - $functions .= $reverseRelationshipStub ; |
|
| 316 | + $functions .= $reverseRelationshipStub ; |
|
| 317 | 317 | |
| 318 | - if(isset($relationship->foreignKey->eager) && $relationship->foreignKey->eager){ |
|
| 319 | - array_push($eagerArray, "'".$relationship->foreignKey->table."'"); |
|
| 320 | - } |
|
| 321 | - } |
|
| 318 | + if(isset($relationship->foreignKey->eager) && $relationship->foreignKey->eager){ |
|
| 319 | + array_push($eagerArray, "'".$relationship->foreignKey->table."'"); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | 323 | |
| 324 | - } |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - $this->stub = str_replace('{{reverseRelationship}}', $functions, $this->stub); |
|
| 326 | + $this->stub = str_replace('{{reverseRelationship}}', $functions, $this->stub); |
|
| 327 | 327 | |
| 328 | 328 | |
| 329 | - return $this; |
|
| 330 | - } |
|
| 329 | + return $this; |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | 332 | |
| 333 | - /** |
|
| 334 | - * Replace eager code for each foreing key with eager = true |
|
| 335 | - * |
|
| 336 | - * @return $this |
|
| 337 | - */ |
|
| 338 | - private function replaceEagerCode() |
|
| 339 | - { |
|
| 340 | - $storeCommands = $updateCommands = $ruleCommands = $useCommands = ''; |
|
| 341 | - $eagerConditions = $eagerJoins = ''; |
|
| 333 | + /** |
|
| 334 | + * Replace eager code for each foreing key with eager = true |
|
| 335 | + * |
|
| 336 | + * @return $this |
|
| 337 | + */ |
|
| 338 | + private function replaceEagerCode() |
|
| 339 | + { |
|
| 340 | + $storeCommands = $updateCommands = $ruleCommands = $useCommands = ''; |
|
| 341 | + $eagerConditions = $eagerJoins = ''; |
|
| 342 | 342 | |
| 343 | - $storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php'); |
|
| 344 | - $updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php'); |
|
| 345 | - $rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php'); |
|
| 346 | - $useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php'); |
|
| 347 | - $joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php'); |
|
| 343 | + $storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php'); |
|
| 344 | + $updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php'); |
|
| 345 | + $rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php'); |
|
| 346 | + $useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php'); |
|
| 347 | + $joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php'); |
|
| 348 | 348 | |
| 349 | - foreach ($this->modelData->fields as $field) |
|
| 350 | - { |
|
| 349 | + foreach ($this->modelData->fields as $field) |
|
| 350 | + { |
|
| 351 | 351 | |
| 352 | - // Check foreign key |
|
| 353 | - if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager) |
|
| 354 | - { |
|
| 355 | - |
|
| 356 | - $storeCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal)); |
|
| 357 | - $updateCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ; |
|
| 358 | - $ruleCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ; |
|
| 359 | - $useCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ; |
|
| 360 | - $eagerJoins .= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ; |
|
| 361 | - |
|
| 362 | - // search eager fields |
|
| 363 | - $foreignModelData = $this->getModelData($field->foreignKey->table); |
|
| 364 | - $foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData); |
|
| 365 | - $foreignControllerCompiler->setEagerTable($this->modelData->tableName); |
|
| 366 | - $eagerConditions .= $foreignControllerCompiler->getSearchConditions(); |
|
| 367 | - $eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules(); |
|
| 368 | - $eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules); |
|
| 369 | - $eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules); |
|
| 370 | - $ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - $this->stub = str_replace('{{store_eager_objects}}', $storeCommands, $this->stub); |
|
| 376 | - $this->stub = str_replace('{{update_eager_objects}}', $updateCommands, $this->stub); |
|
| 377 | - $this->stub = str_replace('{{rules_eager}}', $ruleCommands, $this->stub); |
|
| 378 | - $this->stub = str_replace('{{eager_use_classes}}', $useCommands, $this->stub); |
|
| 379 | - $this->stub = str_replace('{{eager_joins}}', $eagerJoins, $this->stub); |
|
| 380 | - $this->stub = str_replace('{{eager_conditions}}', $eagerConditions, $this->stub); |
|
| 381 | - $this->stub = str_replace('{{eager_table}}', $this->eagerTable, $this->stub); |
|
| 352 | + // Check foreign key |
|
| 353 | + if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager) |
|
| 354 | + { |
|
| 355 | + |
|
| 356 | + $storeCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal)); |
|
| 357 | + $updateCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ; |
|
| 358 | + $ruleCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ; |
|
| 359 | + $useCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ; |
|
| 360 | + $eagerJoins .= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ; |
|
| 361 | + |
|
| 362 | + // search eager fields |
|
| 363 | + $foreignModelData = $this->getModelData($field->foreignKey->table); |
|
| 364 | + $foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData); |
|
| 365 | + $foreignControllerCompiler->setEagerTable($this->modelData->tableName); |
|
| 366 | + $eagerConditions .= $foreignControllerCompiler->getSearchConditions(); |
|
| 367 | + $eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules(); |
|
| 368 | + $eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules); |
|
| 369 | + $eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules); |
|
| 370 | + $ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + $this->stub = str_replace('{{store_eager_objects}}', $storeCommands, $this->stub); |
|
| 376 | + $this->stub = str_replace('{{update_eager_objects}}', $updateCommands, $this->stub); |
|
| 377 | + $this->stub = str_replace('{{rules_eager}}', $ruleCommands, $this->stub); |
|
| 378 | + $this->stub = str_replace('{{eager_use_classes}}', $useCommands, $this->stub); |
|
| 379 | + $this->stub = str_replace('{{eager_joins}}', $eagerJoins, $this->stub); |
|
| 380 | + $this->stub = str_replace('{{eager_conditions}}', $eagerConditions, $this->stub); |
|
| 381 | + $this->stub = str_replace('{{eager_table}}', $this->eagerTable, $this->stub); |
|
| 382 | 382 | |
| 383 | 383 | |
| 384 | 384 | |
| 385 | - return $this; |
|
| 386 | - } |
|
| 385 | + return $this; |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | - /** |
|
| 389 | - * replace relationship tables |
|
| 390 | - * |
|
| 391 | - * @return $this |
|
| 392 | - */ |
|
| 393 | - public function replaceRelationshipTables() { |
|
| 388 | + /** |
|
| 389 | + * replace relationship tables |
|
| 390 | + * |
|
| 391 | + * @return $this |
|
| 392 | + */ |
|
| 393 | + public function replaceRelationshipTables() { |
|
| 394 | 394 | |
| 395 | - $functions = ""; |
|
| 396 | - $functionsCall = ""; |
|
| 397 | - $removeAll = ""; |
|
| 398 | - $removeAllCall = ""; |
|
| 399 | - $includes = ""; |
|
| 400 | - $joins = ""; |
|
| 401 | - $joinSorts = ""; |
|
| 395 | + $functions = ""; |
|
| 396 | + $functionsCall = ""; |
|
| 397 | + $removeAll = ""; |
|
| 398 | + $removeAllCall = ""; |
|
| 399 | + $includes = ""; |
|
| 400 | + $joins = ""; |
|
| 401 | + $joinSorts = ""; |
|
| 402 | 402 | |
| 403 | - $method = File::get($this->stubsDirectory . '/Model/ModelRelationshipTable.php'); |
|
| 403 | + $method = File::get($this->stubsDirectory . '/Model/ModelRelationshipTable.php'); |
|
| 404 | 404 | |
| 405 | - foreach ($this->modelData->reverseRelationships as $relationship) { |
|
| 405 | + foreach ($this->modelData->reverseRelationships as $relationship) { |
|
| 406 | 406 | |
| 407 | - if ($relationship->type == "belongsToMany") { |
|
| 408 | - $relatedTablePluralized = CamelCase::pluralize($relationship->relatedTable); |
|
| 409 | - $relatedTablePluralizedUc = CamelCase::pluralize(CamelCase::convertToCamelCase($relationship->relatedTable)); |
|
| 407 | + if ($relationship->type == "belongsToMany") { |
|
| 408 | + $relatedTablePluralized = CamelCase::pluralize($relationship->relatedTable); |
|
| 409 | + $relatedTablePluralizedUc = CamelCase::pluralize(CamelCase::convertToCamelCase($relationship->relatedTable)); |
|
| 410 | 410 | |
| 411 | - $replacedMethod = ''; |
|
| 412 | - $replacedMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $method); |
|
| 413 | - $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod); |
|
| 414 | - $replacedMethod = str_replace('{{related_table_pl}}', $relatedTablePluralized, $replacedMethod); |
|
| 415 | - $replacedMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $replacedMethod); |
|
| 416 | - $replacedMethod = str_replace('{{related_field}}', $relationship->relatedField, $replacedMethod); |
|
| 417 | - $replacedMethod = str_replace('{{foreign_table_lw}}', strtolower($relationship->modelName), $replacedMethod); |
|
| 418 | - $replacedMethod = str_replace('{{foreign_table}}', $relationship->modelName, $replacedMethod); |
|
| 411 | + $replacedMethod = ''; |
|
| 412 | + $replacedMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $method); |
|
| 413 | + $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod); |
|
| 414 | + $replacedMethod = str_replace('{{related_table_pl}}', $relatedTablePluralized, $replacedMethod); |
|
| 415 | + $replacedMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $replacedMethod); |
|
| 416 | + $replacedMethod = str_replace('{{related_field}}', $relationship->relatedField, $replacedMethod); |
|
| 417 | + $replacedMethod = str_replace('{{foreign_table_lw}}', strtolower($relationship->modelName), $replacedMethod); |
|
| 418 | + $replacedMethod = str_replace('{{foreign_table}}', $relationship->modelName, $replacedMethod); |
|
| 419 | 419 | |
| 420 | - $functions .= $replacedMethod; |
|
| 420 | + $functions .= $replacedMethod; |
|
| 421 | 421 | |
| 422 | - $methodCall = 'if (array_key_exists(\'{{related_table_pl}}\', $vars))'; |
|
| 423 | - $methodCall .= "\n\t\t\t"; |
|
| 424 | - $methodCall .= '$this->save{{related_table_pl_uc}}($vars, ${{class_name_lw}});'; |
|
| 425 | - $methodCall = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $methodCall); |
|
| 426 | - $methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall); |
|
| 427 | - $methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall); |
|
| 422 | + $methodCall = 'if (array_key_exists(\'{{related_table_pl}}\', $vars))'; |
|
| 423 | + $methodCall .= "\n\t\t\t"; |
|
| 424 | + $methodCall .= '$this->save{{related_table_pl_uc}}($vars, ${{class_name_lw}});'; |
|
| 425 | + $methodCall = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $methodCall); |
|
| 426 | + $methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall); |
|
| 427 | + $methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall); |
|
| 428 | 428 | |
| 429 | - $functionsCall .= $methodCall . "\n\t\t"; |
|
| 429 | + $functionsCall .= $methodCall . "\n\t\t"; |
|
| 430 | 430 | |
| 431 | - $removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php'); |
|
| 432 | - $removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod); |
|
| 433 | - $removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod); |
|
| 434 | - $removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod); |
|
| 435 | - $removeAllMethod = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $removeAllMethod); |
|
| 431 | + $removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php'); |
|
| 432 | + $removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod); |
|
| 433 | + $removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod); |
|
| 434 | + $removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod); |
|
| 435 | + $removeAllMethod = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $removeAllMethod); |
|
| 436 | 436 | |
| 437 | - $removeAll .= $removeAllMethod; |
|
| 437 | + $removeAll .= $removeAllMethod; |
|
| 438 | 438 | |
| 439 | - $removeAllCallMethod = '$this->deleteAll{{related_table_pl_uc}}(${{class_name_lw}}[\'id\']);'; |
|
| 440 | - $removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod); |
|
| 441 | - $removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod); |
|
| 439 | + $removeAllCallMethod = '$this->deleteAll{{related_table_pl_uc}}(${{class_name_lw}}[\'id\']);'; |
|
| 440 | + $removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod); |
|
| 441 | + $removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod); |
|
| 442 | 442 | |
| 443 | - $removeAllCall .= $removeAllCallMethod . "\n\t\t"; |
|
| 443 | + $removeAllCall .= $removeAllCallMethod . "\n\t\t"; |
|
| 444 | 444 | |
| 445 | - $joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php'); |
|
| 446 | - $joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub); |
|
| 447 | - $joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub); |
|
| 448 | - $joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub); |
|
| 449 | - $joinRelationshipTableStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $joinRelationshipTableStub); |
|
| 450 | - $joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub); |
|
| 451 | - $joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub); |
|
| 445 | + $joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php'); |
|
| 446 | + $joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub); |
|
| 447 | + $joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub); |
|
| 448 | + $joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub); |
|
| 449 | + $joinRelationshipTableStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $joinRelationshipTableStub); |
|
| 450 | + $joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub); |
|
| 451 | + $joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub); |
|
| 452 | 452 | |
| 453 | - $joins .= $joinRelationshipTableStub . "\n"; |
|
| 453 | + $joins .= $joinRelationshipTableStub . "\n"; |
|
| 454 | 454 | |
| 455 | - $use = 'use App\Models\{{foreign_table}};'; |
|
| 456 | - $use = str_replace('{{foreign_table}}', $relationship->modelName, $use); |
|
| 455 | + $use = 'use App\Models\{{foreign_table}};'; |
|
| 456 | + $use = str_replace('{{foreign_table}}', $relationship->modelName, $use); |
|
| 457 | 457 | |
| 458 | - $includes .= $use . "\n"; |
|
| 459 | - } |
|
| 460 | - } |
|
| 458 | + $includes .= $use . "\n"; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | 461 | |
| 462 | - $this->stub = str_replace('{{relationship_tables_store}}', $functions, $this->stub); |
|
| 462 | + $this->stub = str_replace('{{relationship_tables_store}}', $functions, $this->stub); |
|
| 463 | 463 | |
| 464 | - $this->stub = str_replace('{{relationship_tables_call}}', $functionsCall, $this->stub); |
|
| 464 | + $this->stub = str_replace('{{relationship_tables_call}}', $functionsCall, $this->stub); |
|
| 465 | 465 | |
| 466 | - $this->stub = str_replace('{{remove_relationship_objects}}', $removeAll, $this->stub); |
|
| 466 | + $this->stub = str_replace('{{remove_relationship_objects}}', $removeAll, $this->stub); |
|
| 467 | 467 | |
| 468 | - $this->stub = str_replace('{{remove_relationship_objects_call}}', $removeAllCall, $this->stub); |
|
| 468 | + $this->stub = str_replace('{{remove_relationship_objects_call}}', $removeAllCall, $this->stub); |
|
| 469 | 469 | |
| 470 | - $this->stub = str_replace('{{relationship_tables_classes}}', $includes, $this->stub); |
|
| 470 | + $this->stub = str_replace('{{relationship_tables_classes}}', $includes, $this->stub); |
|
| 471 | 471 | |
| 472 | - $this->stub = str_replace('{{relationship_tables_joins}}', $joins, $this->stub); |
|
| 472 | + $this->stub = str_replace('{{relationship_tables_joins}}', $joins, $this->stub); |
|
| 473 | 473 | |
| 474 | 474 | |
| 475 | 475 | |
| 476 | - return $this; |
|
| 476 | + return $this; |
|
| 477 | 477 | |
| 478 | - } |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | 480 | |
| 481 | - /** |
|
| 482 | - * Replace search conditions |
|
| 483 | - * |
|
| 484 | - * @return $this |
|
| 485 | - */ |
|
| 486 | - private function replaceSearchConditions(){ |
|
| 481 | + /** |
|
| 482 | + * Replace search conditions |
|
| 483 | + * |
|
| 484 | + * @return $this |
|
| 485 | + */ |
|
| 486 | + private function replaceSearchConditions(){ |
|
| 487 | 487 | |
| 488 | - $searchConditions = $this->getSearchConditions(); |
|
| 488 | + $searchConditions = $this->getSearchConditions(); |
|
| 489 | 489 | |
| 490 | - $this->stub = str_replace('{{conditions}}', $searchConditions, $this->stub); |
|
| 490 | + $this->stub = str_replace('{{conditions}}', $searchConditions, $this->stub); |
|
| 491 | 491 | |
| 492 | - return $this; |
|
| 493 | - } |
|
| 492 | + return $this; |
|
| 493 | + } |
|
| 494 | 494 | |
| 495 | - /** |
|
| 496 | - * get search conditions |
|
| 497 | - * |
|
| 498 | - * @return $this |
|
| 499 | - */ |
|
| 500 | - public function getSearchConditions(){ |
|
| 495 | + /** |
|
| 496 | + * get search conditions |
|
| 497 | + * |
|
| 498 | + * @return $this |
|
| 499 | + */ |
|
| 500 | + public function getSearchConditions(){ |
|
| 501 | 501 | |
| 502 | - $fieldConditions = ''; |
|
| 502 | + $fieldConditions = ''; |
|
| 503 | 503 | |
| 504 | - $searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php'); |
|
| 504 | + $searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php'); |
|
| 505 | 505 | |
| 506 | - foreach ($this->modelData->fields as $field) |
|
| 507 | - { |
|
| 506 | + foreach ($this->modelData->fields as $field) |
|
| 507 | + { |
|
| 508 | 508 | |
| 509 | - $fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ; |
|
| 509 | + $fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ; |
|
| 510 | 510 | |
| 511 | - } |
|
| 511 | + } |
|
| 512 | 512 | |
| 513 | - // replace all field conditions |
|
| 514 | - $searchConditions = str_replace('{{field_conditions}}', $fieldConditions, $searchConditions); |
|
| 513 | + // replace all field conditions |
|
| 514 | + $searchConditions = str_replace('{{field_conditions}}', $fieldConditions, $searchConditions); |
|
| 515 | 515 | |
| 516 | - // replace table name |
|
| 517 | - $searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions); |
|
| 516 | + // replace table name |
|
| 517 | + $searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions); |
|
| 518 | 518 | |
| 519 | - return $searchConditions ; |
|
| 519 | + return $searchConditions ; |
|
| 520 | 520 | |
| 521 | - } |
|
| 521 | + } |
|
| 522 | 522 | |
| 523 | - /** |
|
| 524 | - * get search conditions stub by db type |
|
| 525 | - * |
|
| 526 | - * @param string $field |
|
| 527 | - * |
|
| 528 | - * @return $this |
|
| 529 | - */ |
|
| 530 | - private $conditionsStub = []; |
|
| 531 | - private function getConditionStubByField($field){ |
|
| 523 | + /** |
|
| 524 | + * get search conditions stub by db type |
|
| 525 | + * |
|
| 526 | + * @param string $field |
|
| 527 | + * |
|
| 528 | + * @return $this |
|
| 529 | + */ |
|
| 530 | + private $conditionsStub = []; |
|
| 531 | + private function getConditionStubByField($field){ |
|
| 532 | 532 | |
| 533 | - if($field->index == 'primary'){ |
|
| 534 | - $dbType = 'primary' ; |
|
| 535 | - } |
|
| 536 | - elseif($field->foreignKey){ |
|
| 537 | - $dbType = 'primary' ; |
|
| 538 | - } |
|
| 539 | - elseif($field->type->db == 'enum'){ |
|
| 540 | - $dbType = 'primary' ; |
|
| 541 | - } |
|
| 542 | - elseif($field->type->db == 'boolean'){ |
|
| 543 | - $dbType = 'primary' ; |
|
| 544 | - } |
|
| 545 | - elseif($field->type->db == 'text'){ |
|
| 546 | - $dbType = 'string' ; |
|
| 547 | - } |
|
| 548 | - else { |
|
| 549 | - $dbType = $field->type->db ; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - if(array_key_exists($dbType, $this->conditionsStub)){ |
|
| 553 | - return $this->conditionsStub[$dbType]; |
|
| 554 | - } |
|
| 555 | - else { |
|
| 556 | - $this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');; |
|
| 557 | - |
|
| 558 | - return $this->conditionsStub[$dbType]; |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - public function replaceSortConditions() { |
|
| 563 | - $joinSorts = ''; |
|
| 564 | - |
|
| 565 | - foreach ($this->modelData->fields as $field) { |
|
| 566 | - if($field->foreignKey){ |
|
| 567 | - $joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php'); |
|
| 568 | - $joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub); |
|
| 569 | - $joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub); |
|
| 570 | - $joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub); |
|
| 571 | - $joinSorts .= $joinSortStub; |
|
| 572 | - |
|
| 573 | - } |
|
| 533 | + if($field->index == 'primary'){ |
|
| 534 | + $dbType = 'primary' ; |
|
| 535 | + } |
|
| 536 | + elseif($field->foreignKey){ |
|
| 537 | + $dbType = 'primary' ; |
|
| 538 | + } |
|
| 539 | + elseif($field->type->db == 'enum'){ |
|
| 540 | + $dbType = 'primary' ; |
|
| 541 | + } |
|
| 542 | + elseif($field->type->db == 'boolean'){ |
|
| 543 | + $dbType = 'primary' ; |
|
| 544 | + } |
|
| 545 | + elseif($field->type->db == 'text'){ |
|
| 546 | + $dbType = 'string' ; |
|
| 547 | + } |
|
| 548 | + else { |
|
| 549 | + $dbType = $field->type->db ; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + if(array_key_exists($dbType, $this->conditionsStub)){ |
|
| 553 | + return $this->conditionsStub[$dbType]; |
|
| 554 | + } |
|
| 555 | + else { |
|
| 556 | + $this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');; |
|
| 557 | + |
|
| 558 | + return $this->conditionsStub[$dbType]; |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + public function replaceSortConditions() { |
|
| 563 | + $joinSorts = ''; |
|
| 564 | + |
|
| 565 | + foreach ($this->modelData->fields as $field) { |
|
| 566 | + if($field->foreignKey){ |
|
| 567 | + $joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php'); |
|
| 568 | + $joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub); |
|
| 569 | + $joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub); |
|
| 570 | + $joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub); |
|
| 571 | + $joinSorts .= $joinSortStub; |
|
| 572 | + |
|
| 573 | + } |
|
| 574 | 574 | |
| 575 | 575 | |
| 576 | 576 | |
| 577 | - } |
|
| 577 | + } |
|
| 578 | 578 | |
| 579 | 579 | |
| 580 | - $this->stub = str_replace('{{relationship_tables_joins_sort}}', $joinSorts, $this->stub); |
|
| 580 | + $this->stub = str_replace('{{relationship_tables_joins_sort}}', $joinSorts, $this->stub); |
|
| 581 | 581 | |
| 582 | - return $this; |
|
| 583 | - } |
|
| 582 | + return $this; |
|
| 583 | + } |
|
| 584 | 584 | |
| 585 | 585 | |
| 586 | 586 | |
| 587 | - /** |
|
| 588 | - * replace reverse relationships |
|
| 589 | - * |
|
| 590 | - * @return $this |
|
| 591 | - */ |
|
| 592 | - public function replaceReverseRelationshipsFunctions(){ |
|
| 587 | + /** |
|
| 588 | + * replace reverse relationships |
|
| 589 | + * |
|
| 590 | + * @return $this |
|
| 591 | + */ |
|
| 592 | + public function replaceReverseRelationshipsFunctions(){ |
|
| 593 | 593 | |
| 594 | - $functions = ''; |
|
| 594 | + $functions = ''; |
|
| 595 | 595 | |
| 596 | - $method = File::get($this->stubsDirectory . '/Model/ModelReverseRelationshipFunctions.php'); |
|
| 596 | + $method = File::get($this->stubsDirectory . '/Model/ModelReverseRelationshipFunctions.php'); |
|
| 597 | 597 | |
| 598 | - foreach ($this->modelData->reverseRelationships as $relationship) |
|
| 599 | - { |
|
| 600 | - $functionName = ''; |
|
| 601 | - if ($relationship->type == "hasOne") |
|
| 602 | - $functionName = strtolower($relationship->modelName); |
|
| 603 | - elseif ($relationship->type == "belongsToMany") |
|
| 604 | - $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); |
|
| 605 | - else |
|
| 606 | - $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 598 | + foreach ($this->modelData->reverseRelationships as $relationship) |
|
| 599 | + { |
|
| 600 | + $functionName = ''; |
|
| 601 | + if ($relationship->type == "hasOne") |
|
| 602 | + $functionName = strtolower($relationship->modelName); |
|
| 603 | + elseif ($relationship->type == "belongsToMany") |
|
| 604 | + $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); |
|
| 605 | + else |
|
| 606 | + $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 607 | 607 | |
| 608 | - $replacedMethod = ''; |
|
| 609 | - $replacedMethod = str_replace('{{function_name}}', $functionName, $method); |
|
| 610 | - $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod); |
|
| 611 | - $replacedMethod = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $replacedMethod); |
|
| 608 | + $replacedMethod = ''; |
|
| 609 | + $replacedMethod = str_replace('{{function_name}}', $functionName, $method); |
|
| 610 | + $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod); |
|
| 611 | + $replacedMethod = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $replacedMethod); |
|
| 612 | 612 | |
| 613 | - $functions .= $replacedMethod; |
|
| 614 | - } |
|
| 613 | + $functions .= $replacedMethod; |
|
| 614 | + } |
|
| 615 | 615 | |
| 616 | - $this->stub = str_replace('{{reverseRelationshipFunctions}}', $functions, $this->stub); |
|
| 616 | + $this->stub = str_replace('{{reverseRelationshipFunctions}}', $functions, $this->stub); |
|
| 617 | 617 | |
| 618 | - return $this; |
|
| 618 | + return $this; |
|
| 619 | 619 | |
| 620 | - } |
|
| 620 | + } |
|
| 621 | 621 | |
| 622 | 622 | |
| 623 | - /** |
|
| 624 | - * replace checkbox fields |
|
| 625 | - * |
|
| 626 | - * @return $this |
|
| 627 | - */ |
|
| 628 | - public function replaceCheckbox(){ |
|
| 623 | + /** |
|
| 624 | + * replace checkbox fields |
|
| 625 | + * |
|
| 626 | + * @return $this |
|
| 627 | + */ |
|
| 628 | + public function replaceCheckbox(){ |
|
| 629 | 629 | |
| 630 | - $method = File::get($this->stubsDirectory . '/Model/ModelCheckbox.php'); |
|
| 631 | - $key = false; |
|
| 630 | + $method = File::get($this->stubsDirectory . '/Model/ModelCheckbox.php'); |
|
| 631 | + $key = false; |
|
| 632 | 632 | |
| 633 | - $method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method); |
|
| 634 | - $method = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $method); |
|
| 635 | - $method = str_replace('{{model_name}}', $this->modelData->modelName, $method); |
|
| 636 | - $this->stub = str_replace('{{checkbox}}', $method, $this->stub); |
|
| 633 | + $method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method); |
|
| 634 | + $method = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $method); |
|
| 635 | + $method = str_replace('{{model_name}}', $this->modelData->modelName, $method); |
|
| 636 | + $this->stub = str_replace('{{checkbox}}', $method, $this->stub); |
|
| 637 | 637 | |
| 638 | - return $this; |
|
| 638 | + return $this; |
|
| 639 | 639 | |
| 640 | - } |
|
| 640 | + } |
|
| 641 | 641 | |
| 642 | 642 | |
| 643 | - /** |
|
| 644 | - * Replace simple filter |
|
| 645 | - * |
|
| 646 | - * @return $this |
|
| 647 | - */ |
|
| 648 | - private function replaceSimpleFilter(){ |
|
| 649 | - $i = 0; |
|
| 643 | + /** |
|
| 644 | + * Replace simple filter |
|
| 645 | + * |
|
| 646 | + * @return $this |
|
| 647 | + */ |
|
| 648 | + private function replaceSimpleFilter(){ |
|
| 649 | + $i = 0; |
|
| 650 | 650 | |
| 651 | - $stubSimpleFilter = ''; |
|
| 651 | + $stubSimpleFilter = ''; |
|
| 652 | 652 | |
| 653 | - foreach ($this->modelData->fields as $field) |
|
| 654 | - { |
|
| 655 | - //var_dump($field->name); |
|
| 653 | + foreach ($this->modelData->fields as $field) |
|
| 654 | + { |
|
| 655 | + //var_dump($field->name); |
|
| 656 | 656 | |
| 657 | - if($field->index == 'primary'){ |
|
| 658 | - $dbType = 'primaryKey' ; |
|
| 659 | - } |
|
| 660 | - elseif($field->foreignKey){ |
|
| 661 | - $dbType = 'primary' ; |
|
| 662 | - } |
|
| 663 | - elseif($field->type->db == 'enum'){ |
|
| 664 | - $dbType = 'primary' ; |
|
| 665 | - } |
|
| 666 | - elseif($field->type->db == 'boolean'){ |
|
| 667 | - $dbType = 'primary' ; |
|
| 668 | - } |
|
| 669 | - elseif($field->type->db == 'text'){ |
|
| 670 | - $dbType = 'string' ; |
|
| 671 | - } |
|
| 672 | - else { |
|
| 673 | - $dbType = $field->type->db ; |
|
| 674 | - } |
|
| 657 | + if($field->index == 'primary'){ |
|
| 658 | + $dbType = 'primaryKey' ; |
|
| 659 | + } |
|
| 660 | + elseif($field->foreignKey){ |
|
| 661 | + $dbType = 'primary' ; |
|
| 662 | + } |
|
| 663 | + elseif($field->type->db == 'enum'){ |
|
| 664 | + $dbType = 'primary' ; |
|
| 665 | + } |
|
| 666 | + elseif($field->type->db == 'boolean'){ |
|
| 667 | + $dbType = 'primary' ; |
|
| 668 | + } |
|
| 669 | + elseif($field->type->db == 'text'){ |
|
| 670 | + $dbType = 'string' ; |
|
| 671 | + } |
|
| 672 | + else { |
|
| 673 | + $dbType = $field->type->db ; |
|
| 674 | + } |
|
| 675 | 675 | |
| 676 | - if($dbType == 'primaryKey') |
|
| 677 | - { |
|
| 678 | - $stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - if($dbType == 'primary') |
|
| 682 | - { |
|
| 683 | - $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - if($dbType == 'string') |
|
| 687 | - { |
|
| 688 | - $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number') |
|
| 692 | - { |
|
| 693 | - $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - } |
|
| 697 | - $stubSimpleFilter .= ';'; |
|
| 698 | - $this->stub = str_replace('{{simple_filter}}', $stubSimpleFilter, $this->stub); |
|
| 699 | - |
|
| 700 | - return $this; |
|
| 701 | - } |
|
| 676 | + if($dbType == 'primaryKey') |
|
| 677 | + { |
|
| 678 | + $stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + if($dbType == 'primary') |
|
| 682 | + { |
|
| 683 | + $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + if($dbType == 'string') |
|
| 687 | + { |
|
| 688 | + $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number') |
|
| 692 | + { |
|
| 693 | + $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + } |
|
| 697 | + $stubSimpleFilter .= ';'; |
|
| 698 | + $this->stub = str_replace('{{simple_filter}}', $stubSimpleFilter, $this->stub); |
|
| 699 | + |
|
| 700 | + return $this; |
|
| 701 | + } |
|
| 702 | 702 | } |
| 703 | 703 | \ No newline at end of file |
@@ -12,13 +12,13 @@ discard block |
||
| 12 | 12 | class ModelCompiler extends AbstractCompiler |
| 13 | 13 | { |
| 14 | 14 | protected $cachePrefix = 'model_'; |
| 15 | - protected $stubFilename = 'Model/Model.php' ; |
|
| 15 | + protected $stubFilename = 'Model/Model.php'; |
|
| 16 | 16 | |
| 17 | 17 | public function __construct($scaffolderConfig, $modelData = null, $stubName = null) |
| 18 | 18 | { |
| 19 | 19 | if ($stubName) |
| 20 | 20 | $this->stubFilename = $stubName; |
| 21 | - $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
|
| 21 | + $this->stubsDirectory = __DIR__.'/../../../../stubs/Api/'; |
|
| 22 | 22 | parent::__construct($scaffolderConfig, $modelData); |
| 23 | 23 | } |
| 24 | 24 | |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | protected function getOutputFilename() |
| 60 | 60 | { |
| 61 | - $folder = PathParser::parse($this->scaffolderConfig->generator->paths->models) ; |
|
| 61 | + $folder = PathParser::parse($this->scaffolderConfig->generator->paths->models); |
|
| 62 | 62 | |
| 63 | - return $folder . $this->modelName . '.php'; |
|
| 63 | + return $folder.$this->modelName.'.php'; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | |
@@ -91,21 +91,21 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | foreach ($this->modelData->fields as $field) |
| 93 | 93 | { |
| 94 | - if($field->index == "primary") |
|
| 95 | - continue ; |
|
| 96 | - if($this->modelData->timeStamps && $field->name == "created_at") |
|
| 97 | - continue ; |
|
| 98 | - if($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 99 | - continue ; |
|
| 94 | + if ($field->index == "primary") |
|
| 95 | + continue; |
|
| 96 | + if ($this->modelData->timeStamps && $field->name == "created_at") |
|
| 97 | + continue; |
|
| 98 | + if ($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 99 | + continue; |
|
| 100 | 100 | |
| 101 | 101 | if ($firstIteration) |
| 102 | 102 | { |
| 103 | - $fields .= sprintf("'%s'," . PHP_EOL, $field->name); |
|
| 103 | + $fields .= sprintf("'%s',".PHP_EOL, $field->name); |
|
| 104 | 104 | $firstIteration = false; |
| 105 | 105 | } |
| 106 | 106 | else |
| 107 | 107 | { |
| 108 | - $fields .= sprintf("\t\t'%s'," . PHP_EOL, $field->name); |
|
| 108 | + $fields .= sprintf("\t\t'%s',".PHP_EOL, $field->name); |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | $arrays = ''; |
| 121 | 121 | |
| 122 | 122 | foreach ($this->modelData->fields as $field) { |
| 123 | - $enumStub = File::get($this->stubsDirectory . '/Model/ModelEnum.php'); |
|
| 123 | + $enumStub = File::get($this->stubsDirectory.'/Model/ModelEnum.php'); |
|
| 124 | 124 | |
| 125 | 125 | if ($field->type->db == "enum") { |
| 126 | 126 | $items = ''; |
| 127 | 127 | |
| 128 | 128 | foreach ($field->options as $key => $option) { |
| 129 | - $items .= "'" . $option . "'"; |
|
| 129 | + $items .= "'".$option."'"; |
|
| 130 | 130 | if ($key < (count($field->options) - 1)) |
| 131 | 131 | $items .= ", "; |
| 132 | 132 | |
@@ -160,25 +160,25 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | foreach ($this->modelData->fields as $field) |
| 162 | 162 | { |
| 163 | - if($field->index == "primary") |
|
| 164 | - continue ; |
|
| 165 | - if($this->modelData->timeStamps && $field->name == "created_at") |
|
| 166 | - continue ; |
|
| 167 | - if($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 168 | - continue ; |
|
| 163 | + if ($field->index == "primary") |
|
| 164 | + continue; |
|
| 165 | + if ($this->modelData->timeStamps && $field->name == "created_at") |
|
| 166 | + continue; |
|
| 167 | + if ($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 168 | + continue; |
|
| 169 | 169 | |
| 170 | 170 | if ($firstIteration) |
| 171 | 171 | { |
| 172 | - $fields .= sprintf("'%s' => '%s'," . PHP_EOL, $field->name, $field->validations); |
|
| 172 | + $fields .= sprintf("'%s' => '%s',".PHP_EOL, $field->name, $field->validations); |
|
| 173 | 173 | $firstIteration = false; |
| 174 | 174 | } |
| 175 | 175 | else |
| 176 | 176 | { |
| 177 | - $fields .= sprintf("\t\t\t'%s' => '%s'," . PHP_EOL, $field->name, $field->validations); |
|
| 177 | + $fields .= sprintf("\t\t\t'%s' => '%s',".PHP_EOL, $field->name, $field->validations); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - $fields = str_replace('unique','unique:'.$this->modelData->tableName,$fields); |
|
| 181 | + $fields = str_replace('unique', 'unique:'.$this->modelData->tableName, $fields); |
|
| 182 | 182 | //var_dump($fields); |
| 183 | 183 | |
| 184 | 184 | $this->stub = str_replace('{{validations}}', $fields, $this->stub); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | private function setTimeStamps() |
| 194 | 194 | { |
| 195 | - if($this->modelData->timeStamps) |
|
| 195 | + if ($this->modelData->timeStamps) |
|
| 196 | 196 | { |
| 197 | 197 | $this->stub = str_replace('{{timestamps}}', ' ', $this->stub); |
| 198 | 198 | } else { |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | private function setPrimaryKey() |
| 210 | 210 | { |
| 211 | - $primaryKey = '// Using default primary key' . PHP_EOL; |
|
| 211 | + $primaryKey = '// Using default primary key'.PHP_EOL; |
|
| 212 | 212 | |
| 213 | - $field = $this->getPrimaryKeyField() ; |
|
| 213 | + $field = $this->getPrimaryKeyField(); |
|
| 214 | 214 | |
| 215 | - $primaryKey = 'protected $primaryKey = \'' . $field->name . '\';' . PHP_EOL; |
|
| 215 | + $primaryKey = 'protected $primaryKey = \''.$field->name.'\';'.PHP_EOL; |
|
| 216 | 216 | |
| 217 | 217 | $this->stub = str_replace('{{primaryAttribute}}', $primaryKey, $this->stub); |
| 218 | 218 | |
@@ -241,13 +241,13 @@ discard block |
||
| 241 | 241 | $functionName = $field->foreignKey->table; |
| 242 | 242 | |
| 243 | 243 | if ($field->foreignKey->relationship == "belongsTo") { |
| 244 | - $belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsTo.php'); |
|
| 244 | + $belongsToOriginalStub = File::get($this->stubsDirectory.'/Model/ModelBelongsTo.php'); |
|
| 245 | 245 | $belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub); |
| 246 | 246 | $belongsToStub = str_replace('{{field}}', $field->name, $belongsToStub); |
| 247 | 247 | $belongsToStub = str_replace('{{foreign_field}}', $field->foreignKey->field, $belongsToStub); |
| 248 | 248 | } |
| 249 | 249 | elseif ($field->foreignKey->relationship == "belongsToMany") { |
| 250 | - $belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php'); |
|
| 250 | + $belongsToOriginalStub = File::get($this->stubsDirectory.'/Model/ModelBelongsToMany.php'); |
|
| 251 | 251 | $functionName = CamelCase::pluralize($field->foreignKey->table); |
| 252 | 252 | $belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub); |
| 253 | 253 | $belongsToStub = str_replace('{{foreign_key}}', $field->name, $belongsToStub); |
@@ -258,9 +258,9 @@ discard block |
||
| 258 | 258 | $belongsToStub = str_replace('{{foreign_table}}', $functionName, $belongsToStub); |
| 259 | 259 | $belongsToStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $belongsToStub); |
| 260 | 260 | |
| 261 | - $functions .= $belongsToStub ; |
|
| 261 | + $functions .= $belongsToStub; |
|
| 262 | 262 | |
| 263 | - if(isset($field->foreignKey->eager) && $field->foreignKey->eager){ |
|
| 263 | + if (isset($field->foreignKey->eager) && $field->foreignKey->eager) { |
|
| 264 | 264 | array_push($eagerArray, "'".$field->foreignKey->table."'"); |
| 265 | 265 | } |
| 266 | 266 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | |
| 271 | 271 | $this->stub = str_replace('{{belongsTo}}', $functions, $this->stub); |
| 272 | 272 | |
| 273 | - $this->stub = str_replace('{{eager}}', join("," , $eagerArray) , $this->stub); |
|
| 273 | + $this->stub = str_replace('{{eager}}', join(",", $eagerArray), $this->stub); |
|
| 274 | 274 | |
| 275 | 275 | return $this; |
| 276 | 276 | } |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
| 296 | 296 | |
| 297 | 297 | if ($relationship->type == "belongsToMany") { |
| 298 | - $reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php'); |
|
| 298 | + $reverseRelationshipOriginalStub = File::get($this->stubsDirectory.'/Model/ModelBelongsToMany.php'); |
|
| 299 | 299 | $reverseRelationshipStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($relationship->relatedTable), $reverseRelationshipOriginalStub); |
| 300 | 300 | $reverseRelationshipStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $reverseRelationshipStub); |
| 301 | 301 | $reverseRelationshipStub = str_replace('{{table_name}}', $relationship->tableName, $reverseRelationshipStub); |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | $reverseRelationshipStub = str_replace('{{foreign_table}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $reverseRelationshipStub); |
| 304 | 304 | } |
| 305 | 305 | else { |
| 306 | - $reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelReverseRelationship.php'); |
|
| 306 | + $reverseRelationshipOriginalStub = File::get($this->stubsDirectory.'/Model/ModelReverseRelationship.php'); |
|
| 307 | 307 | $reverseRelationshipStub = str_replace('{{foreign_model}}', $relationship->modelName, $reverseRelationshipOriginalStub); |
| 308 | 308 | $reverseRelationshipStub = str_replace('{{field}}', $relationship->foreignKey, $reverseRelationshipStub); |
| 309 | 309 | $reverseRelationshipStub = str_replace('{{foreign_field}}', $relationship->localKey, $reverseRelationshipStub); |
@@ -313,9 +313,9 @@ discard block |
||
| 313 | 313 | |
| 314 | 314 | $reverseRelationshipStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $reverseRelationshipStub); |
| 315 | 315 | |
| 316 | - $functions .= $reverseRelationshipStub ; |
|
| 316 | + $functions .= $reverseRelationshipStub; |
|
| 317 | 317 | |
| 318 | - if(isset($relationship->foreignKey->eager) && $relationship->foreignKey->eager){ |
|
| 318 | + if (isset($relationship->foreignKey->eager) && $relationship->foreignKey->eager) { |
|
| 319 | 319 | array_push($eagerArray, "'".$relationship->foreignKey->table."'"); |
| 320 | 320 | } |
| 321 | 321 | } |
@@ -340,11 +340,11 @@ discard block |
||
| 340 | 340 | $storeCommands = $updateCommands = $ruleCommands = $useCommands = ''; |
| 341 | 341 | $eagerConditions = $eagerJoins = ''; |
| 342 | 342 | |
| 343 | - $storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php'); |
|
| 344 | - $updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php'); |
|
| 345 | - $rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php'); |
|
| 346 | - $useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php'); |
|
| 347 | - $joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php'); |
|
| 343 | + $storeEagerStubOriginal = File::get($this->stubsDirectory.'StoreEager.php'); |
|
| 344 | + $updateEagerStubOriginal = File::get($this->stubsDirectory.'UpdateEager.php'); |
|
| 345 | + $rulesEagerStubOriginal = File::get($this->stubsDirectory.'RulesEager.php'); |
|
| 346 | + $useEagerStubOriginal = File::get($this->stubsDirectory.'UseEager.php'); |
|
| 347 | + $joinEagerStubOriginal = File::get($this->stubsDirectory.'SearchConditions/JoinEager.php'); |
|
| 348 | 348 | |
| 349 | 349 | foreach ($this->modelData->fields as $field) |
| 350 | 350 | { |
@@ -354,20 +354,20 @@ discard block |
||
| 354 | 354 | { |
| 355 | 355 | |
| 356 | 356 | $storeCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal)); |
| 357 | - $updateCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ; |
|
| 358 | - $ruleCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ; |
|
| 359 | - $useCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ; |
|
| 360 | - $eagerJoins .= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ; |
|
| 357 | + $updateCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)); |
|
| 358 | + $ruleCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)); |
|
| 359 | + $useCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)); |
|
| 360 | + $eagerJoins .= $this->replaceForeingStrings($field, $joinEagerStubOriginal); |
|
| 361 | 361 | |
| 362 | 362 | // search eager fields |
| 363 | 363 | $foreignModelData = $this->getModelData($field->foreignKey->table); |
| 364 | 364 | $foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData); |
| 365 | 365 | $foreignControllerCompiler->setEagerTable($this->modelData->tableName); |
| 366 | - $eagerConditions .= $foreignControllerCompiler->getSearchConditions(); |
|
| 366 | + $eagerConditions .= $foreignControllerCompiler->getSearchConditions(); |
|
| 367 | 367 | $eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules(); |
| 368 | 368 | $eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules); |
| 369 | 369 | $eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules); |
| 370 | - $ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ; |
|
| 370 | + $ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | } |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | $joins = ""; |
| 401 | 401 | $joinSorts = ""; |
| 402 | 402 | |
| 403 | - $method = File::get($this->stubsDirectory . '/Model/ModelRelationshipTable.php'); |
|
| 403 | + $method = File::get($this->stubsDirectory.'/Model/ModelRelationshipTable.php'); |
|
| 404 | 404 | |
| 405 | 405 | foreach ($this->modelData->reverseRelationships as $relationship) { |
| 406 | 406 | |
@@ -426,9 +426,9 @@ discard block |
||
| 426 | 426 | $methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall); |
| 427 | 427 | $methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall); |
| 428 | 428 | |
| 429 | - $functionsCall .= $methodCall . "\n\t\t"; |
|
| 429 | + $functionsCall .= $methodCall."\n\t\t"; |
|
| 430 | 430 | |
| 431 | - $removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php'); |
|
| 431 | + $removeAllMethod = File::get($this->stubsDirectory.'/Controller/ControllerRemoveAll.php'); |
|
| 432 | 432 | $removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod); |
| 433 | 433 | $removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod); |
| 434 | 434 | $removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod); |
@@ -440,9 +440,9 @@ discard block |
||
| 440 | 440 | $removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod); |
| 441 | 441 | $removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod); |
| 442 | 442 | |
| 443 | - $removeAllCall .= $removeAllCallMethod . "\n\t\t"; |
|
| 443 | + $removeAllCall .= $removeAllCallMethod."\n\t\t"; |
|
| 444 | 444 | |
| 445 | - $joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php'); |
|
| 445 | + $joinRelationshipTableStub = File::get($this->stubsDirectory.'SearchConditions/joinRelationshipTable.php'); |
|
| 446 | 446 | $joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub); |
| 447 | 447 | $joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub); |
| 448 | 448 | $joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub); |
@@ -450,12 +450,12 @@ discard block |
||
| 450 | 450 | $joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub); |
| 451 | 451 | $joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub); |
| 452 | 452 | |
| 453 | - $joins .= $joinRelationshipTableStub . "\n"; |
|
| 453 | + $joins .= $joinRelationshipTableStub."\n"; |
|
| 454 | 454 | |
| 455 | 455 | $use = 'use App\Models\{{foreign_table}};'; |
| 456 | 456 | $use = str_replace('{{foreign_table}}', $relationship->modelName, $use); |
| 457 | 457 | |
| 458 | - $includes .= $use . "\n"; |
|
| 458 | + $includes .= $use."\n"; |
|
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | * |
| 484 | 484 | * @return $this |
| 485 | 485 | */ |
| 486 | - private function replaceSearchConditions(){ |
|
| 486 | + private function replaceSearchConditions() { |
|
| 487 | 487 | |
| 488 | 488 | $searchConditions = $this->getSearchConditions(); |
| 489 | 489 | |
@@ -497,16 +497,16 @@ discard block |
||
| 497 | 497 | * |
| 498 | 498 | * @return $this |
| 499 | 499 | */ |
| 500 | - public function getSearchConditions(){ |
|
| 500 | + public function getSearchConditions() { |
|
| 501 | 501 | |
| 502 | 502 | $fieldConditions = ''; |
| 503 | 503 | |
| 504 | - $searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php'); |
|
| 504 | + $searchConditions = File::get($this->stubsDirectory.'/SearchConditions/Conditions.php'); |
|
| 505 | 505 | |
| 506 | 506 | foreach ($this->modelData->fields as $field) |
| 507 | 507 | { |
| 508 | 508 | |
| 509 | - $fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ; |
|
| 509 | + $fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)); |
|
| 510 | 510 | |
| 511 | 511 | } |
| 512 | 512 | |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | // replace table name |
| 517 | 517 | $searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions); |
| 518 | 518 | |
| 519 | - return $searchConditions ; |
|
| 519 | + return $searchConditions; |
|
| 520 | 520 | |
| 521 | 521 | } |
| 522 | 522 | |
@@ -528,43 +528,43 @@ discard block |
||
| 528 | 528 | * @return $this |
| 529 | 529 | */ |
| 530 | 530 | private $conditionsStub = []; |
| 531 | - private function getConditionStubByField($field){ |
|
| 531 | + private function getConditionStubByField($field) { |
|
| 532 | 532 | |
| 533 | - if($field->index == 'primary'){ |
|
| 534 | - $dbType = 'primary' ; |
|
| 533 | + if ($field->index == 'primary') { |
|
| 534 | + $dbType = 'primary'; |
|
| 535 | 535 | } |
| 536 | - elseif($field->foreignKey){ |
|
| 537 | - $dbType = 'primary' ; |
|
| 536 | + elseif ($field->foreignKey) { |
|
| 537 | + $dbType = 'primary'; |
|
| 538 | 538 | } |
| 539 | - elseif($field->type->db == 'enum'){ |
|
| 540 | - $dbType = 'primary' ; |
|
| 539 | + elseif ($field->type->db == 'enum') { |
|
| 540 | + $dbType = 'primary'; |
|
| 541 | 541 | } |
| 542 | - elseif($field->type->db == 'boolean'){ |
|
| 543 | - $dbType = 'primary' ; |
|
| 542 | + elseif ($field->type->db == 'boolean') { |
|
| 543 | + $dbType = 'primary'; |
|
| 544 | 544 | } |
| 545 | - elseif($field->type->db == 'text'){ |
|
| 546 | - $dbType = 'string' ; |
|
| 545 | + elseif ($field->type->db == 'text') { |
|
| 546 | + $dbType = 'string'; |
|
| 547 | 547 | } |
| 548 | 548 | else { |
| 549 | - $dbType = $field->type->db ; |
|
| 549 | + $dbType = $field->type->db; |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - if(array_key_exists($dbType, $this->conditionsStub)){ |
|
| 552 | + if (array_key_exists($dbType, $this->conditionsStub)) { |
|
| 553 | 553 | return $this->conditionsStub[$dbType]; |
| 554 | 554 | } |
| 555 | 555 | else { |
| 556 | - $this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');; |
|
| 556 | + $this->conditionsStub[$dbType] = File::get($this->stubsDirectory.'SearchConditions/'.ucwords($dbType).'.php'); ; |
|
| 557 | 557 | |
| 558 | 558 | return $this->conditionsStub[$dbType]; |
| 559 | 559 | } |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - public function replaceSortConditions() { |
|
| 562 | + public function replaceSortConditions() { |
|
| 563 | 563 | $joinSorts = ''; |
| 564 | 564 | |
| 565 | 565 | foreach ($this->modelData->fields as $field) { |
| 566 | - if($field->foreignKey){ |
|
| 567 | - $joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php'); |
|
| 566 | + if ($field->foreignKey) { |
|
| 567 | + $joinSortStub = File::get($this->stubsDirectory.'SearchConditions/JoinSort.php'); |
|
| 568 | 568 | $joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub); |
| 569 | 569 | $joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub); |
| 570 | 570 | $joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub); |
@@ -589,11 +589,11 @@ discard block |
||
| 589 | 589 | * |
| 590 | 590 | * @return $this |
| 591 | 591 | */ |
| 592 | - public function replaceReverseRelationshipsFunctions(){ |
|
| 592 | + public function replaceReverseRelationshipsFunctions() { |
|
| 593 | 593 | |
| 594 | 594 | $functions = ''; |
| 595 | 595 | |
| 596 | - $method = File::get($this->stubsDirectory . '/Model/ModelReverseRelationshipFunctions.php'); |
|
| 596 | + $method = File::get($this->stubsDirectory.'/Model/ModelReverseRelationshipFunctions.php'); |
|
| 597 | 597 | |
| 598 | 598 | foreach ($this->modelData->reverseRelationships as $relationship) |
| 599 | 599 | { |
@@ -625,9 +625,9 @@ discard block |
||
| 625 | 625 | * |
| 626 | 626 | * @return $this |
| 627 | 627 | */ |
| 628 | - public function replaceCheckbox(){ |
|
| 628 | + public function replaceCheckbox() { |
|
| 629 | 629 | |
| 630 | - $method = File::get($this->stubsDirectory . '/Model/ModelCheckbox.php'); |
|
| 630 | + $method = File::get($this->stubsDirectory.'/Model/ModelCheckbox.php'); |
|
| 631 | 631 | $key = false; |
| 632 | 632 | |
| 633 | 633 | $method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method); |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | * |
| 646 | 646 | * @return $this |
| 647 | 647 | */ |
| 648 | - private function replaceSimpleFilter(){ |
|
| 648 | + private function replaceSimpleFilter() { |
|
| 649 | 649 | $i = 0; |
| 650 | 650 | |
| 651 | 651 | $stubSimpleFilter = ''; |
@@ -654,41 +654,41 @@ discard block |
||
| 654 | 654 | { |
| 655 | 655 | //var_dump($field->name); |
| 656 | 656 | |
| 657 | - if($field->index == 'primary'){ |
|
| 658 | - $dbType = 'primaryKey' ; |
|
| 657 | + if ($field->index == 'primary') { |
|
| 658 | + $dbType = 'primaryKey'; |
|
| 659 | 659 | } |
| 660 | - elseif($field->foreignKey){ |
|
| 661 | - $dbType = 'primary' ; |
|
| 660 | + elseif ($field->foreignKey) { |
|
| 661 | + $dbType = 'primary'; |
|
| 662 | 662 | } |
| 663 | - elseif($field->type->db == 'enum'){ |
|
| 664 | - $dbType = 'primary' ; |
|
| 663 | + elseif ($field->type->db == 'enum') { |
|
| 664 | + $dbType = 'primary'; |
|
| 665 | 665 | } |
| 666 | - elseif($field->type->db == 'boolean'){ |
|
| 667 | - $dbType = 'primary' ; |
|
| 666 | + elseif ($field->type->db == 'boolean') { |
|
| 667 | + $dbType = 'primary'; |
|
| 668 | 668 | } |
| 669 | - elseif($field->type->db == 'text'){ |
|
| 670 | - $dbType = 'string' ; |
|
| 669 | + elseif ($field->type->db == 'text') { |
|
| 670 | + $dbType = 'string'; |
|
| 671 | 671 | } |
| 672 | 672 | else { |
| 673 | - $dbType = $field->type->db ; |
|
| 673 | + $dbType = $field->type->db; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | - if($dbType == 'primaryKey') |
|
| 676 | + if ($dbType == 'primaryKey') |
|
| 677 | 677 | { |
| 678 | 678 | $stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | - if($dbType == 'primary') |
|
| 681 | + if ($dbType == 'primary') |
|
| 682 | 682 | { |
| 683 | 683 | $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
| 684 | 684 | } |
| 685 | 685 | |
| 686 | - if($dbType == 'string') |
|
| 686 | + if ($dbType == 'string') |
|
| 687 | 687 | { |
| 688 | 688 | $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number') |
|
| 691 | + if ($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number') |
|
| 692 | 692 | { |
| 693 | 693 | $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL; |
| 694 | 694 | } |
@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | public function __construct($scaffolderConfig, $modelData = null, $stubName = null) |
| 18 | 18 | { |
| 19 | - if ($stubName) |
|
| 20 | - $this->stubFilename = $stubName; |
|
| 19 | + if ($stubName) { |
|
| 20 | + $this->stubFilename = $stubName; |
|
| 21 | + } |
|
| 21 | 22 | $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
| 22 | 23 | parent::__construct($scaffolderConfig, $modelData); |
| 23 | 24 | } |
@@ -91,19 +92,21 @@ discard block |
||
| 91 | 92 | |
| 92 | 93 | foreach ($this->modelData->fields as $field) |
| 93 | 94 | { |
| 94 | - if($field->index == "primary") |
|
| 95 | - continue ; |
|
| 96 | - if($this->modelData->timeStamps && $field->name == "created_at") |
|
| 97 | - continue ; |
|
| 98 | - if($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 99 | - continue ; |
|
| 95 | + if($field->index == "primary") { |
|
| 96 | + continue ; |
|
| 97 | + } |
|
| 98 | + if($this->modelData->timeStamps && $field->name == "created_at") { |
|
| 99 | + continue ; |
|
| 100 | + } |
|
| 101 | + if($this->modelData->timeStamps && $field->name == "updated_at") { |
|
| 102 | + continue ; |
|
| 103 | + } |
|
| 100 | 104 | |
| 101 | 105 | if ($firstIteration) |
| 102 | 106 | { |
| 103 | 107 | $fields .= sprintf("'%s'," . PHP_EOL, $field->name); |
| 104 | 108 | $firstIteration = false; |
| 105 | - } |
|
| 106 | - else |
|
| 109 | + } else |
|
| 107 | 110 | { |
| 108 | 111 | $fields .= sprintf("\t\t'%s'," . PHP_EOL, $field->name); |
| 109 | 112 | } |
@@ -127,8 +130,9 @@ discard block |
||
| 127 | 130 | |
| 128 | 131 | foreach ($field->options as $key => $option) { |
| 129 | 132 | $items .= "'" . $option . "'"; |
| 130 | - if ($key < (count($field->options) - 1)) |
|
| 131 | - $items .= ", "; |
|
| 133 | + if ($key < (count($field->options) - 1)) { |
|
| 134 | + $items .= ", "; |
|
| 135 | + } |
|
| 132 | 136 | |
| 133 | 137 | } |
| 134 | 138 | |
@@ -160,19 +164,21 @@ discard block |
||
| 160 | 164 | |
| 161 | 165 | foreach ($this->modelData->fields as $field) |
| 162 | 166 | { |
| 163 | - if($field->index == "primary") |
|
| 164 | - continue ; |
|
| 165 | - if($this->modelData->timeStamps && $field->name == "created_at") |
|
| 166 | - continue ; |
|
| 167 | - if($this->modelData->timeStamps && $field->name == "updated_at") |
|
| 168 | - continue ; |
|
| 167 | + if($field->index == "primary") { |
|
| 168 | + continue ; |
|
| 169 | + } |
|
| 170 | + if($this->modelData->timeStamps && $field->name == "created_at") { |
|
| 171 | + continue ; |
|
| 172 | + } |
|
| 173 | + if($this->modelData->timeStamps && $field->name == "updated_at") { |
|
| 174 | + continue ; |
|
| 175 | + } |
|
| 169 | 176 | |
| 170 | 177 | if ($firstIteration) |
| 171 | 178 | { |
| 172 | 179 | $fields .= sprintf("'%s' => '%s'," . PHP_EOL, $field->name, $field->validations); |
| 173 | 180 | $firstIteration = false; |
| 174 | - } |
|
| 175 | - else |
|
| 181 | + } else |
|
| 176 | 182 | { |
| 177 | 183 | $fields .= sprintf("\t\t\t'%s' => '%s'," . PHP_EOL, $field->name, $field->validations); |
| 178 | 184 | } |
@@ -245,8 +251,7 @@ discard block |
||
| 245 | 251 | $belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub); |
| 246 | 252 | $belongsToStub = str_replace('{{field}}', $field->name, $belongsToStub); |
| 247 | 253 | $belongsToStub = str_replace('{{foreign_field}}', $field->foreignKey->field, $belongsToStub); |
| 248 | - } |
|
| 249 | - elseif ($field->foreignKey->relationship == "belongsToMany") { |
|
| 254 | + } elseif ($field->foreignKey->relationship == "belongsToMany") { |
|
| 250 | 255 | $belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php'); |
| 251 | 256 | $functionName = CamelCase::pluralize($field->foreignKey->table); |
| 252 | 257 | $belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub); |
@@ -289,10 +294,11 @@ discard block |
||
| 289 | 294 | { |
| 290 | 295 | $reverseRelationshipStub = ""; |
| 291 | 296 | $functionName = ''; |
| 292 | - if ($relationship->type == "hasOne") |
|
| 293 | - $functionName = strtolower($relationship->modelName); |
|
| 294 | - else |
|
| 295 | - $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 297 | + if ($relationship->type == "hasOne") { |
|
| 298 | + $functionName = strtolower($relationship->modelName); |
|
| 299 | + } else { |
|
| 300 | + $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 301 | + } |
|
| 296 | 302 | |
| 297 | 303 | if ($relationship->type == "belongsToMany") { |
| 298 | 304 | $reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php'); |
@@ -301,8 +307,7 @@ discard block |
||
| 301 | 307 | $reverseRelationshipStub = str_replace('{{table_name}}', $relationship->tableName, $reverseRelationshipStub); |
| 302 | 308 | $reverseRelationshipStub = str_replace('{{related_field}}', $relationship->relatedField, $reverseRelationshipStub); |
| 303 | 309 | $reverseRelationshipStub = str_replace('{{foreign_table}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $reverseRelationshipStub); |
| 304 | - } |
|
| 305 | - else { |
|
| 310 | + } else { |
|
| 306 | 311 | $reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelReverseRelationship.php'); |
| 307 | 312 | $reverseRelationshipStub = str_replace('{{foreign_model}}', $relationship->modelName, $reverseRelationshipOriginalStub); |
| 308 | 313 | $reverseRelationshipStub = str_replace('{{field}}', $relationship->foreignKey, $reverseRelationshipStub); |
@@ -532,27 +537,21 @@ discard block |
||
| 532 | 537 | |
| 533 | 538 | if($field->index == 'primary'){ |
| 534 | 539 | $dbType = 'primary' ; |
| 535 | - } |
|
| 536 | - elseif($field->foreignKey){ |
|
| 540 | + } elseif($field->foreignKey){ |
|
| 537 | 541 | $dbType = 'primary' ; |
| 538 | - } |
|
| 539 | - elseif($field->type->db == 'enum'){ |
|
| 542 | + } elseif($field->type->db == 'enum'){ |
|
| 540 | 543 | $dbType = 'primary' ; |
| 541 | - } |
|
| 542 | - elseif($field->type->db == 'boolean'){ |
|
| 544 | + } elseif($field->type->db == 'boolean'){ |
|
| 543 | 545 | $dbType = 'primary' ; |
| 544 | - } |
|
| 545 | - elseif($field->type->db == 'text'){ |
|
| 546 | + } elseif($field->type->db == 'text'){ |
|
| 546 | 547 | $dbType = 'string' ; |
| 547 | - } |
|
| 548 | - else { |
|
| 548 | + } else { |
|
| 549 | 549 | $dbType = $field->type->db ; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | if(array_key_exists($dbType, $this->conditionsStub)){ |
| 553 | 553 | return $this->conditionsStub[$dbType]; |
| 554 | - } |
|
| 555 | - else { |
|
| 554 | + } else { |
|
| 556 | 555 | $this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');; |
| 557 | 556 | |
| 558 | 557 | return $this->conditionsStub[$dbType]; |
@@ -598,12 +597,13 @@ discard block |
||
| 598 | 597 | foreach ($this->modelData->reverseRelationships as $relationship) |
| 599 | 598 | { |
| 600 | 599 | $functionName = ''; |
| 601 | - if ($relationship->type == "hasOne") |
|
| 602 | - $functionName = strtolower($relationship->modelName); |
|
| 603 | - elseif ($relationship->type == "belongsToMany") |
|
| 604 | - $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); |
|
| 605 | - else |
|
| 606 | - $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 600 | + if ($relationship->type == "hasOne") { |
|
| 601 | + $functionName = strtolower($relationship->modelName); |
|
| 602 | + } elseif ($relationship->type == "belongsToMany") { |
|
| 603 | + $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); |
|
| 604 | + } else { |
|
| 605 | + $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 606 | + } |
|
| 607 | 607 | |
| 608 | 608 | $replacedMethod = ''; |
| 609 | 609 | $replacedMethod = str_replace('{{function_name}}', $functionName, $method); |
@@ -656,20 +656,15 @@ discard block |
||
| 656 | 656 | |
| 657 | 657 | if($field->index == 'primary'){ |
| 658 | 658 | $dbType = 'primaryKey' ; |
| 659 | - } |
|
| 660 | - elseif($field->foreignKey){ |
|
| 659 | + } elseif($field->foreignKey){ |
|
| 661 | 660 | $dbType = 'primary' ; |
| 662 | - } |
|
| 663 | - elseif($field->type->db == 'enum'){ |
|
| 661 | + } elseif($field->type->db == 'enum'){ |
|
| 664 | 662 | $dbType = 'primary' ; |
| 665 | - } |
|
| 666 | - elseif($field->type->db == 'boolean'){ |
|
| 663 | + } elseif($field->type->db == 'boolean'){ |
|
| 667 | 664 | $dbType = 'primary' ; |
| 668 | - } |
|
| 669 | - elseif($field->type->db == 'text'){ |
|
| 665 | + } elseif($field->type->db == 'text'){ |
|
| 670 | 666 | $dbType = 'string' ; |
| 671 | - } |
|
| 672 | - else { |
|
| 667 | + } else { |
|
| 673 | 668 | $dbType = $field->type->db ; |
| 674 | 669 | } |
| 675 | 670 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * Compiles a group of routes. |
| 46 | 46 | * |
| 47 | 47 | * @param $hash |
| 48 | - * @param null $extra |
|
| 48 | + * @param string $compiledRoutes |
|
| 49 | 49 | * |
| 50 | 50 | * @return mixed |
| 51 | 51 | */ |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * Get output filename |
| 65 | 65 | * |
| 66 | 66 | * |
| 67 | - * @return $this |
|
| 67 | + * @return string |
|
| 68 | 68 | */ |
| 69 | 69 | protected function getOutputFilename() |
| 70 | 70 | { |
@@ -10,165 +10,165 @@ |
||
| 10 | 10 | |
| 11 | 11 | class RouteCompiler extends AbstractCompiler |
| 12 | 12 | { |
| 13 | - protected $stubFilename = 'Routes.php' ; |
|
| 13 | + protected $stubFilename = 'Routes.php' ; |
|
| 14 | 14 | |
| 15 | - protected $stubResourceFilename = 'ResourceRoute.php' ; |
|
| 16 | - protected $stubResource ; |
|
| 15 | + protected $stubResourceFilename = 'ResourceRoute.php' ; |
|
| 16 | + protected $stubResource ; |
|
| 17 | 17 | |
| 18 | 18 | |
| 19 | - public function __construct($scaffolderConfig, $modelData = null) |
|
| 20 | - { |
|
| 21 | - $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
|
| 22 | - parent::__construct($scaffolderConfig, null); |
|
| 19 | + public function __construct($scaffolderConfig, $modelData = null) |
|
| 20 | + { |
|
| 21 | + $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
|
| 22 | + parent::__construct($scaffolderConfig, null); |
|
| 23 | 23 | |
| 24 | - $this->stubResource = File::get($this->stubsDirectory . $this->stubResourceFilename ); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Replace and store the Stub. |
|
| 29 | - * |
|
| 30 | - * @return string |
|
| 31 | - */ |
|
| 32 | - public function replaceAndStore(){} |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Compiles a resource. |
|
| 36 | - * |
|
| 37 | - * @param $hash |
|
| 38 | - * @param null $extra |
|
| 39 | - * |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public function compile($extra = null) {} |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Compiles a group of routes. |
|
| 46 | - * |
|
| 47 | - * @param $hash |
|
| 48 | - * @param null $extra |
|
| 49 | - * |
|
| 50 | - * @return mixed |
|
| 51 | - */ |
|
| 52 | - public function compileGroup($compiledRoutes) |
|
| 53 | - { |
|
| 54 | - |
|
| 55 | - $this->replaceRoutes($compiledRoutes) |
|
| 56 | - ->replaceRoutePrefix() |
|
| 57 | - ->store(new FileToCompile(null, null)); |
|
| 58 | - |
|
| 59 | - return $this->stub; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Get output filename |
|
| 65 | - * |
|
| 66 | - * |
|
| 67 | - * @return $this |
|
| 68 | - */ |
|
| 69 | - protected function getOutputFilename() |
|
| 70 | - { |
|
| 71 | - $folder = PathParser::parse($this->scaffolderConfig->generator->paths->routes); |
|
| 72 | - |
|
| 73 | - return $folder . 'routes.php'; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Replace the resource. |
|
| 79 | - * |
|
| 80 | - * @param $this->modelName |
|
| 81 | - * |
|
| 82 | - * @return string routeStub |
|
| 83 | - */ |
|
| 84 | - public function replaceResource($modelData) |
|
| 85 | - { |
|
| 24 | + $this->stubResource = File::get($this->stubsDirectory . $this->stubResourceFilename ); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Replace and store the Stub. |
|
| 29 | + * |
|
| 30 | + * @return string |
|
| 31 | + */ |
|
| 32 | + public function replaceAndStore(){} |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Compiles a resource. |
|
| 36 | + * |
|
| 37 | + * @param $hash |
|
| 38 | + * @param null $extra |
|
| 39 | + * |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public function compile($extra = null) {} |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Compiles a group of routes. |
|
| 46 | + * |
|
| 47 | + * @param $hash |
|
| 48 | + * @param null $extra |
|
| 49 | + * |
|
| 50 | + * @return mixed |
|
| 51 | + */ |
|
| 52 | + public function compileGroup($compiledRoutes) |
|
| 53 | + { |
|
| 54 | + |
|
| 55 | + $this->replaceRoutes($compiledRoutes) |
|
| 56 | + ->replaceRoutePrefix() |
|
| 57 | + ->store(new FileToCompile(null, null)); |
|
| 58 | + |
|
| 59 | + return $this->stub; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Get output filename |
|
| 65 | + * |
|
| 66 | + * |
|
| 67 | + * @return $this |
|
| 68 | + */ |
|
| 69 | + protected function getOutputFilename() |
|
| 70 | + { |
|
| 71 | + $folder = PathParser::parse($this->scaffolderConfig->generator->paths->routes); |
|
| 72 | + |
|
| 73 | + return $folder . 'routes.php'; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Replace the resource. |
|
| 79 | + * |
|
| 80 | + * @param $this->modelName |
|
| 81 | + * |
|
| 82 | + * @return string routeStub |
|
| 83 | + */ |
|
| 84 | + public function replaceResource($modelData) |
|
| 85 | + { |
|
| 86 | 86 | |
| 87 | - $routeStub = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $this->stubResource); |
|
| 88 | - $routeStub = str_replace('{{resource}}', $modelData->modelName, $routeStub); |
|
| 89 | - $routeStub = str_replace('{{reverseRelationships}}', $this->replaceReverseRelationships($modelData), $routeStub); |
|
| 90 | - $routeStub = str_replace('{{enum}}', $this->replaceEnum($modelData), $routeStub); |
|
| 91 | - |
|
| 92 | - return $routeStub; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Replace the reverse relationships. |
|
| 97 | - * |
|
| 98 | - * @param $this->modelData |
|
| 99 | - * |
|
| 100 | - * @return string functions |
|
| 101 | - */ |
|
| 102 | - public function replaceReverseRelationships($modelData) |
|
| 103 | - { |
|
| 104 | - $functions = ''; |
|
| 105 | - |
|
| 106 | - foreach ($modelData->reverseRelationships as $relationship) |
|
| 107 | - { |
|
| 108 | - if ($relationship) |
|
| 109 | - { |
|
| 110 | - $functionName = ''; |
|
| 111 | - if ($relationship->type == "hasOne") |
|
| 112 | - $functionName = strtolower($relationship->modelName); |
|
| 113 | - elseif ($relationship->type == "belongsToMany") |
|
| 114 | - $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); |
|
| 115 | - else |
|
| 116 | - $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 117 | - |
|
| 118 | - $method = "\tRoute::get('{{resource_lw}}/{id}/{{function_name}}', '{{resource}}Controller@{{function_name}}');\n"; |
|
| 119 | - $method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method); |
|
| 120 | - $method = str_replace('{{function_name}}', $functionName, $method); |
|
| 121 | - $method = str_replace('{{resource}}', $modelData->modelName, $method); |
|
| 122 | - |
|
| 123 | - $functions .= $method; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return $functions; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Replace the enum. |
|
| 132 | - * |
|
| 133 | - * @param $this->modelData |
|
| 134 | - * |
|
| 135 | - * @return string functions |
|
| 136 | - */ |
|
| 137 | - public function replaceEnum($modelData) |
|
| 138 | - { |
|
| 139 | - $functions = ''; |
|
| 140 | - |
|
| 141 | - foreach ($modelData->fields as $field) |
|
| 142 | - { |
|
| 143 | - if ($field->type->db == "enum") |
|
| 144 | - { |
|
| 145 | - $method = "\tRoute::get('{{resource_lw}}/{{field_name}}', '{{resource}}Controller@get{{field_name_uc}}Options');\n"; |
|
| 146 | - $method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method); |
|
| 147 | - $method = str_replace('{{field_name_uc}}', CamelCase::convertToCamelCase($field->name), $method); |
|
| 148 | - $method = str_replace('{{field_name}}', $field->name, $method); |
|
| 149 | - $method = str_replace('{{resource}}', $modelData->modelName, $method); |
|
| 150 | - |
|
| 151 | - $functions .= $method; |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return $functions; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Replace compiled routes. |
|
| 161 | - * |
|
| 162 | - * @param $compiledRoutes |
|
| 163 | - * |
|
| 164 | - * @return $this |
|
| 165 | - */ |
|
| 166 | - private function replaceRoutes($compiledRoutes) |
|
| 167 | - { |
|
| 168 | - $this->stub = str_replace('{{routes}}', $compiledRoutes, $this->stub); |
|
| 169 | - |
|
| 170 | - return $this; |
|
| 171 | - } |
|
| 87 | + $routeStub = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $this->stubResource); |
|
| 88 | + $routeStub = str_replace('{{resource}}', $modelData->modelName, $routeStub); |
|
| 89 | + $routeStub = str_replace('{{reverseRelationships}}', $this->replaceReverseRelationships($modelData), $routeStub); |
|
| 90 | + $routeStub = str_replace('{{enum}}', $this->replaceEnum($modelData), $routeStub); |
|
| 91 | + |
|
| 92 | + return $routeStub; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Replace the reverse relationships. |
|
| 97 | + * |
|
| 98 | + * @param $this->modelData |
|
| 99 | + * |
|
| 100 | + * @return string functions |
|
| 101 | + */ |
|
| 102 | + public function replaceReverseRelationships($modelData) |
|
| 103 | + { |
|
| 104 | + $functions = ''; |
|
| 105 | + |
|
| 106 | + foreach ($modelData->reverseRelationships as $relationship) |
|
| 107 | + { |
|
| 108 | + if ($relationship) |
|
| 109 | + { |
|
| 110 | + $functionName = ''; |
|
| 111 | + if ($relationship->type == "hasOne") |
|
| 112 | + $functionName = strtolower($relationship->modelName); |
|
| 113 | + elseif ($relationship->type == "belongsToMany") |
|
| 114 | + $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); |
|
| 115 | + else |
|
| 116 | + $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 117 | + |
|
| 118 | + $method = "\tRoute::get('{{resource_lw}}/{id}/{{function_name}}', '{{resource}}Controller@{{function_name}}');\n"; |
|
| 119 | + $method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method); |
|
| 120 | + $method = str_replace('{{function_name}}', $functionName, $method); |
|
| 121 | + $method = str_replace('{{resource}}', $modelData->modelName, $method); |
|
| 122 | + |
|
| 123 | + $functions .= $method; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return $functions; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Replace the enum. |
|
| 132 | + * |
|
| 133 | + * @param $this->modelData |
|
| 134 | + * |
|
| 135 | + * @return string functions |
|
| 136 | + */ |
|
| 137 | + public function replaceEnum($modelData) |
|
| 138 | + { |
|
| 139 | + $functions = ''; |
|
| 140 | + |
|
| 141 | + foreach ($modelData->fields as $field) |
|
| 142 | + { |
|
| 143 | + if ($field->type->db == "enum") |
|
| 144 | + { |
|
| 145 | + $method = "\tRoute::get('{{resource_lw}}/{{field_name}}', '{{resource}}Controller@get{{field_name_uc}}Options');\n"; |
|
| 146 | + $method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method); |
|
| 147 | + $method = str_replace('{{field_name_uc}}', CamelCase::convertToCamelCase($field->name), $method); |
|
| 148 | + $method = str_replace('{{field_name}}', $field->name, $method); |
|
| 149 | + $method = str_replace('{{resource}}', $modelData->modelName, $method); |
|
| 150 | + |
|
| 151 | + $functions .= $method; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return $functions; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Replace compiled routes. |
|
| 161 | + * |
|
| 162 | + * @param $compiledRoutes |
|
| 163 | + * |
|
| 164 | + * @return $this |
|
| 165 | + */ |
|
| 166 | + private function replaceRoutes($compiledRoutes) |
|
| 167 | + { |
|
| 168 | + $this->stub = str_replace('{{routes}}', $compiledRoutes, $this->stub); |
|
| 169 | + |
|
| 170 | + return $this; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | 173 | |
| 174 | 174 | } |
@@ -10,18 +10,18 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | class RouteCompiler extends AbstractCompiler |
| 12 | 12 | { |
| 13 | - protected $stubFilename = 'Routes.php' ; |
|
| 13 | + protected $stubFilename = 'Routes.php'; |
|
| 14 | 14 | |
| 15 | - protected $stubResourceFilename = 'ResourceRoute.php' ; |
|
| 16 | - protected $stubResource ; |
|
| 15 | + protected $stubResourceFilename = 'ResourceRoute.php'; |
|
| 16 | + protected $stubResource; |
|
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | public function __construct($scaffolderConfig, $modelData = null) |
| 20 | 20 | { |
| 21 | - $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/'; |
|
| 21 | + $this->stubsDirectory = __DIR__.'/../../../../stubs/Api/'; |
|
| 22 | 22 | parent::__construct($scaffolderConfig, null); |
| 23 | 23 | |
| 24 | - $this->stubResource = File::get($this->stubsDirectory . $this->stubResourceFilename ); |
|
| 24 | + $this->stubResource = File::get($this->stubsDirectory.$this->stubResourceFilename); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @return string |
| 31 | 31 | */ |
| 32 | - public function replaceAndStore(){} |
|
| 32 | + public function replaceAndStore() {} |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Compiles a resource. |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | { |
| 71 | 71 | $folder = PathParser::parse($this->scaffolderConfig->generator->paths->routes); |
| 72 | 72 | |
| 73 | - return $folder . 'routes.php'; |
|
| 73 | + return $folder.'routes.php'; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | |
@@ -108,12 +108,13 @@ |
||
| 108 | 108 | if ($relationship) |
| 109 | 109 | { |
| 110 | 110 | $functionName = ''; |
| 111 | - if ($relationship->type == "hasOne") |
|
| 112 | - $functionName = strtolower($relationship->modelName); |
|
| 113 | - elseif ($relationship->type == "belongsToMany") |
|
| 114 | - $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); |
|
| 115 | - else |
|
| 116 | - $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 111 | + if ($relationship->type == "hasOne") { |
|
| 112 | + $functionName = strtolower($relationship->modelName); |
|
| 113 | + } elseif ($relationship->type == "belongsToMany") { |
|
| 114 | + $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); |
|
| 115 | + } else { |
|
| 116 | + $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); |
|
| 117 | + } |
|
| 117 | 118 | |
| 118 | 119 | $method = "\tRoute::get('{{resource_lw}}/{id}/{{function_name}}', '{{resource}}Controller@{{function_name}}');\n"; |
| 119 | 120 | $method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method); |
@@ -68,7 +68,7 @@ |
||
| 68 | 68 | /** |
| 69 | 69 | * Get the services provided by the provider. |
| 70 | 70 | * |
| 71 | - * @return array |
|
| 71 | + * @return string[] |
|
| 72 | 72 | */ |
| 73 | 73 | public function provides() |
| 74 | 74 | { |
@@ -10,68 +10,68 @@ |
||
| 10 | 10 | |
| 11 | 11 | class ScaffolderServiceProvider extends ServiceProvider |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Bootstrap the application services. |
|
| 15 | - */ |
|
| 16 | - public function boot() |
|
| 17 | - { |
|
| 18 | - // Scaffolder config |
|
| 19 | - $this->publishes([ |
|
| 20 | - __DIR__ . '/../../config/' => base_path('scaffolder-config/') |
|
| 21 | - ], 'config'); |
|
| 13 | + /** |
|
| 14 | + * Bootstrap the application services. |
|
| 15 | + */ |
|
| 16 | + public function boot() |
|
| 17 | + { |
|
| 18 | + // Scaffolder config |
|
| 19 | + $this->publishes([ |
|
| 20 | + __DIR__ . '/../../config/' => base_path('scaffolder-config/') |
|
| 21 | + ], 'config'); |
|
| 22 | 22 | |
| 23 | - // Generator views |
|
| 24 | - //$this->loadViewsFrom(__DIR__ . '/../../views', 'scaffolder'); |
|
| 23 | + // Generator views |
|
| 24 | + //$this->loadViewsFrom(__DIR__ . '/../../views', 'scaffolder'); |
|
| 25 | 25 | |
| 26 | - // Generator routes |
|
| 27 | - if (!$this->app->routesAreCached()) |
|
| 28 | - { |
|
| 29 | - require __DIR__ . '/../../routes/generator.php'; |
|
| 30 | - } |
|
| 31 | - } |
|
| 26 | + // Generator routes |
|
| 27 | + if (!$this->app->routesAreCached()) |
|
| 28 | + { |
|
| 29 | + require __DIR__ . '/../../routes/generator.php'; |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Register the service provider. |
|
| 35 | - * |
|
| 36 | - * @return void |
|
| 37 | - */ |
|
| 38 | - public function register() |
|
| 39 | - { |
|
| 40 | - $this->app->singleton('scaffolder.command.generate', function ($app) |
|
| 41 | - { |
|
| 42 | - return new GeneratorCommand(); |
|
| 43 | - }); |
|
| 33 | + /** |
|
| 34 | + * Register the service provider. |
|
| 35 | + * |
|
| 36 | + * @return void |
|
| 37 | + */ |
|
| 38 | + public function register() |
|
| 39 | + { |
|
| 40 | + $this->app->singleton('scaffolder.command.generate', function ($app) |
|
| 41 | + { |
|
| 42 | + return new GeneratorCommand(); |
|
| 43 | + }); |
|
| 44 | 44 | |
| 45 | - $this->app->singleton('scaffolder.command.cache.clear', function () |
|
| 46 | - { |
|
| 47 | - return new ClearCacheCommand(); |
|
| 48 | - }); |
|
| 45 | + $this->app->singleton('scaffolder.command.cache.clear', function () |
|
| 46 | + { |
|
| 47 | + return new ClearCacheCommand(); |
|
| 48 | + }); |
|
| 49 | 49 | |
| 50 | - $this->app->singleton('scaffolder.command.build', function () |
|
| 51 | - { |
|
| 52 | - return new BuildCommand(); |
|
| 53 | - }); |
|
| 50 | + $this->app->singleton('scaffolder.command.build', function () |
|
| 51 | + { |
|
| 52 | + return new BuildCommand(); |
|
| 53 | + }); |
|
| 54 | 54 | |
| 55 | - $this->app->singleton('scaffolder.command.serve', function () |
|
| 56 | - { |
|
| 57 | - return new ServeCommand(); |
|
| 58 | - }); |
|
| 55 | + $this->app->singleton('scaffolder.command.serve', function () |
|
| 56 | + { |
|
| 57 | + return new ServeCommand(); |
|
| 58 | + }); |
|
| 59 | 59 | |
| 60 | - $this->commands([ |
|
| 61 | - 'scaffolder.command.generate', |
|
| 62 | - 'scaffolder.command.cache.clear', |
|
| 63 | - 'scaffolder.command.build', |
|
| 64 | - 'scaffolder.command.serve' |
|
| 65 | - ]); |
|
| 66 | - } |
|
| 60 | + $this->commands([ |
|
| 61 | + 'scaffolder.command.generate', |
|
| 62 | + 'scaffolder.command.cache.clear', |
|
| 63 | + 'scaffolder.command.build', |
|
| 64 | + 'scaffolder.command.serve' |
|
| 65 | + ]); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Get the services provided by the provider. |
|
| 70 | - * |
|
| 71 | - * @return array |
|
| 72 | - */ |
|
| 73 | - public function provides() |
|
| 74 | - { |
|
| 75 | - return ['scaffolder.command.generate', 'scaffolder.command.cache.clear', 'scaffolder.command.serve', 'scaffolder.command.build']; |
|
| 76 | - } |
|
| 68 | + /** |
|
| 69 | + * Get the services provided by the provider. |
|
| 70 | + * |
|
| 71 | + * @return array |
|
| 72 | + */ |
|
| 73 | + public function provides() |
|
| 74 | + { |
|
| 75 | + return ['scaffolder.command.generate', 'scaffolder.command.cache.clear', 'scaffolder.command.serve', 'scaffolder.command.build']; |
|
| 76 | + } |
|
| 77 | 77 | } |
| 78 | 78 | \ No newline at end of file |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | // Scaffolder config |
| 19 | 19 | $this->publishes([ |
| 20 | - __DIR__ . '/../../config/' => base_path('scaffolder-config/') |
|
| 20 | + __DIR__.'/../../config/' => base_path('scaffolder-config/') |
|
| 21 | 21 | ], 'config'); |
| 22 | 22 | |
| 23 | 23 | // Generator views |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | // Generator routes |
| 27 | 27 | if (!$this->app->routesAreCached()) |
| 28 | 28 | { |
| 29 | - require __DIR__ . '/../../routes/generator.php'; |
|
| 29 | + require __DIR__.'/../../routes/generator.php'; |
|
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | 32 | |
@@ -37,22 +37,22 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function register() |
| 39 | 39 | { |
| 40 | - $this->app->singleton('scaffolder.command.generate', function ($app) |
|
| 40 | + $this->app->singleton('scaffolder.command.generate', function($app) |
|
| 41 | 41 | { |
| 42 | 42 | return new GeneratorCommand(); |
| 43 | 43 | }); |
| 44 | 44 | |
| 45 | - $this->app->singleton('scaffolder.command.cache.clear', function () |
|
| 45 | + $this->app->singleton('scaffolder.command.cache.clear', function() |
|
| 46 | 46 | { |
| 47 | 47 | return new ClearCacheCommand(); |
| 48 | 48 | }); |
| 49 | 49 | |
| 50 | - $this->app->singleton('scaffolder.command.build', function () |
|
| 50 | + $this->app->singleton('scaffolder.command.build', function() |
|
| 51 | 51 | { |
| 52 | 52 | return new BuildCommand(); |
| 53 | 53 | }); |
| 54 | 54 | |
| 55 | - $this->app->singleton('scaffolder.command.serve', function () |
|
| 55 | + $this->app->singleton('scaffolder.command.serve', function() |
|
| 56 | 56 | { |
| 57 | 57 | return new ServeCommand(); |
| 58 | 58 | }); |
@@ -4,6 +4,9 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Arrays |
| 6 | 6 | { |
| 7 | + /** |
|
| 8 | + * @param integer $targetIndex |
|
| 9 | + */ |
|
| 7 | 10 | public static function moveElement($array, $toMove, $targetIndex) { |
| 8 | 11 | if (count($array) == 1) |
| 9 | 12 | return $array; |
@@ -4,29 +4,29 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Arrays |
| 6 | 6 | { |
| 7 | - public static function moveElement($array, $toMove, $targetIndex) { |
|
| 8 | - if (count($array) == 1) |
|
| 9 | - return $array; |
|
| 10 | - if (is_int($toMove)) { |
|
| 11 | - $tmp = array_splice($array, $toMove, 1); |
|
| 12 | - array_splice($array, $targetIndex, 0, $tmp); |
|
| 13 | - $output = $array; |
|
| 14 | - } |
|
| 15 | - elseif (is_string($toMove)) { |
|
| 16 | - $indexToMove = array_search($toMove, array_keys($array)); |
|
| 17 | - $itemToMove = $array[$toMove]; |
|
| 18 | - array_splice($array, $indexToMove, 1); |
|
| 19 | - $i = 0; |
|
| 20 | - $output = Array(); |
|
| 21 | - foreach($array as $key => $item) { |
|
| 22 | - if ($i == $targetIndex) { |
|
| 23 | - $output[$toMove] = $itemToMove; |
|
| 24 | - } |
|
| 25 | - $output[$key] = $item; |
|
| 26 | - $i++; |
|
| 27 | - } |
|
| 28 | - } |
|
| 29 | - return $output; |
|
| 30 | - } |
|
| 7 | + public static function moveElement($array, $toMove, $targetIndex) { |
|
| 8 | + if (count($array) == 1) |
|
| 9 | + return $array; |
|
| 10 | + if (is_int($toMove)) { |
|
| 11 | + $tmp = array_splice($array, $toMove, 1); |
|
| 12 | + array_splice($array, $targetIndex, 0, $tmp); |
|
| 13 | + $output = $array; |
|
| 14 | + } |
|
| 15 | + elseif (is_string($toMove)) { |
|
| 16 | + $indexToMove = array_search($toMove, array_keys($array)); |
|
| 17 | + $itemToMove = $array[$toMove]; |
|
| 18 | + array_splice($array, $indexToMove, 1); |
|
| 19 | + $i = 0; |
|
| 20 | + $output = Array(); |
|
| 21 | + foreach($array as $key => $item) { |
|
| 22 | + if ($i == $targetIndex) { |
|
| 23 | + $output[$toMove] = $itemToMove; |
|
| 24 | + } |
|
| 25 | + $output[$key] = $item; |
|
| 26 | + $i++; |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | + return $output; |
|
| 30 | + } |
|
| 31 | 31 | } |
| 32 | 32 | |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | array_splice($array, $indexToMove, 1); |
| 19 | 19 | $i = 0; |
| 20 | 20 | $output = Array(); |
| 21 | - foreach($array as $key => $item) { |
|
| 21 | + foreach ($array as $key => $item) { |
|
| 22 | 22 | if ($i == $targetIndex) { |
| 23 | 23 | $output[$toMove] = $itemToMove; |
| 24 | 24 | } |
@@ -5,14 +5,14 @@ |
||
| 5 | 5 | class Arrays |
| 6 | 6 | { |
| 7 | 7 | public static function moveElement($array, $toMove, $targetIndex) { |
| 8 | - if (count($array) == 1) |
|
| 9 | - return $array; |
|
| 8 | + if (count($array) == 1) { |
|
| 9 | + return $array; |
|
| 10 | + } |
|
| 10 | 11 | if (is_int($toMove)) { |
| 11 | 12 | $tmp = array_splice($array, $toMove, 1); |
| 12 | 13 | array_splice($array, $targetIndex, 0, $tmp); |
| 13 | 14 | $output = $array; |
| 14 | - } |
|
| 15 | - elseif (is_string($toMove)) { |
|
| 15 | + } elseif (is_string($toMove)) { |
|
| 16 | 16 | $indexToMove = array_search($toMove, array_keys($array)); |
| 17 | 17 | $itemToMove = $array[$toMove]; |
| 18 | 18 | array_splice($array, $indexToMove, 1); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @param string $rule |
| 36 | 36 | * @param string $parameter |
| 37 | - * @return array |
|
| 37 | + * @return string |
|
| 38 | 38 | */ |
| 39 | 39 | public static function parseParameters($rule, $parameter) |
| 40 | 40 | { |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | /** |
| 49 | 49 | * Explode the rules into an array of rules. |
| 50 | 50 | * |
| 51 | - * @param string $rules |
|
| 51 | + * @param string $rule |
|
| 52 | 52 | * @return array |
| 53 | 53 | */ |
| 54 | 54 | public static function explodeRule($rule) |
@@ -2,9 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Scaffolder\Support; |
| 4 | 4 | |
| 5 | -use Illuminate\Support\Arr; |
|
| 6 | -use Illuminate\Support\Str; |
|
| 7 | - |
|
| 8 | 5 | class Validator |
| 9 | 6 | { |
| 10 | 7 | /** |
@@ -7,104 +7,104 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Validator |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Parse a string based rule. |
|
| 12 | - * |
|
| 13 | - * @param string $rules |
|
| 14 | - * @return array |
|
| 15 | - */ |
|
| 16 | - public static function parseStringRule($rules) |
|
| 17 | - { |
|
| 18 | - $parameters = []; |
|
| 19 | - |
|
| 20 | - // The format for specifying validation rules and parameters follows an |
|
| 21 | - // easy {rule}:{parameters} formatting convention. For instance the |
|
| 22 | - // rule "Max:3" states that the value may only be three letters. |
|
| 23 | - if (strpos($rules, ':') !== false) { |
|
| 24 | - list($rules, $parameter) = explode(':', $rules, 2); |
|
| 25 | - |
|
| 26 | - $parameters = self::parseParameters($rules, $parameter); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - return [(trim($rules)), $parameters]; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Parse a parameter list. |
|
| 34 | - * |
|
| 35 | - * @param string $rule |
|
| 36 | - * @param string $parameter |
|
| 37 | - * @return array |
|
| 38 | - */ |
|
| 39 | - public static function parseParameters($rule, $parameter) |
|
| 40 | - { |
|
| 41 | - if (strtolower($rule) == 'regex') { |
|
| 42 | - return [$parameter]; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - return str_getcsv($parameter); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Explode the rules into an array of rules. |
|
| 50 | - * |
|
| 51 | - * @param string $rules |
|
| 52 | - * @return array |
|
| 53 | - */ |
|
| 54 | - public static function explodeRule($rule) |
|
| 55 | - { |
|
| 56 | - return explode('|', $rule); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Convert laravel validations to theme validation angular js. |
|
| 61 | - * |
|
| 62 | - * @param string $validations |
|
| 63 | - * @return array |
|
| 64 | - */ |
|
| 65 | - public static function convertValidations($validations, $blnSearch = false){ |
|
| 66 | - $validationsConverted = []; |
|
| 67 | - foreach (self::explodeRule($validations) as $validation) { |
|
| 68 | - $validation = self::parseStringRule($validation); |
|
| 69 | - |
|
| 70 | - if(isset($validation[0])){ |
|
| 71 | - |
|
| 72 | - $rule = $validation[0]; |
|
| 73 | - $values = $validation[1]; |
|
| 74 | - |
|
| 75 | - switch ($rule) { |
|
| 76 | - case 'required': |
|
| 77 | - if($blnSearch) { |
|
| 78 | - $attribute = null ; |
|
| 79 | - $attributeValue = null ; |
|
| 80 | - } |
|
| 81 | - else { |
|
| 82 | - $attribute = "required" ; |
|
| 83 | - $attributeValue = null ; |
|
| 84 | - } |
|
| 10 | + /** |
|
| 11 | + * Parse a string based rule. |
|
| 12 | + * |
|
| 13 | + * @param string $rules |
|
| 14 | + * @return array |
|
| 15 | + */ |
|
| 16 | + public static function parseStringRule($rules) |
|
| 17 | + { |
|
| 18 | + $parameters = []; |
|
| 19 | + |
|
| 20 | + // The format for specifying validation rules and parameters follows an |
|
| 21 | + // easy {rule}:{parameters} formatting convention. For instance the |
|
| 22 | + // rule "Max:3" states that the value may only be three letters. |
|
| 23 | + if (strpos($rules, ':') !== false) { |
|
| 24 | + list($rules, $parameter) = explode(':', $rules, 2); |
|
| 25 | + |
|
| 26 | + $parameters = self::parseParameters($rules, $parameter); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + return [(trim($rules)), $parameters]; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Parse a parameter list. |
|
| 34 | + * |
|
| 35 | + * @param string $rule |
|
| 36 | + * @param string $parameter |
|
| 37 | + * @return array |
|
| 38 | + */ |
|
| 39 | + public static function parseParameters($rule, $parameter) |
|
| 40 | + { |
|
| 41 | + if (strtolower($rule) == 'regex') { |
|
| 42 | + return [$parameter]; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + return str_getcsv($parameter); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Explode the rules into an array of rules. |
|
| 50 | + * |
|
| 51 | + * @param string $rules |
|
| 52 | + * @return array |
|
| 53 | + */ |
|
| 54 | + public static function explodeRule($rule) |
|
| 55 | + { |
|
| 56 | + return explode('|', $rule); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Convert laravel validations to theme validation angular js. |
|
| 61 | + * |
|
| 62 | + * @param string $validations |
|
| 63 | + * @return array |
|
| 64 | + */ |
|
| 65 | + public static function convertValidations($validations, $blnSearch = false){ |
|
| 66 | + $validationsConverted = []; |
|
| 67 | + foreach (self::explodeRule($validations) as $validation) { |
|
| 68 | + $validation = self::parseStringRule($validation); |
|
| 69 | + |
|
| 70 | + if(isset($validation[0])){ |
|
| 71 | + |
|
| 72 | + $rule = $validation[0]; |
|
| 73 | + $values = $validation[1]; |
|
| 74 | + |
|
| 75 | + switch ($rule) { |
|
| 76 | + case 'required': |
|
| 77 | + if($blnSearch) { |
|
| 78 | + $attribute = null ; |
|
| 79 | + $attributeValue = null ; |
|
| 80 | + } |
|
| 81 | + else { |
|
| 82 | + $attribute = "required" ; |
|
| 83 | + $attributeValue = null ; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - break; |
|
| 86 | + break; |
|
| 87 | 87 | |
| 88 | - case 'max': |
|
| 89 | - case 'min': |
|
| 90 | - $attribute = $rule.'length' ; |
|
| 91 | - $attributeValue = $values[0] ; |
|
| 92 | - break; |
|
| 88 | + case 'max': |
|
| 89 | + case 'min': |
|
| 90 | + $attribute = $rule.'length' ; |
|
| 91 | + $attributeValue = $values[0] ; |
|
| 92 | + break; |
|
| 93 | 93 | |
| 94 | - default: |
|
| 95 | - $attribute = null ; |
|
| 96 | - $attributeValue = null ; |
|
| 97 | - break; |
|
| 98 | - } |
|
| 94 | + default: |
|
| 95 | + $attribute = null ; |
|
| 96 | + $attributeValue = null ; |
|
| 97 | + break; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - if($attribute) |
|
| 101 | - $validationsConverted[$attribute] = $attributeValue ; |
|
| 100 | + if($attribute) |
|
| 101 | + $validationsConverted[$attribute] = $attributeValue ; |
|
| 102 | 102 | |
| 103 | - } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - return $validationsConverted ; |
|
| 108 | - } |
|
| 107 | + return $validationsConverted ; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | 110 | } |
| 111 | 111 | \ No newline at end of file |
@@ -62,49 +62,49 @@ |
||
| 62 | 62 | * @param string $validations |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - public static function convertValidations($validations, $blnSearch = false){ |
|
| 65 | + public static function convertValidations($validations, $blnSearch = false) { |
|
| 66 | 66 | $validationsConverted = []; |
| 67 | 67 | foreach (self::explodeRule($validations) as $validation) { |
| 68 | 68 | $validation = self::parseStringRule($validation); |
| 69 | 69 | |
| 70 | - if(isset($validation[0])){ |
|
| 70 | + if (isset($validation[0])) { |
|
| 71 | 71 | |
| 72 | 72 | $rule = $validation[0]; |
| 73 | 73 | $values = $validation[1]; |
| 74 | 74 | |
| 75 | 75 | switch ($rule) { |
| 76 | 76 | case 'required': |
| 77 | - if($blnSearch) { |
|
| 78 | - $attribute = null ; |
|
| 79 | - $attributeValue = null ; |
|
| 77 | + if ($blnSearch) { |
|
| 78 | + $attribute = null; |
|
| 79 | + $attributeValue = null; |
|
| 80 | 80 | } |
| 81 | 81 | else { |
| 82 | - $attribute = "required" ; |
|
| 83 | - $attributeValue = null ; |
|
| 82 | + $attribute = "required"; |
|
| 83 | + $attributeValue = null; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | break; |
| 87 | 87 | |
| 88 | 88 | case 'max': |
| 89 | 89 | case 'min': |
| 90 | - $attribute = $rule.'length' ; |
|
| 91 | - $attributeValue = $values[0] ; |
|
| 90 | + $attribute = $rule.'length'; |
|
| 91 | + $attributeValue = $values[0]; |
|
| 92 | 92 | break; |
| 93 | 93 | |
| 94 | 94 | default: |
| 95 | - $attribute = null ; |
|
| 96 | - $attributeValue = null ; |
|
| 95 | + $attribute = null; |
|
| 96 | + $attributeValue = null; |
|
| 97 | 97 | break; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if($attribute) |
|
| 101 | - $validationsConverted[$attribute] = $attributeValue ; |
|
| 100 | + if ($attribute) |
|
| 101 | + $validationsConverted[$attribute] = $attributeValue; |
|
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - return $validationsConverted ; |
|
| 107 | + return $validationsConverted; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | } |
| 111 | 111 | \ No newline at end of file |
@@ -77,8 +77,7 @@ discard block |
||
| 77 | 77 | if($blnSearch) { |
| 78 | 78 | $attribute = null ; |
| 79 | 79 | $attributeValue = null ; |
| 80 | - } |
|
| 81 | - else { |
|
| 80 | + } else { |
|
| 82 | 81 | $attribute = "required" ; |
| 83 | 82 | $attributeValue = null ; |
| 84 | 83 | } |
@@ -97,8 +96,9 @@ discard block |
||
| 97 | 96 | break; |
| 98 | 97 | } |
| 99 | 98 | |
| 100 | - if($attribute) |
|
| 101 | - $validationsConverted[$attribute] = $attributeValue ; |
|
| 99 | + if($attribute) { |
|
| 100 | + $validationsConverted[$attribute] = $attributeValue ; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |
@@ -6,13 +6,13 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Directory |
| 8 | 8 | { |
| 9 | - public static function createIfNotExists($path, $mode = 0755, $recursive = false, $force = false) |
|
| 10 | - { |
|
| 11 | - if (!File::isDirectory($path)) |
|
| 12 | - { |
|
| 13 | - File::makeDirectory($path, $mode, $recursive , $force ); |
|
| 14 | - } |
|
| 15 | - } |
|
| 9 | + public static function createIfNotExists($path, $mode = 0755, $recursive = false, $force = false) |
|
| 10 | + { |
|
| 11 | + if (!File::isDirectory($path)) |
|
| 12 | + { |
|
| 13 | + File::makeDirectory($path, $mode, $recursive , $force ); |
|
| 14 | + } |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | } |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | { |
| 11 | 11 | if (!File::isDirectory($path)) |
| 12 | 12 | { |
| 13 | - File::makeDirectory($path, $mode, $recursive , $force ); |
|
| 13 | + File::makeDirectory($path, $mode, $recursive, $force); |
|
| 14 | 14 | } |
| 15 | 15 | } |
| 16 | 16 | |