| @@ 7-96 (lines=90) @@ | ||
| 4 | ||
| 5 | use Milkmeowo\Framework\Repository\Generators\Migrations\SchemaParser; |
|
| 6 | ||
| 7 | class RepositoryInterfaceGenerator extends Generator |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * Get stub name. |
|
| 11 | * |
|
| 12 | * @var string |
|
| 13 | */ |
|
| 14 | protected $stub = 'repository/interface'; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * Get root namespace. |
|
| 18 | * |
|
| 19 | * @return string |
|
| 20 | */ |
|
| 21 | public function getRootNamespace() |
|
| 22 | { |
|
| 23 | return parent::getRootNamespace().parent::getConfigGeneratorClassPath($this->getPathConfigNode()); |
|
| 24 | } |
|
| 25 | ||
| 26 | /** |
|
| 27 | * Get generator path config node. |
|
| 28 | * |
|
| 29 | * @return string |
|
| 30 | */ |
|
| 31 | public function getPathConfigNode() |
|
| 32 | { |
|
| 33 | return 'interfaces'; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * Get destination path for generated file. |
|
| 38 | * |
|
| 39 | * @return string |
|
| 40 | */ |
|
| 41 | public function getPath() |
|
| 42 | { |
|
| 43 | return $this->getBasePath().'/'.parent::getConfigGeneratorClassPath($this->getPathConfigNode(), true).'/'.$this->getName().'Repository.php'; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Get base path of destination file. |
|
| 48 | * |
|
| 49 | * @return string |
|
| 50 | */ |
|
| 51 | public function getBasePath() |
|
| 52 | { |
|
| 53 | return config('repository.generator.basePath', app()->path()); |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * Get array replacements. |
|
| 58 | * |
|
| 59 | * @return array |
|
| 60 | */ |
|
| 61 | public function getReplacements() |
|
| 62 | { |
|
| 63 | return array_merge(parent::getReplacements(), [ |
|
| 64 | 'fillable' => $this->getFillable(), |
|
| 65 | ]); |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * Get the fillable attributes. |
|
| 70 | * |
|
| 71 | * @return string |
|
| 72 | */ |
|
| 73 | public function getFillable() |
|
| 74 | { |
|
| 75 | if (! $this->fillable) { |
|
| 76 | return '[]'; |
|
| 77 | } |
|
| 78 | $results = '['.PHP_EOL; |
|
| 79 | ||
| 80 | foreach ($this->getSchemaParser()->toArray() as $column => $value) { |
|
| 81 | $results .= "\t\t'{$column}',".PHP_EOL; |
|
| 82 | } |
|
| 83 | ||
| 84 | return $results."\t".']'; |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * Get schema parser. |
|
| 89 | * |
|
| 90 | * @return SchemaParser |
|
| 91 | */ |
|
| 92 | public function getSchemaParser() |
|
| 93 | { |
|
| 94 | return new SchemaParser($this->fillable); |
|
| 95 | } |
|
| 96 | } |
|
| 97 | ||
| @@ 7-96 (lines=90) @@ | ||
| 4 | ||
| 5 | use Milkmeowo\Framework\Repository\Generators\Migrations\RulesParser; |
|
| 6 | ||
| 7 | class ValidatorGenerator extends Generator |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * Get stub name. |
|
| 11 | * |
|
| 12 | * @var string |
|
| 13 | */ |
|
| 14 | protected $stub = 'validator/validator'; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * Get root namespace. |
|
| 18 | * |
|
| 19 | * @return string |
|
| 20 | */ |
|
| 21 | public function getRootNamespace() |
|
| 22 | { |
|
| 23 | return parent::getRootNamespace().parent::getConfigGeneratorClassPath($this->getPathConfigNode()); |
|
| 24 | } |
|
| 25 | ||
| 26 | /** |
|
| 27 | * Get generator path config node. |
|
| 28 | * |
|
| 29 | * @return string |
|
| 30 | */ |
|
| 31 | public function getPathConfigNode() |
|
| 32 | { |
|
| 33 | return 'validators'; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * Get destination path for generated file. |
|
| 38 | * |
|
| 39 | * @return string |
|
| 40 | */ |
|
| 41 | public function getPath() |
|
| 42 | { |
|
| 43 | return $this->getBasePath().'/'.parent::getConfigGeneratorClassPath($this->getPathConfigNode(), true).'/'.$this->getName().'Validator.php'; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Get base path of destination file. |
|
| 48 | * |
|
| 49 | * @return string |
|
| 50 | */ |
|
| 51 | public function getBasePath() |
|
| 52 | { |
|
| 53 | return config('repository.generator.basePath', app()->path()); |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * Get array replacements. |
|
| 58 | * |
|
| 59 | * @return array |
|
| 60 | */ |
|
| 61 | public function getReplacements() |
|
| 62 | { |
|
| 63 | return array_merge(parent::getReplacements(), [ |
|
| 64 | 'rules' => $this->getRules(), |
|
| 65 | ]); |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * Get the rules. |
|
| 70 | * |
|
| 71 | * @return string |
|
| 72 | */ |
|
| 73 | public function getRules() |
|
| 74 | { |
|
| 75 | if (! $this->rules) { |
|
| 76 | return '[]'; |
|
| 77 | } |
|
| 78 | $results = '['.PHP_EOL; |
|
| 79 | ||
| 80 | foreach ($this->getSchemaParser()->toArray() as $column => $value) { |
|
| 81 | $results .= "\t\t'{$column}'\t=>'\t{$value}',".PHP_EOL; |
|
| 82 | } |
|
| 83 | ||
| 84 | return $results."\t".']'; |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * Get schema parser. |
|
| 89 | * |
|
| 90 | * @return RulesParser |
|
| 91 | */ |
|
| 92 | public function getSchemaParser() |
|
| 93 | { |
|
| 94 | return new RulesParser($this->rules); |
|
| 95 | } |
|
| 96 | } |
|
| 97 | ||