@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use PSFS\base\exception\ConfigException; |
7 | 7 | use PSFS\base\Service; |
8 | 8 | |
9 | - class GeneratorService extends Service{ |
|
9 | + class GeneratorService extends Service { |
|
10 | 10 | /** |
11 | 11 | * @Inyectable |
12 | 12 | * @var \PSFS\base\config\Config Servicio de configuración |
@@ -31,25 +31,25 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public static function findTranslations($path, $locale) |
33 | 33 | { |
34 | - $locale_path = realpath(BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
35 | - $locale_path .= DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR; |
|
34 | + $locale_path = realpath(BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
35 | + $locale_path .= DIRECTORY_SEPARATOR.$locale.DIRECTORY_SEPARATOR.'LC_MESSAGES'.DIRECTORY_SEPARATOR; |
|
36 | 36 | |
37 | 37 | $translations = array(); |
38 | - if(file_exists($path)) |
|
38 | + if (file_exists($path)) |
|
39 | 39 | { |
40 | 40 | $d = dir($path); |
41 | - while(false !== ($dir = $d->read())) |
|
41 | + while (false !== ($dir = $d->read())) |
|
42 | 42 | { |
43 | 43 | Config::createDir($locale_path); |
44 | - if(!file_exists($locale_path . 'translations.po')) { |
|
45 | - file_put_contents($locale_path . 'translations.po', ''); |
|
44 | + if (!file_exists($locale_path.'translations.po')) { |
|
45 | + file_put_contents($locale_path.'translations.po', ''); |
|
46 | 46 | } |
47 | 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) |
|
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 | 50 | { |
51 | - $res = _('Revisando directorio: ') . $inspect_path; |
|
52 | - $res .= _('Comando ejecutado: '). $cmd_php; |
|
51 | + $res = _('Revisando directorio: ').$inspect_path; |
|
52 | + $res .= _('Comando ejecutado: ').$cmd_php; |
|
53 | 53 | $res .= shell_exec($cmd_php); |
54 | 54 | usleep(10); |
55 | 55 | $translations[] = $res; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function createStructureModule($module, $force = false, $type = "") |
71 | 71 | { |
72 | - $mod_path = CORE_DIR . DIRECTORY_SEPARATOR; |
|
72 | + $mod_path = CORE_DIR.DIRECTORY_SEPARATOR; |
|
73 | 73 | $module = ucfirst($module); |
74 | 74 | $this->createModulePath($module, $mod_path); |
75 | 75 | $this->createModulePathTree($module, $mod_path); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | //Creamos el directorio base de los módulos |
91 | 91 | Config::createDir($mod_path); |
92 | 92 | //Creamos la carpeta del módulo |
93 | - Config::createDir($mod_path . $module); |
|
93 | + Config::createDir($mod_path.$module); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | //Creamos las carpetas CORE del módulo |
104 | 104 | $this->log->infoLog("Generamos la estructura"); |
105 | 105 | $paths = array("Api", "Api/base", "Config", "Controller", "Form", "Models", "Public", "Templates", "Services", "Test"); |
106 | - foreach($paths as $path) { |
|
107 | - Config::createDir($mod_path . $module . DIRECTORY_SEPARATOR . $path); |
|
106 | + foreach ($paths as $path) { |
|
107 | + Config::createDir($mod_path.$module.DIRECTORY_SEPARATOR.$path); |
|
108 | 108 | } |
109 | 109 | //Creamos las carpetas de los assets |
110 | 110 | $htmlPaths = array("css", "js", "img", "media", "font"); |
111 | - foreach($htmlPaths as $path) { |
|
112 | - Config::createDir($mod_path . $module . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . $path); |
|
111 | + foreach ($htmlPaths as $path) { |
|
112 | + Config::createDir($mod_path.$module.DIRECTORY_SEPARATOR."Public".DIRECTORY_SEPARATOR.$path); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | private function createModuleModels($module) |
140 | 140 | { |
141 | 141 | //Generamos las clases de propel y la configuración |
142 | - $exec = "export PATH=\$PATH:/opt/local/bin; " . BASE_DIR . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "propel "; |
|
143 | - $schemaOpt = " --schema-dir=" . CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . "Config"; |
|
144 | - $opt = " --config-dir=" . CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . "Config --output-dir=" . CORE_DIR . " --verbose"; |
|
145 | - $ret = shell_exec($exec . "build" . $opt . $schemaOpt); |
|
142 | + $exec = "export PATH=\$PATH:/opt/local/bin; ".BASE_DIR.DIRECTORY_SEPARATOR."vendor".DIRECTORY_SEPARATOR."bin".DIRECTORY_SEPARATOR."propel "; |
|
143 | + $schemaOpt = " --schema-dir=".CORE_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR."Config"; |
|
144 | + $opt = " --config-dir=".CORE_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR."Config --output-dir=".CORE_DIR." --verbose"; |
|
145 | + $ret = shell_exec($exec."build".$opt.$schemaOpt); |
|
146 | 146 | |
147 | 147 | $this->log->infoLog("Generamos clases invocando a propel:\n $ret"); |
148 | - $ret = shell_exec($exec . "sql:build" . $opt . " --output-dir=" . CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . "Config" . $schemaOpt); |
|
148 | + $ret = shell_exec($exec."sql:build".$opt." --output-dir=".CORE_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR."Config".$schemaOpt); |
|
149 | 149 | $this->log->infoLog("Generamos sql invocando a propel:\n $ret"); |
150 | - $ret = shell_exec($exec . "config:convert" . $opt . " --output-dir=" . CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . "Config"); |
|
150 | + $ret = shell_exec($exec."config:convert".$opt." --output-dir=".CORE_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR."Config"); |
|
151 | 151 | $this->log->infoLog("Generamos configuración invocando a propel:\n $ret"); |
152 | 152 | } |
153 | 153 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | "class" => $class, |
171 | 171 | "controllerType" => $controllerType, |
172 | 172 | )); |
173 | - return $this->writeTemplateToFile($controller, $mod_path . $module . DIRECTORY_SEPARATOR . "Controller" . DIRECTORY_SEPARATOR . "{$class}Controller.php", $force); |
|
173 | + return $this->writeTemplateToFile($controller, $mod_path.$module.DIRECTORY_SEPARATOR."Controller".DIRECTORY_SEPARATOR."{$class}Controller.php", $force); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | private function generateBaseApiTemplate($module, $mod_path, $force = false, $controllerType = "") |
184 | 184 | { |
185 | 185 | $created = true; |
186 | - $modelPath = $mod_path . $module . DIRECTORY_SEPARATOR . 'Models'; |
|
187 | - if(file_exists($modelPath)) { |
|
186 | + $modelPath = $mod_path.$module.DIRECTORY_SEPARATOR.'Models'; |
|
187 | + if (file_exists($modelPath)) { |
|
188 | 188 | $dir = dir($modelPath); |
189 | - while($file = $dir->read()) { |
|
190 | - if(!in_array($file, array('.', '..')) && !preg_match('/Query\.php$/i', $file) && preg_match('/\.php$/i', $file)) { |
|
189 | + while ($file = $dir->read()) { |
|
190 | + if (!in_array($file, array('.', '..')) && !preg_match('/Query\.php$/i', $file) && preg_match('/\.php$/i', $file)) { |
|
191 | 191 | $filename = str_replace(".php", "", $file); |
192 | 192 | $this->log->infoLog("Generamos Api BASES para {$filename}"); |
193 | 193 | $this->createApiBaseFile($module, $mod_path, $filename); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | { |
209 | 209 | //Generamos el fichero de configuración |
210 | 210 | $this->log->infoLog("Generamos fichero vacío de configuración"); |
211 | - return $this->writeTemplateToFile("<?php\n\t", $mod_path . $module . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "config.php", $force); |
|
211 | + return $this->writeTemplateToFile("<?php\n\t", $mod_path.$module.DIRECTORY_SEPARATOR."Config".DIRECTORY_SEPARATOR."config.php", $force); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | { |
222 | 222 | //Generamos el fichero de configuración |
223 | 223 | $this->log->infoLog("Generamos ficheros para assets base"); |
224 | - $css = $this->writeTemplateToFile("/* CSS3 STYLES */\n\n", $mod_path . $module . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . "css" . DIRECTORY_SEPARATOR . "styles.css", false); |
|
225 | - $js = $this->writeTemplateToFile("/* APP MODULE JS */\n\n(function() {\n\t'use strict';\n})();", $mod_path . $module . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . "js" . DIRECTORY_SEPARATOR . "app.js", false); |
|
224 | + $css = $this->writeTemplateToFile("/* CSS3 STYLES */\n\n", $mod_path.$module.DIRECTORY_SEPARATOR."Public".DIRECTORY_SEPARATOR."css".DIRECTORY_SEPARATOR."styles.css", false); |
|
225 | + $js = $this->writeTemplateToFile("/* APP MODULE JS */\n\n(function() {\n\t'use strict';\n})();", $mod_path.$module.DIRECTORY_SEPARATOR."Public".DIRECTORY_SEPARATOR."js".DIRECTORY_SEPARATOR."app.js", false); |
|
226 | 226 | return ($css && $js); |
227 | 227 | } |
228 | 228 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | "namespace" => preg_replace('/(\\\|\/)/', '\\', $module), |
243 | 243 | "class" => $class, |
244 | 244 | )); |
245 | - return $this->writeTemplateToFile($controller, $mod_path . $module . DIRECTORY_SEPARATOR . "Services" . DIRECTORY_SEPARATOR . "{$class}Service.php", $force); |
|
245 | + return $this->writeTemplateToFile($controller, $mod_path.$module.DIRECTORY_SEPARATOR."Services".DIRECTORY_SEPARATOR."{$class}Service.php", $force); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | "autoloader" => preg_replace('/(\\\|\/)/', '_', $module), |
261 | 261 | "regex" => preg_replace('/(\\\|\/)/m', '\\\\\\', $module), |
262 | 262 | )); |
263 | - return $this->writeTemplateToFile($autoloader, $mod_path . $module . DIRECTORY_SEPARATOR . "autoload.php", $force); |
|
263 | + return $this->writeTemplateToFile($autoloader, $mod_path.$module.DIRECTORY_SEPARATOR."autoload.php", $force); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | "prefix" => preg_replace('/(\\\|\/)/', '', $module), |
280 | 280 | "db" => $this->config->get("db_name"), |
281 | 281 | )); |
282 | - return $this->writeTemplateToFile($schema, $mod_path . $module . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "schema.xml", $force); |
|
282 | + return $this->writeTemplateToFile($schema, $mod_path.$module.DIRECTORY_SEPARATOR."Config".DIRECTORY_SEPARATOR."schema.xml", $force); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | "db" => $this->config->get("db_name"), |
301 | 301 | "namespace" => preg_replace('/(\\\|\/)/', '', $module), |
302 | 302 | )); |
303 | - return $this->writeTemplateToFile($build_properties, $mod_path . $module . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "propel.yml", $force); |
|
303 | + return $this->writeTemplateToFile($build_properties, $mod_path.$module.DIRECTORY_SEPARATOR."Config".DIRECTORY_SEPARATOR."propel.yml", $force); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | $index = $this->tpl->dump("generator/index.template.twig", array( |
317 | 317 | "module" => $module, |
318 | 318 | )); |
319 | - return $this->writeTemplateToFile($index, $mod_path . $module . DIRECTORY_SEPARATOR . "Templates" . DIRECTORY_SEPARATOR . "index.html.twig", $force); |
|
319 | + return $this->writeTemplateToFile($index, $mod_path.$module.DIRECTORY_SEPARATOR."Templates".DIRECTORY_SEPARATOR."index.html.twig", $force); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -330,13 +330,13 @@ discard block |
||
330 | 330 | $created = false; |
331 | 331 | if ($force || !file_exists($filename)) { |
332 | 332 | try { |
333 | - $this->cache->storeData($filename, $fileContent, Cache::TEXT,true); |
|
333 | + $this->cache->storeData($filename, $fileContent, Cache::TEXT, true); |
|
334 | 334 | $created = true; |
335 | - } catch(\Exception $e) { |
|
335 | + }catch (\Exception $e) { |
|
336 | 336 | $this->log->errorLog($e->getMessage()); |
337 | 337 | } |
338 | - } else{ |
|
339 | - $this->log->errorLog($filename . _(' not exists or cant write')); |
|
338 | + }else { |
|
339 | + $this->log->errorLog($filename._(' not exists or cant write')); |
|
340 | 340 | } |
341 | 341 | return $created; |
342 | 342 | } |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | "api" => $api |
357 | 357 | )); |
358 | 358 | |
359 | - return $this->writeTemplateToFile($controller, $mod_path . $module . DIRECTORY_SEPARATOR . "Api" . DIRECTORY_SEPARATOR . 'base' . DIRECTORY_SEPARATOR . "{$api}BaseApi.php", true); |
|
359 | + return $this->writeTemplateToFile($controller, $mod_path.$module.DIRECTORY_SEPARATOR."Api".DIRECTORY_SEPARATOR.'base'.DIRECTORY_SEPARATOR."{$api}BaseApi.php", true); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | "api" => $api |
376 | 376 | )); |
377 | 377 | |
378 | - return $this->writeTemplateToFile($controller, $mod_path . $module . DIRECTORY_SEPARATOR . "Api" . DIRECTORY_SEPARATOR . "{$api}.php", $force); |
|
378 | + return $this->writeTemplateToFile($controller, $mod_path.$module.DIRECTORY_SEPARATOR."Api".DIRECTORY_SEPARATOR."{$api}.php", $force); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | /** |