1 | <?php |
||||
2 | |||||
3 | namespace Yeelight\Generators; |
||||
4 | |||||
5 | /** |
||||
6 | * Class ApiControllerGenerator |
||||
7 | * |
||||
8 | * @category Yeelight |
||||
9 | * |
||||
10 | * @package Yeelight\Generators |
||||
11 | * |
||||
12 | * @author Sheldon Lee <[email protected]> |
||||
13 | * |
||||
14 | * @license https://opensource.org/licenses/MIT MIT |
||||
15 | * |
||||
16 | * @link https://www.yeelight.com |
||||
17 | */ |
||||
18 | class ApiControllerGenerator extends Generator |
||||
19 | { |
||||
20 | /** |
||||
21 | * Get stub name. |
||||
22 | * |
||||
23 | * @var string |
||||
24 | */ |
||||
25 | protected $stub = 'controller/api_controller'; |
||||
26 | |||||
27 | /** |
||||
28 | * Get root namespace. |
||||
29 | * |
||||
30 | * @return string |
||||
31 | */ |
||||
32 | public function getRootNamespace() |
||||
33 | { |
||||
34 | return str_replace( |
||||
35 | '/', |
||||
36 | '\\', |
||||
37 | parent::getRootNamespace() . parent::getConfigGeneratorClassPath($this->getPathConfigNode()) |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
38 | ); |
||||
39 | } |
||||
40 | |||||
41 | /** |
||||
42 | * Get generator path config node. |
||||
43 | * |
||||
44 | * @return string |
||||
45 | */ |
||||
46 | public function getPathConfigNode() |
||||
47 | { |
||||
48 | return 'api_controllers'; |
||||
49 | } |
||||
50 | |||||
51 | /** |
||||
52 | * Get destination path for generated file. |
||||
53 | * |
||||
54 | * @return string |
||||
55 | */ |
||||
56 | public function getPath() |
||||
57 | { |
||||
58 | return $this->getBasePath() . '/' . |
||||
59 | parent::getConfigGeneratorClassPath( |
||||
0 ignored issues
–
show
Are you sure
parent::getConfigGenerat...PathConfigNode(), true) of type Illuminate\Config\Repository|mixed can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
60 | $this->getPathConfigNode(), |
||||
61 | true |
||||
62 | ) . |
||||
63 | '/' . |
||||
64 | $this->getControllerName() . 'Controller.php'; |
||||
65 | } |
||||
66 | |||||
67 | /** |
||||
68 | * Get base path of destination file. |
||||
69 | * |
||||
70 | * @return string |
||||
71 | */ |
||||
72 | public function getBasePath() |
||||
73 | { |
||||
74 | return config('repository.generator.basePath', app_path()); |
||||
75 | } |
||||
76 | |||||
77 | /** |
||||
78 | * Gets controller name based on model. |
||||
79 | * |
||||
80 | * @return string |
||||
81 | */ |
||||
82 | public function getControllerName() |
||||
83 | { |
||||
84 | return ucfirst($this->getPluralName()); |
||||
85 | } |
||||
86 | |||||
87 | /** |
||||
88 | * Gets plural name based on model. |
||||
89 | * |
||||
90 | * @return string |
||||
91 | */ |
||||
92 | public function getPluralName() |
||||
93 | { |
||||
94 | return str_plural(lcfirst(ucwords($this->getClass()))); |
||||
95 | } |
||||
96 | |||||
97 | /** |
||||
98 | * Get array replacements. |
||||
99 | * |
||||
100 | * @return array |
||||
101 | */ |
||||
102 | public function getReplacements() |
||||
103 | { |
||||
104 | return array_merge( |
||||
105 | parent::getReplacements(), |
||||
106 | [ |
||||
107 | 'controller' => $this->getControllerName(), |
||||
108 | 'plural' => $this->getPluralName(), |
||||
109 | 'singular' => $this->getSingularName(), |
||||
110 | 'validator' => $this->getValidator(), |
||||
111 | 'repository' => $this->getRepository(), |
||||
112 | 'appname' => $this->getAppNamespace(), |
||||
113 | ] |
||||
114 | ); |
||||
115 | } |
||||
116 | |||||
117 | /** |
||||
118 | * Gets singular name based on model. |
||||
119 | * |
||||
120 | * @return string |
||||
121 | */ |
||||
122 | public function getSingularName() |
||||
123 | { |
||||
124 | return str_singular(lcfirst(ucwords($this->getClass()))); |
||||
125 | } |
||||
126 | |||||
127 | /** |
||||
128 | * Gets validator full class name. |
||||
129 | * |
||||
130 | * @return string |
||||
131 | */ |
||||
132 | public function getValidator() |
||||
133 | { |
||||
134 | $validatorGenerator = new ValidatorGenerator( |
||||
135 | [ |
||||
136 | 'name' => $this->name, |
||||
0 ignored issues
–
show
The property
name does not exist on Yeelight\Generators\ApiControllerGenerator . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||||
137 | ] |
||||
138 | ); |
||||
139 | |||||
140 | $validator = $validatorGenerator->getRootNamespace().'\\'.$validatorGenerator->getName(); |
||||
141 | |||||
142 | return 'use ' . str_replace( |
||||
143 | [ |
||||
144 | '\\', |
||||
145 | '/', |
||||
146 | ] |
||||
147 | , '\\', $validator) . 'Validator;'; |
||||
148 | } |
||||
149 | |||||
150 | /** |
||||
151 | * Gets repository full class name. |
||||
152 | * |
||||
153 | * @return string |
||||
154 | */ |
||||
155 | public function getRepository() |
||||
156 | { |
||||
157 | $repositoryGenerator = new RepositoryInterfaceGenerator( |
||||
158 | [ |
||||
159 | 'name' => $this->name, |
||||
0 ignored issues
–
show
The property
name does not exist on Yeelight\Generators\ApiControllerGenerator . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||||
160 | ] |
||||
161 | ); |
||||
162 | |||||
163 | $repository = $repositoryGenerator->getRootNamespace().'\\'.$repositoryGenerator->getName(); |
||||
164 | |||||
165 | return 'use ' . str_replace( |
||||
166 | [ |
||||
167 | '\\', |
||||
168 | '/', |
||||
169 | ] |
||||
170 | , '\\', $repository) . 'Repository;'; |
||||
171 | } |
||||
172 | } |
||||
173 |