|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Milkmeowo\Framework\Repository\Generators; |
|
4
|
|
|
|
|
5
|
|
|
use Milkmeowo\Framework\Repository\Generators\Migrations\SchemaParser; |
|
6
|
|
|
|
|
7
|
|
View Code Duplication |
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
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.