1
|
|
|
<?php |
2
|
|
|
namespace PSFS\controller; |
3
|
|
|
|
4
|
|
|
use PSFS\base\config\ModuleForm; |
5
|
|
|
use PSFS\base\exception\ConfigException; |
6
|
|
|
use PSFS\base\Logger; |
7
|
|
|
use PSFS\base\Security; |
8
|
|
|
use PSFS\controller\base\Admin; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class GeneratorController |
12
|
|
|
* @package PSFS\controller |
13
|
|
|
* @domain ROOT |
14
|
|
|
*/ |
15
|
|
|
class GeneratorController extends Admin |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @Inyectable |
19
|
|
|
* @var \PSFS\services\GeneratorService Servicio de generación de estructura de directorios |
20
|
|
|
*/ |
21
|
|
|
protected $gen; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Método que genera un nuevo módulo |
25
|
|
|
* @GET |
26
|
|
|
* @route /admin/module |
27
|
|
|
* |
28
|
|
|
* @return string HTML |
|
|
|
|
29
|
|
|
* @throws \HttpException |
30
|
|
|
*/ |
31
|
|
|
public function generateModule() |
32
|
|
|
{ |
33
|
|
|
Logger::log("Arranque generador de módulos al solicitar " . $this->getRequest()->getRequestUri()); |
34
|
|
|
/* @var $form \PSFS\base\config\ConfigForm */ |
35
|
|
|
$form = new ModuleForm(); |
36
|
|
|
$form->build(); |
37
|
|
|
return $this->render("modules.html.twig", array( |
38
|
|
|
'properties' => $this->config->getPropelParams(), |
39
|
|
|
'form' => $form, |
40
|
|
|
)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @POST |
45
|
|
|
* @route /admin/module |
46
|
|
|
* @return string |
|
|
|
|
47
|
|
|
*/ |
48
|
|
|
public function doGenerateModule() |
49
|
|
|
{ |
50
|
|
|
$form = new ModuleForm(); |
51
|
|
|
$form->build(); |
52
|
|
|
$form->hydrate(); |
53
|
|
|
if ($form->isValid()) { |
54
|
|
|
$module = $form->getFieldValue("module"); |
55
|
|
|
$force = $form->getFieldValue("force"); |
56
|
|
|
$type = $form->getFieldValue("controllerType"); |
57
|
|
|
try { |
58
|
|
|
$module = preg_replace('/(\\\|\/)/', '/', $module); |
59
|
|
|
$module = preg_replace('/^\//', '', $module); |
60
|
|
|
$this->gen->createStructureModule($module, $force, $type); |
|
|
|
|
61
|
|
|
Security::getInstance()->setFlash("callback_message", str_replace("%s", $module, _("Módulo %s generado correctamente"))); |
|
|
|
|
62
|
|
|
Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-module", true)); |
63
|
|
|
} catch (\Exception $e) { |
64
|
|
|
Logger::getInstance()->infoLog($e->getMessage() . " [" . $e->getFile() . ":" . $e->getLine() . "]"); |
65
|
|
|
throw new ConfigException('Error al generar el módulo, prueba a cambiar los permisos', 403); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
return $this->render("modules.html.twig", array( |
69
|
|
|
'properties' => $this->config->getPropelParams(), |
70
|
|
|
'form' => $form, |
71
|
|
|
)); |
72
|
|
|
} |
73
|
|
|
} |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.