1
|
|
|
<?php |
2
|
|
|
namespace PSFS\Services; |
3
|
|
|
|
4
|
|
|
use PSFS\base\Cache; |
5
|
|
|
use PSFS\base\config\Config; |
6
|
|
|
use PSFS\base\exception\ConfigException; |
7
|
|
|
use PSFS\base\Service; |
8
|
|
|
|
9
|
|
|
class GeneratorService extends Service{ |
10
|
|
|
/** |
11
|
|
|
* @Inyectable |
12
|
|
|
* @var \PSFS\base\config\Config Servicio de configuración |
13
|
|
|
*/ |
14
|
|
|
protected $config; |
15
|
|
|
/** |
16
|
|
|
* @Inyectable |
17
|
|
|
* @var \PSFS\base\Security Servicio de autenticación |
18
|
|
|
*/ |
19
|
|
|
protected $security; |
20
|
|
|
/** |
21
|
|
|
* @Inyectable |
22
|
|
|
* @var \PSFS\base\Template Servicio de gestión de plantillas |
23
|
|
|
*/ |
24
|
|
|
protected $tpl; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Método que revisa las traducciones directorio a directorio |
28
|
|
|
* @param $path |
29
|
|
|
* @param $locale |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
|
|
public static function findTranslations($path, $locale) |
33
|
|
|
{ |
34
|
|
|
$locale_path = realpath(BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
35
|
|
|
$locale_path .= DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR; |
36
|
|
|
|
37
|
|
|
$translations = array(); |
38
|
|
|
if(file_exists($path)) |
39
|
|
|
{ |
40
|
|
|
$d = dir($path); |
|
|
|
|
41
|
|
|
while(false !== ($dir = $d->read())) |
42
|
|
|
{ |
43
|
|
|
Config::createDir($locale_path); |
44
|
|
|
if(!file_exists($locale_path . 'translations.po')) { |
45
|
|
|
file_put_contents($locale_path . 'translations.po', ''); |
46
|
|
|
} |
47
|
|
|
$inspect_path = realpath($path.DIRECTORY_SEPARATOR.$dir); |
48
|
|
|
$cmd_php = "export PATH=\$PATH:/opt/local/bin; xgettext ". $inspect_path . DIRECTORY_SEPARATOR ."*.php --from-code=UTF-8 -j -L PHP --debug --force-po -o {$locale_path}translations.po"; |
|
|
|
|
49
|
|
|
if(is_dir($path.DIRECTORY_SEPARATOR.$dir) && preg_match('/^\./',$dir) == 0) |
50
|
|
|
{ |
51
|
|
|
$res = _('Revisando directorio: ') . $inspect_path; |
52
|
|
|
$res .= _('Comando ejecutado: '). $cmd_php; |
53
|
|
|
$res .= shell_exec($cmd_php); |
54
|
|
|
usleep(10); |
55
|
|
|
$translations[] = $res; |
56
|
|
|
$translations = array_merge($translations, self::findTranslations($inspect_path, $locale)); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
return $translations; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Servicio que genera la estructura de un módulo o lo actualiza en caso de ser necesario |
65
|
|
|
* @param string $module |
66
|
|
|
* @param boolean $force |
67
|
|
|
* @param string $type |
68
|
|
|
* @param boolean $is_module |
|
|
|
|
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
|
|
public function createStructureModule($module, $force = false, $type = "", $isModule = false) |
72
|
|
|
{ |
73
|
|
|
$mod_path = CORE_DIR . DIRECTORY_SEPARATOR; |
74
|
|
|
$module = ucfirst($module); |
75
|
|
|
$this->createModulePath($module, $mod_path, $isModule); |
76
|
|
|
$this->createModulePathTree($module, $mod_path, $isModule); |
77
|
|
|
$this->createModuleBaseFiles($module, $mod_path, $force, $type, $isModule); |
78
|
|
|
$this->createModuleModels($module, $mod_path, $isModule); |
79
|
|
|
//$this->generateBaseApiTemplate($module, $mod_path, $isModule); |
|
|
|
|
80
|
|
|
//Redireccionamos al home definido |
81
|
|
|
$this->log->infoLog("Módulo generado correctamente"); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Service that creates the root paths for the modules |
86
|
|
|
* @param string $module |
87
|
|
|
* @param string $mod_path |
88
|
|
|
* @param boolean $isModule |
89
|
|
|
*/ |
90
|
|
|
private function createModulePath($module, $mod_path, $isModule = false) |
91
|
|
|
{ |
92
|
|
|
// Creates the src folder |
93
|
|
|
Config::createDir($mod_path); |
94
|
|
|
// Create module path |
95
|
|
|
if(false === $isModule) { |
96
|
|
|
Config::createDir($mod_path . $module); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Servicio que genera la estructura base |
102
|
|
|
* @param $module |
103
|
|
|
* @param $mod_path |
104
|
|
|
* @param boolean $isModule |
105
|
|
|
*/ |
106
|
|
|
private function createModulePathTree($module, $mod_path, $isModule = false) |
107
|
|
|
{ |
108
|
|
|
//Creamos las carpetas CORE del módulo |
109
|
|
|
$this->log->infoLog("Generamos la estructura"); |
110
|
|
|
$paths = array("Api", "Api/base", "Config", "Controller", "Form", "Models", "Public", "Templates", "Services", "Test"); |
|
|
|
|
111
|
|
|
$module_path = $isModule ? $mod_path : $mod_path . $module; |
112
|
|
|
foreach($paths as $path) { |
113
|
|
|
Config::createDir($module_path . DIRECTORY_SEPARATOR . $path); |
114
|
|
|
} |
115
|
|
|
//Creamos las carpetas de los assets |
116
|
|
|
$htmlPaths = array("css", "js", "img", "media", "font"); |
117
|
|
|
foreach($htmlPaths as $path) { |
118
|
|
|
Config::createDir($module_path . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . $path); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
if($isModule) { |
122
|
|
|
return $this->writeTemplateToFile(json_encode([ |
123
|
|
|
"module" => "\\" . preg_replace('/(\\\|\/)/', '\\\\',$module), |
124
|
|
|
], JSON_PRETTY_PRINT), $mod_path . DIRECTORY_SEPARATOR . "module.json", true); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Servicio que genera las plantillas básicas de ficheros del módulo |
130
|
|
|
* @param string $module |
131
|
|
|
* @param string $mod_path |
132
|
|
|
* @param boolean $force |
133
|
|
|
* @param string $controllerType |
134
|
|
|
* @param boolean $isModule |
135
|
|
|
*/ |
136
|
|
|
private function createModuleBaseFiles($module, $mod_path, $force = false, $controllerType = '', $isModule = false) |
|
|
|
|
137
|
|
|
{ |
138
|
|
|
$module_path = $isModule ? $mod_path : $mod_path . $module; |
139
|
|
|
$this->generateControllerTemplate($module, $module_path, $force, $controllerType); |
140
|
|
|
$this->generateServiceTemplate($module, $module_path, $force); |
141
|
|
|
$this->genereateAutoloaderTemplate($module, $module_path, $force, $isModule); |
142
|
|
|
$this->generateSchemaTemplate($module, $module_path, $force); |
143
|
|
|
$this->generatePropertiesTemplate($module, $module_path, $force); |
144
|
|
|
$this->generateConfigTemplate($module_path, $force); |
145
|
|
|
$this->generateIndexTemplate($module, $module_path, $force); |
146
|
|
|
$this->generatePublicTemplates($module_path, $force); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Servicio que ejecuta Propel y genera el modelo de datos |
151
|
|
|
* @param string $module |
152
|
|
|
* @param string $path |
153
|
|
|
* @param boolean $isModule |
154
|
|
|
*/ |
155
|
|
|
private function createModuleModels($module, $path, $isModule = false) |
156
|
|
|
{ |
157
|
|
|
$module_path = $isModule ? $path : $path . $module; |
158
|
|
|
$module_path = str_replace(BASE_DIR . DIRECTORY_SEPARATOR, '', $module_path); |
159
|
|
|
//Generamos las clases de propel y la configuración |
160
|
|
|
$exec = "export PATH=\$PATH:/opt/local/bin; " . BASE_DIR . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "propel "; |
|
|
|
|
161
|
|
|
$schemaOpt = " --schema-dir=" . CORE_DIR . DIRECTORY_SEPARATOR . $module_path . DIRECTORY_SEPARATOR . "Config"; |
|
|
|
|
162
|
|
|
$opt = " --config-dir=" . CORE_DIR . DIRECTORY_SEPARATOR . $module_path . DIRECTORY_SEPARATOR . "Config --output-dir=" . CORE_DIR . " --verbose"; |
|
|
|
|
163
|
|
|
$this->log->infoLog("[GENERATOR] Ejecutamos propel:\n" . $exec . "build" . $opt . $schemaOpt); |
164
|
|
|
$ret = shell_exec($exec . "build" . $opt . $schemaOpt); |
165
|
|
|
|
166
|
|
|
$this->log->infoLog("[GENERATOR] Generamos clases invocando a propel:\n $ret"); |
167
|
|
|
$ret = shell_exec($exec . "sql:build" . $opt . " --output-dir=" . CORE_DIR . DIRECTORY_SEPARATOR . $module_path . DIRECTORY_SEPARATOR . "Config" . $schemaOpt); |
|
|
|
|
168
|
|
|
$this->log->infoLog("[GENERATOR] Generamos sql invocando a propel:\n $ret"); |
169
|
|
|
$ret = shell_exec($exec . "config:convert" . $opt . " --output-dir=" . CORE_DIR . DIRECTORY_SEPARATOR . $module_path . DIRECTORY_SEPARATOR . "Config"); |
|
|
|
|
170
|
|
|
$this->log->infoLog("[GENERATOR] Generamos configuración invocando a propel:\n $ret"); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param string $module |
175
|
|
|
* @param string $mod_path |
176
|
|
|
* @param boolean $force |
177
|
|
|
* @param string $controllerType |
178
|
|
|
* @return boolean |
179
|
|
|
*/ |
180
|
|
|
private function generateControllerTemplate($module, $mod_path, $force = false, $controllerType = "") |
181
|
|
|
{ |
182
|
|
|
//Generamos el controlador base |
183
|
|
|
$this->log->infoLog("Generamos el controlador BASE"); |
184
|
|
|
$class = preg_replace('/(\\\|\/)/', '', $module); |
185
|
|
|
$controller = $this->tpl->dump("generator/controller.template.twig", array( |
186
|
|
|
"module" => $module, |
187
|
|
|
"namespace" => preg_replace('/(\\\|\/)/', '\\', $module), |
188
|
|
|
"url" => preg_replace('/(\\\|\/)/', '/', $module), |
189
|
|
|
"class" => $class, |
190
|
|
|
"controllerType" => $controllerType, |
191
|
|
|
)); |
192
|
|
|
return $this->writeTemplateToFile($controller, $mod_path . DIRECTORY_SEPARATOR . "Controller" . DIRECTORY_SEPARATOR . "{$class}Controller.php", $force); |
|
|
|
|
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param string $module |
197
|
|
|
* @param string $mod_path |
198
|
|
|
* @param boolean $force |
199
|
|
|
* @param string $controllerType |
200
|
|
|
* @return boolean |
201
|
|
|
*/ |
202
|
|
|
private function generateBaseApiTemplate($module, $mod_path, $force = false, $controllerType = "") |
203
|
|
|
{ |
204
|
|
|
$created = true; |
205
|
|
|
$modelPath = $mod_path . $module . DIRECTORY_SEPARATOR . 'Models'; |
206
|
|
|
if(file_exists($modelPath)) { |
207
|
|
|
$dir = dir($modelPath); |
208
|
|
|
while($file = $dir->read()) { |
209
|
|
|
if(!in_array($file, array('.', '..')) && !preg_match('/Query\.php$/i', $file) && preg_match('/\.php$/i', $file)) { |
|
|
|
|
210
|
|
|
$filename = str_replace(".php", "", $file); |
211
|
|
|
$this->log->infoLog("Generamos Api BASES para {$filename}"); |
212
|
|
|
$this->createApiBaseFile($module, $mod_path, $filename); |
213
|
|
|
$this->createApi($module, $mod_path, $force, $filename); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
return $created; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @param string $mod_path |
222
|
|
|
* @param boolean $force |
223
|
|
|
* @return boolean |
224
|
|
|
*/ |
225
|
|
|
private function generateConfigTemplate($mod_path, $force = false) |
226
|
|
|
{ |
227
|
|
|
//Generamos el fichero de configuración |
228
|
|
|
$this->log->infoLog("Generamos fichero vacío de configuración"); |
229
|
|
|
return $this->writeTemplateToFile("<?php\n\t", $mod_path . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "config.php", $force); |
|
|
|
|
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param string $module |
|
|
|
|
234
|
|
|
* @param string $mod_path |
235
|
|
|
* @param boolean $force |
236
|
|
|
* @return boolean |
237
|
|
|
*/ |
238
|
|
|
private function generatePublicTemplates($mod_path, $force = false) |
239
|
|
|
{ |
240
|
|
|
//Generamos el fichero de configuración |
241
|
|
|
$this->log->infoLog("Generamos ficheros para assets base"); |
242
|
|
|
$css = $this->writeTemplateToFile("/* CSS3 STYLES */\n\n", $mod_path . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . "css" . DIRECTORY_SEPARATOR . "styles.css", $force); |
|
|
|
|
243
|
|
|
$js = $this->writeTemplateToFile("/* APP MODULE JS */\n\n(function() {\n\t'use strict';\n})();", $mod_path . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . "js" . DIRECTORY_SEPARATOR . "app.js", $force); |
|
|
|
|
244
|
|
|
return ($css && $js); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @param string $module |
249
|
|
|
* @param string $mod_path |
250
|
|
|
* @param boolean $force |
251
|
|
|
* @return boolean |
252
|
|
|
*/ |
253
|
|
|
private function generateServiceTemplate($module, $mod_path, $force = false) |
254
|
|
|
{ |
255
|
|
|
//Generamos el controlador base |
256
|
|
|
$this->log->infoLog("Generamos el servicio BASE"); |
257
|
|
|
$class = preg_replace('/(\\\|\/)/', '', $module); |
258
|
|
|
$controller = $this->tpl->dump("generator/service.template.twig", array( |
259
|
|
|
"module" => $module, |
260
|
|
|
"namespace" => preg_replace('/(\\\|\/)/', '\\', $module), |
261
|
|
|
"class" => $class, |
262
|
|
|
)); |
263
|
|
|
return $this->writeTemplateToFile($controller, $mod_path . DIRECTORY_SEPARATOR . "Services" . DIRECTORY_SEPARATOR . "{$class}Service.php", $force); |
|
|
|
|
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @param string $module |
268
|
|
|
* @param string $mod_path |
269
|
|
|
* @param boolean $force |
270
|
|
|
* @param boolean $isModule |
271
|
|
|
* @return boolean |
272
|
|
|
*/ |
273
|
|
|
private function genereateAutoloaderTemplate($module, $mod_path, $force = false, $isModule = false) |
274
|
|
|
{ |
275
|
|
|
//Generamos el autoloader del módulo |
276
|
|
|
$this->log->infoLog("Generamos el autoloader"); |
277
|
|
|
$autoloader = $this->tpl->dump("generator/autoloader.template.twig", array( |
278
|
|
|
"module" => $module, |
279
|
|
|
"autoloader" => preg_replace('/(\\\|\/)/', '_', $module), |
280
|
|
|
"regex" => preg_replace('/(\\\|\/)/m', '\\\\\\\\\\\\', $module), |
281
|
|
|
"is_module" => $isModule, |
282
|
|
|
)); |
283
|
|
|
return $this->writeTemplateToFile($autoloader, $mod_path . DIRECTORY_SEPARATOR . "autoload.php", $force); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* @param string $module |
288
|
|
|
* @param string $mod_path |
289
|
|
|
* @param boolean $force |
290
|
|
|
* @return boolean |
291
|
|
|
*/ |
292
|
|
|
private function generateSchemaTemplate($module, $mod_path, $force = false) |
293
|
|
|
{ |
294
|
|
|
//Generamos el autoloader del módulo |
295
|
|
|
$this->log->infoLog("Generamos el schema"); |
296
|
|
|
$schema = $this->tpl->dump("generator/schema.propel.twig", array( |
297
|
|
|
"module" => $module, |
298
|
|
|
"namespace" => preg_replace('/(\\\|\/)/', '\\', $module), |
299
|
|
|
"prefix" => preg_replace('/(\\\|\/)/', '', $module), |
300
|
|
|
"db" => $this->config->get("db_name"), |
301
|
|
|
)); |
302
|
|
|
return $this->writeTemplateToFile($schema, $mod_path . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "schema.xml", $force); |
|
|
|
|
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @param string $module |
307
|
|
|
* @param string $mod_path |
308
|
|
|
* @param boolean $force |
309
|
|
|
* @return boolean |
310
|
|
|
*/ |
311
|
|
|
private function generatePropertiesTemplate($module, $mod_path, $force = false) |
312
|
|
|
{ |
313
|
|
|
$this->log->infoLog("Generamos la configuración de Propel"); |
314
|
|
|
$build_properties = $this->tpl->dump("generator/build.properties.twig", array( |
315
|
|
|
"module" => $module, |
316
|
|
|
"host" => $this->config->get("db_host"), |
317
|
|
|
"port" => $this->config->get("db_port"), |
318
|
|
|
"user" => $this->config->get("db_user"), |
319
|
|
|
"pass" => $this->config->get("db_password"), |
320
|
|
|
"db" => $this->config->get("db_name"), |
321
|
|
|
"namespace" => preg_replace('/(\\\|\/)/', '', $module), |
322
|
|
|
)); |
323
|
|
|
return $this->writeTemplateToFile($build_properties, $mod_path . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "propel.yml", $force); |
|
|
|
|
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @param string $module |
328
|
|
|
* @param string $mod_path |
329
|
|
|
* @param boolean $force |
330
|
|
|
* @return boolean |
331
|
|
|
*/ |
332
|
|
|
private function generateIndexTemplate($module, $mod_path, $force = false) |
333
|
|
|
{ |
334
|
|
|
//Generamos la plantilla de index |
335
|
|
|
$this->log->infoLog("Generamos una plantilla base por defecto"); |
336
|
|
|
$index = $this->tpl->dump("generator/index.template.twig", array( |
337
|
|
|
"module" => $module, |
338
|
|
|
)); |
339
|
|
|
return $this->writeTemplateToFile($index, $mod_path . DIRECTORY_SEPARATOR . "Templates" . DIRECTORY_SEPARATOR . "index.html.twig", $force); |
|
|
|
|
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* Método que graba el contenido de una plantilla en un fichero |
344
|
|
|
* @param string $fileContent |
345
|
|
|
* @param string $filename |
346
|
|
|
* @param boolean $force |
347
|
|
|
* @return boolean |
348
|
|
|
*/ |
349
|
|
|
private function writeTemplateToFile($fileContent, $filename, $force = false) { |
350
|
|
|
$created = false; |
351
|
|
|
if ($force || !file_exists($filename)) { |
352
|
|
|
try { |
353
|
|
|
$this->cache->storeData($filename, $fileContent, Cache::TEXT,true); |
354
|
|
|
$created = true; |
355
|
|
|
} catch(\Exception $e) { |
356
|
|
|
$this->log->errorLog($e->getMessage()); |
357
|
|
|
} |
358
|
|
|
} else{ |
359
|
|
|
$this->log->errorLog($filename . _(' not exists or cant write')); |
360
|
|
|
} |
361
|
|
|
return $created; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* Create ApiBase |
366
|
|
|
* @param string $module |
367
|
|
|
* @param string $mod_path |
368
|
|
|
* @param string $api |
369
|
|
|
* |
370
|
|
|
* @return bool |
371
|
|
|
*/ |
372
|
|
|
private function createApiBaseFile($module, $mod_path, $api) |
373
|
|
|
{ |
374
|
|
|
$controller = $this->tpl->dump("generator/api.base.template.twig", array( |
375
|
|
|
"module" => $module, |
376
|
|
|
"api" => $api |
377
|
|
|
)); |
378
|
|
|
|
379
|
|
|
return $this->writeTemplateToFile($controller, $mod_path . $module . DIRECTORY_SEPARATOR . "Api" . DIRECTORY_SEPARATOR . 'base' . DIRECTORY_SEPARATOR . "{$api}BaseApi.php", true); |
|
|
|
|
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* Create Api |
384
|
|
|
* @param string $module |
385
|
|
|
* @param string $mod_path |
386
|
|
|
* @param bool $force |
387
|
|
|
* @param string $api |
388
|
|
|
* |
389
|
|
|
* @return bool |
390
|
|
|
*/ |
391
|
|
|
private function createApi($module, $mod_path, $force, $api) |
392
|
|
|
{ |
393
|
|
|
$controller = $this->tpl->dump("generator/api.template.twig", array( |
394
|
|
|
"module" => $module, |
395
|
|
|
"api" => $api |
396
|
|
|
)); |
397
|
|
|
|
398
|
|
|
return $this->writeTemplateToFile($controller, $mod_path . $module . DIRECTORY_SEPARATOR . "Api" . DIRECTORY_SEPARATOR . "{$api}.php", $force); |
|
|
|
|
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Method that copy resources recursively |
403
|
|
|
* @param string $dest |
404
|
|
|
* @param boolean $force |
405
|
|
|
* @param $filename_path |
406
|
|
|
* @param boolean $debug |
407
|
|
|
*/ |
408
|
|
|
public static function copyResources($dest, $force, $filename_path, $debug) |
409
|
|
|
{ |
410
|
|
|
if (file_exists($filename_path)) { |
411
|
|
|
$destfolder = basename($filename_path); |
412
|
|
|
if (!file_exists(WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder) || $debug || $force) { |
413
|
|
|
if (is_dir($filename_path)) { |
414
|
|
|
self::copyr($filename_path, WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder); |
415
|
|
|
}else { |
416
|
|
|
if (@copy($filename_path, WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder) === FALSE) { |
417
|
|
|
throw new ConfigException("Can't copy ".$filename_path." to ".WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder); |
|
|
|
|
418
|
|
|
} |
419
|
|
|
} |
420
|
|
|
} |
421
|
|
|
} |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Method that copy a resource |
426
|
|
|
* @param string $src |
427
|
|
|
* @param string $dst |
428
|
|
|
* @throws ConfigException |
429
|
|
|
*/ |
430
|
|
|
public static function copyr($src, $dst) { |
431
|
|
|
$dir = opendir($src); |
432
|
|
|
Config::createDir($dst); |
433
|
|
|
while (false !== ($file = readdir($dir))) { |
434
|
|
|
if (($file != '.') && ($file != '..')) { |
435
|
|
|
if (is_dir($src.'/'.$file)) { |
436
|
|
|
self::copyr($src.'/'.$file, $dst.'/'.$file); |
437
|
|
|
} elseif (@copy($src.'/'.$file, $dst.'/'.$file) === false) { |
438
|
|
|
throw new ConfigException("Can't copy ".$src." to ".$dst); |
439
|
|
|
} |
440
|
|
|
} |
441
|
|
|
} |
442
|
|
|
closedir($dir); |
443
|
|
|
} |
444
|
|
|
} |
445
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.