1 | <?php |
||
9 | trait ModuleCreator |
||
10 | { |
||
11 | use Normalizer; |
||
12 | |||
13 | /** |
||
14 | * Verify stub group |
||
15 | * |
||
16 | * @param string $stubGroup |
||
17 | * |
||
18 | * @throws \Exception |
||
19 | */ |
||
20 | protected function verifyStubGroup($stubGroup) |
||
21 | { |
||
22 | // first verify whether this group is in config file |
||
23 | |||
24 | if (!collect($this->laravel['modular.config']->stubGroups())->contains($stubGroup)) { |
||
|
|||
25 | throw new Exception("Stub group {$stubGroup} does not exist. You need to add it to stubs_groups"); |
||
26 | } |
||
27 | |||
28 | // then verify whether this stub group directory exists |
||
29 | $directory = $this->getStubGroupDirectory($stubGroup); |
||
30 | if (!$this->exists($directory)) { |
||
31 | throw new Exception("Stub group directory {$directory} does not exist"); |
||
32 | } |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Get directory for given stub group |
||
37 | * |
||
38 | * @param string $group |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | protected function getStubGroupDirectory($group) |
||
43 | { |
||
44 | return $this->normalizePath($this->laravel['modular.config']->stubsPath() . |
||
45 | DIRECTORY_SEPARATOR . |
||
46 | $this->laravel['modular.config']->stubGroupDirectory($group)); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Verify whether module config was published |
||
51 | * |
||
52 | * @throws \Exception |
||
53 | */ |
||
54 | protected function verifyConfigExistence() |
||
60 | |||
61 | /** |
||
62 | * Verify whether given file or directory exists |
||
63 | * |
||
64 | * @param string $path |
||
65 | * @param Module $module |
||
66 | * |
||
67 | * @return bool |
||
68 | */ |
||
69 | protected function exists($path, Module $module = null) |
||
70 | { |
||
71 | if ($module !== null) { |
||
72 | $path = $module->directory() . DIRECTORY_SEPARATOR . $path; |
||
73 | } |
||
74 | |||
75 | return $this->laravel['files']->exists($path); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Get stub group - either from input of default one |
||
80 | * |
||
81 | * @return mixed |
||
82 | */ |
||
83 | protected function getStubGroup() |
||
87 | |||
88 | protected function getFilesStubGroup() |
||
92 | |||
93 | /** |
||
94 | * Creates module directories |
||
95 | * |
||
96 | * @param Module $module |
||
97 | * @param string $stubGroup |
||
98 | */ |
||
99 | protected function createModuleDirectories(Module $module, $stubGroup) |
||
112 | |||
113 | /** |
||
114 | * Creates directory |
||
115 | * |
||
116 | * @param Module $module |
||
117 | * @param string $directory |
||
118 | * |
||
119 | * @return bool |
||
120 | * @throws Exception |
||
121 | */ |
||
122 | protected function createDirectory(Module $module, $directory) |
||
139 | |||
140 | /** |
||
141 | * Create files inside given module |
||
142 | * |
||
143 | * @param Module $module |
||
144 | * @param string $stubGroup |
||
145 | * @param string $subModule |
||
146 | * |
||
147 | * @return bool |
||
148 | */ |
||
149 | protected function createModuleFiles( |
||
172 | |||
173 | /** |
||
174 | * Copy single stub file into module |
||
175 | * |
||
176 | * @param Module $module |
||
177 | * @param $stubFile |
||
178 | * @param $stubGroup |
||
179 | * @param $moduleFile |
||
180 | * @param array $replacements |
||
181 | * |
||
182 | * @throws Exception |
||
183 | */ |
||
184 | protected function copyStubFileIntoModule( |
||
206 | |||
207 | /** |
||
208 | * Creates directory for given file (if it doesn't exist) |
||
209 | * |
||
210 | * @param Module $module |
||
211 | * @param string $file |
||
212 | */ |
||
213 | protected function createMissingDirectory(Module $module, $file) |
||
219 | |||
220 | /** |
||
221 | * Creates single file |
||
222 | * |
||
223 | * @param Module $module |
||
224 | * @param string $sourceFile |
||
225 | * @param string $destinationFile |
||
226 | * @param array $replacements |
||
227 | * |
||
228 | * @throws Exception |
||
229 | */ |
||
230 | protected function createFile( |
||
248 | } |
||
249 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: