From a4d7783d56b88d98a6e877f54ca188de7184ee21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Garc=C3=ADa=20G=C3=B3mez?= Date: Tue, 12 Oct 2021 10:56:08 +0200 Subject: [PATCH] =?UTF-8?q?Peque=C3=B1as=20mejoras=20al=20c=C3=B3digo=20y?= =?UTF-8?q?=20eliminados=20los=20archivos=20innecesarios.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SAMPLES/Controller.php.sample | 10 +- SAMPLES/Cron.php.sample | 2 +- ....sample => ExtensionController.php.sample} | 11 +- ...l.php.sample => ExtensionModel.php.sample} | 18 +- SAMPLES/Init.php.sample | 4 +- SAMPLES/ListController.php.sample | 6 +- SAMPLES/table.xml.sample | 20 -- fsmaker.php | 247 ++++++++++-------- 8 files changed, 162 insertions(+), 156 deletions(-) rename SAMPLES/{extensionController.php.sample => ExtensionController.php.sample} (78%) rename SAMPLES/{extensionModel.php.sample => ExtensionModel.php.sample} (86%) delete mode 100644 SAMPLES/table.xml.sample diff --git a/SAMPLES/Controller.php.sample b/SAMPLES/Controller.php.sample index ef4e74a..435dfa3 100644 --- a/SAMPLES/Controller.php.sample +++ b/SAMPLES/Controller.php.sample @@ -4,15 +4,15 @@ namespace FacturaScripts\[[NAME_SPACE]]\Controller; class [[NAME]] extends \FacturaScripts\Core\Base\Controller { public function getPageData() { - $pageData = parent::getPageData(); - $pageData["title"] = "[[NAME]]"; - $pageData["menu"] = "admin"; - $pageData["icon"] = "fas fa-page"; + $data = parent::getPageData(); + $data["menu"] = "admin"; + $data["title"] = "[[NAME]]"; + $data["icon"] = "fas fa-page"; return $pageData; } public function privateCore(&$response, $user, $permissions) { parent::privateCore($response, $user, $permissions); - /// tu código aquí + // tu código aquí } } diff --git a/SAMPLES/Cron.php.sample b/SAMPLES/Cron.php.sample index 729856b..85707f2 100644 --- a/SAMPLES/Cron.php.sample +++ b/SAMPLES/Cron.php.sample @@ -6,7 +6,7 @@ class Cron extends \FacturaScripts\Core\Base\CronClass public function run() { /* if ($this->isTimeForJob("my-job-name", "6 hours")) { - /// su código aquí + // su código aquí $this->jobDone("my-job-name"); } */ diff --git a/SAMPLES/extensionController.php.sample b/SAMPLES/ExtensionController.php.sample similarity index 78% rename from SAMPLES/extensionController.php.sample rename to SAMPLES/ExtensionController.php.sample index 5b58744..8270ec4 100644 --- a/SAMPLES/extensionController.php.sample +++ b/SAMPLES/ExtensionController.php.sample @@ -3,32 +3,31 @@ namespace FacturaScripts\[[NAME_SPACE]]\Extension\Controller; class [[NAME]] { - // createViews() se ejecuta una vez realiado el createViews() del controlador. + // createViews() se ejecuta una vez realizado el createViews() del controlador. public function createViews() { return function() { - /// tu código aquí + // tu código aquí }; } // execAfterAction() se ejecuta tras el execAfterAction() del controlador. public function execAfterAction() { return function($action) { - /// tu código aquí + // tu código aquí }; } // execPreviousAction() se ejecuta después del execPreviousAction() del controlador. Si devolvemos false detenemos la ejecución del controlador. public function execPreviousAction() { return function($action) { - /// tu código aquí + // tu código aquí }; } // loadData() se ejecuta tras el loadData() del controlador. Recibe los parámetros $viewName y $view. public function loadData() { return function($viewName, $view) { - /// tu código aquí + // tu código aquí }; } - } diff --git a/SAMPLES/extensionModel.php.sample b/SAMPLES/ExtensionModel.php.sample similarity index 86% rename from SAMPLES/extensionModel.php.sample rename to SAMPLES/ExtensionModel.php.sample index 4e57223..4604762 100644 --- a/SAMPLES/extensionModel.php.sample +++ b/SAMPLES/ExtensionModel.php.sample @@ -17,63 +17,63 @@ class [[NAME]] // clear() public function clear() { return function() { - /// tu código aquí + // tu código aquí }; } // delete() se ejecuta una vez realizado el delete() del modelo. public function delete() { return function() { - /// tu código aquí + // tu código aquí }; } // deleteBefore() se ejecuta antes de hacer el delete() del modelo. Si devolvemos false, impedimos el delete(). public function deleteBefore() { return function() { - /// tu código aquí + // tu código aquí }; } // save() se ejecuta una vez realizado el save() del modelo. public function save() { return function() { - /// tu código aquí + // tu código aquí }; } // saveBefore() se ejecuta antes de hacer el save() del modelo. Si devolvemos false, impedimos el save(). public function saveBefore() { return function() { - /// tu código aquí + // tu código aquí }; } // saveInsert() se ejecuta una vez realizado el saveInsert() del modelo. public function saveInsert() { return function() { - /// tu código aquí + // tu código aquí }; } // saveInsertBefore() se ejecuta antes de hacer el saveInsert() del modelo. Si devolvemos false, impedimos el saveInsert(). public function saveInsertBefore() { return function() { - /// tu código aquí + // tu código aquí }; } // saveUpdate() se ejecuta una vez realizado el saveUpdate() del modelo. public function saveUpdate() { return function() { - /// tu código aquí + // tu código aquí }; } // saveUpdateBefore() se ejecuta antes de hacer el saveUpdate() del modelo. Si devolvemos false, impedimos el saveUpdate(). public function saveUpdateBefore() { return function() { - /// tu código aquí + // tu código aquí }; } diff --git a/SAMPLES/Init.php.sample b/SAMPLES/Init.php.sample index b606325..146e5d9 100644 --- a/SAMPLES/Init.php.sample +++ b/SAMPLES/Init.php.sample @@ -4,10 +4,10 @@ namespace FacturaScripts\Plugins\[[NAME]]; class Init extends \FacturaScripts\Core\Base\InitClass { public function init() { - /// se ejecutara cada vez que carga FacturaScripts (si este plugin está activado). + // se ejecutara cada vez que carga FacturaScripts (si este plugin está activado). } public function update() { - /// se ejecutara cada vez que se instala o actualiza el plugin. + // se ejecutara cada vez que se instala o actualiza el plugin. } } \ No newline at end of file diff --git a/SAMPLES/ListController.php.sample b/SAMPLES/ListController.php.sample index d623235..68bb6fa 100644 --- a/SAMPLES/ListController.php.sample +++ b/SAMPLES/ListController.php.sample @@ -19,10 +19,10 @@ class List[[MODEL_NAME]] extends \FacturaScripts\Core\Lib\ExtendedController\Lis $this->addView($viewName, "[[MODEL_NAME]]", "[[TITLE]]"); // Esto es un ejemplo ... debe de cambiarlo según los nombres de campos del modelo - $this->addOrderBy($viewName, ["id"], "id"); - $this->addOrderBy($viewName, ["name"], "name", 1); + // $this->addOrderBy($viewName, ["id"], "id", 2); + // $this->addOrderBy($viewName, ["name"], "name"); // Esto es un ejemplo ... debe de cambiarlo según los nombres de campos del modelo - $this->addSearchFields($viewName, ["id", "name"]); + // $this->addSearchFields($viewName, ["id", "name"]); } } diff --git a/SAMPLES/table.xml.sample b/SAMPLES/table.xml.sample deleted file mode 100644 index 9e069f4..0000000 --- a/SAMPLES/table.xml.sample +++ /dev/null @@ -1,20 +0,0 @@ - - - - creationdate - timestamp - - - id - serial - - - name - character varying(100) - - - [[TABLE_NAME]]_pkey - PRIMARY KEY (id) - -
- diff --git a/fsmaker.php b/fsmaker.php index 42d3387..3987195 100644 --- a/fsmaker.php +++ b/fsmaker.php @@ -8,14 +8,16 @@ die("Usar: php fsmaker.php"); } -final class fsmaker { +final class fsmaker +{ const TRANSLATIONS = 'ca_ES,de_DE,en_EN,es_AR,es_CL,es_CO,es_CR,es_DO,es_EC,es_ES,es_GT,es_MX,es_PA,es_PE,es_UY,eu_ES,fr_FR,gl_ES,it_IT,pt_PT,va_ES'; const FORBIDDEN_WORDS = 'action,activetab,code'; - const VERSION = 0.93; + const VERSION = 1.0; const OK = " -> OK.\n"; - public function __construct($argv) { + public function __construct($argv) + { if (count($argv) < 2) { $this->help(); return; @@ -61,7 +63,8 @@ public function __construct($argv) { } } - private function askFields(): array { + private function askFields(): array + { $fields = []; $serial = false; @@ -96,7 +99,7 @@ private function askFields(): array { break; case 5: - $long = (int) $this->prompt("\nLongitud caracteres"); + $long = (int)$this->prompt("\nLongitud caracteres"); $fields[$name] = "character varying($long)"; break; @@ -121,19 +124,20 @@ private function askFields(): array { return $fields; } - private function askType(bool $serial): int { + private function askType(bool $serial): int + { while (true) { echo "\n"; - $type = (int) $this->prompt("Elija el tipo de campo\n" - . "1 = serial (autonumérico, ideal para ids)\n" - . "2 = integer\n" - . "3 = float\n" - . "4 = boolean\n" - . "5 = character varying\n" - . "6 = text\n" - . "7 = timestamp\n" - . "8 = date\n" - . "9 = time\n"); + $type = (int)$this->prompt("Elija el tipo de campo\n" + . "1 = serial (autonumérico, ideal para ids)\n" + . "2 = integer\n" + . "3 = float\n" + . "4 = boolean\n" + . "5 = character varying\n" + . "6 = text\n" + . "7 = timestamp\n" + . "8 = date\n" + . "9 = time\n"); if ($type === 1 && $serial) { echo "\nYa hay un campo de tipo serial.\n"; continue; @@ -147,7 +151,8 @@ private function askType(bool $serial): int { } } - private function createController() { + private function createController() + { $name = $this->prompt('Nombre del controlador', '/^[A-Z][a-zA-Z0-9_]*$/'); $fileName = $this->isCoreFolder() ? 'Core/Controller/' . $name . '.php' : 'Controller/' . $name . '.php'; if (file_exists($fileName)) { @@ -159,9 +164,7 @@ private function createController() { } $sample = file_get_contents(__DIR__ . "/SAMPLES/Controller.php.sample"); - $template = str_replace(['[[NAME_SPACE]]', '[[NAME]]'] - , [$this->getNamespace(), $name] - , $sample); + $template = str_replace(['[[NAME_SPACE]]', '[[NAME]]'], [$this->getNamespace(), $name], $sample); file_put_contents($fileName, $template); echo '* ' . $fileName . self::OK; @@ -177,13 +180,14 @@ private function createController() { echo '* ' . $viewFilename . self::OK; } - private function createControllerAction() { + private function createControllerAction() + { if (false === $this->isCoreFolder() && false === $this->isPluginFolder()) { echo "* Esta no es la carpeta raíz del plugin.\n"; return; } - $option = (int) $this->prompt("Elija el tipo de controlador a crear\n1=Controller, 2=ListController, 3=EditController"); + $option = (int)$this->prompt("Elija el tipo de controlador a crear\n1=Controller, 2=ListController, 3=EditController"); switch ($option) { case 1: $this->createController(); @@ -205,7 +209,8 @@ private function createControllerAction() { echo "Opción no válida.\n"; } - private function createControllerEdit(string $modelName, array $fields) { + private function createControllerEdit(string $modelName, array $fields) + { $fileName = $this->isCoreFolder() ? 'Core/Controller/Edit' . $modelName . '.php' : 'Controller/Edit' . $modelName . '.php'; if (file_exists($fileName)) { echo "El controlador " . $fileName . " YA EXISTE.\n"; @@ -229,7 +234,8 @@ private function createControllerEdit(string $modelName, array $fields) { echo '* ' . $xmlFilename . self::OK; } - private function createControllerList(string $modelName, array $fields) { + private function createControllerList(string $modelName, array $fields) + { $menu = $this->prompt('Menú'); $title = $this->prompt('Título'); $fileName = $this->isCoreFolder() ? 'Core/Controller/List' . $modelName . '.php' : 'Controller/List' . $modelName . '.php'; @@ -242,9 +248,9 @@ private function createControllerList(string $modelName, array $fields) { } $sample = file_get_contents(__DIR__ . "/SAMPLES/ListController.php.sample"); - $template = str_replace(['[[NAME_SPACE]]', '[[MODEL_NAME]]', '[[TITLE]]', '[[MENU]]'] - , [$this->getNamespace(), $modelName, $title, $menu] - , $sample); + $template = str_replace(['[[NAME_SPACE]]', '[[MODEL_NAME]]', '[[TITLE]]', '[[MENU]]'], + [$this->getNamespace(), $modelName, $title, $menu], + $sample); file_put_contents($fileName, $template); echo '* ' . $fileName . self::OK; @@ -258,7 +264,8 @@ private function createControllerList(string $modelName, array $fields) { echo '* ' . $xmlFilename . self::OK; } - private function createCron(string $name) { + private function createCron(string $name) + { if (false === $this->isCoreFolder() && false === $this->isPluginFolder()) { echo "* Esta no es la carpeta raíz del plugin.\n"; return; @@ -276,13 +283,14 @@ private function createCron(string $name) { echo '* ' . $fileName . self::OK; } - private function createExtensionAction() { + private function createExtensionAction() + { if (false === $this->isCoreFolder() && false === $this->isPluginFolder()) { echo "* Esta no es la carpeta raíz del plugin.\n"; return; } - $option = (int) $this->prompt("Elija el tipo de extensión\n1=Tabla, 2=Modelo, 3=Controlador, 4=XMLView"); + $option = (int)$this->prompt("Elija el tipo de extensión\n1=Tabla, 2=Modelo, 3=Controlador, 4=XMLView"); switch ($option) { case 1: $name = strtolower($this->prompt('Nombre de la tabla (plural)', '/^[a-zA-Z][a-zA-Z0-9_]*$/')); @@ -308,7 +316,8 @@ private function createExtensionAction() { echo "* Opción no válida.\n"; } - private function createExtensionController(string $name) { + private function createExtensionController(string $name) + { if (empty($name)) { echo '* No introdujo el nombre del controlador a extender.\n'; return; @@ -320,7 +329,7 @@ private function createExtensionController(string $name) { return; } - $sample = file_get_contents(__DIR__ . "/SAMPLES/extensionController.php.sample"); + $sample = file_get_contents(__DIR__ . "/SAMPLES/ExtensionController.php.sample"); $template = str_replace(['[[NAME]]', '[[NAME_SPACE]]'], [$name, $this->getNamespace()], $sample); file_put_contents($fileName, $template); echo '* ' . $fileName . "\n"; @@ -328,7 +337,8 @@ private function createExtensionController(string $name) { $this->modifyInit($name, 1); } - private function createExtensionModel(string $name) { + private function createExtensionModel(string $name) + { if (empty($name)) { echo '* No introdujo el nombre del modelo a extender.\n'; return; @@ -340,7 +350,7 @@ private function createExtensionModel(string $name) { return; } - $sample = file_get_contents(__DIR__ . "/SAMPLES/extensionModel.php.sample"); + $sample = file_get_contents(__DIR__ . "/SAMPLES/ExtensionModel.php.sample"); $template = str_replace(['[[NAME]]', '[[NAME_SPACE]]'], [$name, $this->getNamespace()], $sample); file_put_contents($fileName, $template); echo '* ' . $fileName . "\n"; @@ -348,7 +358,8 @@ private function createExtensionModel(string $name) { $this->modifyInit($name, 0); } - private function createExtensionTable(string $name) { + private function createExtensionTable(string $name) + { if (empty($name)) { echo '* No introdujo el nombre de la tabla a extender.\n'; return; @@ -365,7 +376,8 @@ private function createExtensionTable(string $name) { echo '* ' . $fileName . self::OK; } - private function createExtensionXMLView(string $name) { + private function createExtensionXMLView(string $name) + { if (empty($name)) { echo '* No introdujo el nombre del XMLView a extender.\n'; return; @@ -379,11 +391,11 @@ private function createExtensionXMLView(string $name) { $fields = $this->askFields(); $this->createXMLViewByFields($fileName, $fields, 2); - echo '* ' . $fileName . self::OK; } - private function createGitIgnore() { + private function createGitIgnore() + { $fileName = '.gitignore'; if (file_exists($fileName)) { echo '* ' . $fileName . " YA EXISTE\n"; @@ -395,7 +407,8 @@ private function createGitIgnore() { echo '* ' . $fileName . self::OK; } - private function createIni(string $name) { + private function createIni(string $name) + { $fileName = "facturascripts.ini"; if (file_exists($fileName)) { echo '* ' . $fileName . " YA EXISTE\n"; @@ -408,7 +421,8 @@ private function createIni(string $name) { echo '* ' . $fileName . self::OK; } - private function createInit(string $name) { + private function createInit(string $name) + { if (false === $this->isCoreFolder() && false === $this->isPluginFolder()) { echo "* Esta no es la carpeta raíz del plugin.\n"; return; @@ -426,7 +440,8 @@ private function createInit(string $name) { echo '* ' . $fileName . self::OK; } - private function createModelAction() { + private function createModelAction() + { if (false === $this->isCoreFolder() && false === $this->isPluginFolder()) { echo "* Esta no es la carpeta raíz del plugin.\n"; return; @@ -468,7 +483,8 @@ private function createModelAction() { } } - private function createModelByFields(string $fileName, string $tableName, array $fields, string $name) { + private function createModelByFields(string $fileName, string $tableName, array $fields, string $name) + { $properties = ''; $primaryColumn = ''; $clear = ''; @@ -501,40 +517,41 @@ private function createModelByFields(string $fileName, string $tableName, array break; case 'timestamp': - $clear .= ' $this->' . $property . ' = date("d-m-Y H:i:s");' . "\n"; + $clear .= ' $this->' . $property . ' = date(ModelClass::DATETIME_STYLE);' . "\n"; break; case 'date': - $clear .= ' $this->' . $property . ' = date("d-m-Y");' . "\n"; + $clear .= ' $this->' . $property . ' = date(ModelClass::DATE_STYLE);' . "\n"; break; case 'time': - $clear .= ' $this->' . $property . ' = date("H:i:s");' . "\n"; + $clear .= ' $this->' . $property . ' = date(ModelClass::HOUR_STYLE);' . "\n"; break; } } $sample = 'getNamespace() . '\Model;' . "\n\n" - . 'class ' . $name . ' extends \FacturaScripts\Core\Model\Base\ModelClass' . "\n" - . '{' . "\n" - . ' use \FacturaScripts\Core\Model\Base\ModelTrait;' . "\n\n" - . $properties - . ' public function clear() {' . "\n" - . ' parent::clear();' . "\n" - . $clear - . ' }' . "\n\n" - . ' public static function primaryColumn() {' . "\n" - . ' return "' . $primaryColumn . '";' . "\n" - . ' }' . "\n\n" - . ' public static function tableName() {' . "\n" - . ' return "' . $tableName . '";' . "\n" - . ' }' . "\n" - . '}' . "\n"; + . 'namespace FacturaScripts\\' . $this->getNamespace() . '\Model;' . "\n\n" + . 'class ' . $name . ' extends \FacturaScripts\Core\Model\Base\ModelClass' . "\n" + . '{' . "\n" + . ' use \FacturaScripts\Core\Model\Base\ModelTrait;' . "\n\n" + . $properties + . ' public function clear() {' . "\n" + . ' parent::clear();' . "\n" + . $clear + . ' }' . "\n\n" + . ' public static function primaryColumn() {' . "\n" + . ' return "' . $primaryColumn . '";' . "\n" + . ' }' . "\n\n" + . ' public static function tableName() {' . "\n" + . ' return "' . $tableName . '";' . "\n" + . ' }' . "\n" + . '}' . "\n"; file_put_contents($fileName, $sample); } - private function createPluginAction() { + private function createPluginAction() + { if (file_exists('.git') || file_exists('.gitignore') || file_exists('facturascripts.ini')) { echo "* No se puede crear un plugin en esta carpeta.\n"; return; @@ -564,8 +581,8 @@ private function createPluginAction() { foreach (explode(',', self::TRANSLATIONS) as $filename) { file_put_contents( - $name . '/Translation/' . $filename . '.json', - '{"' . strtolower($name) . '": "' . $name . '"}' + $name . '/Translation/' . $filename . '.json', + '{"' . strtolower($name) . '": "' . $name . '"}' ); echo '* ' . $name . '/Translation/' . $filename . ".json" . self::OK; } @@ -577,32 +594,34 @@ private function createPluginAction() { $this->createInit($name); } - private function createXMLTableByFields(string $tableFilename, string $tableName, array $fields) { + private function createXMLTableByFields(string $tableFilename, string $tableName, array $fields) + { $columns = ''; $constraints = ''; foreach ($fields as $key => $type) { $columns .= " \n" - . " $key\n" - . " $type\n" - . " \n"; + . " $key\n" + . " $type\n" + . " \n"; if ($type === 'serial') { $constraints .= " \n" - . ' ' . $tableName . "_pkey\n" - . ' PRIMARY KEY (' . $key . ")\n" - . " \n"; + . ' ' . $tableName . "_pkey\n" + . ' PRIMARY KEY (' . $key . ")\n" + . " \n"; } } $sample = '' . "\n" - . '' . "\n" - . $columns - . $constraints - . '
' . "\n"; + . '' . "\n" + . $columns + . $constraints + . '
' . "\n"; file_put_contents($tableFilename, $sample); } - private function createXMLViewByFields(string $xmlFilename, array $fields, int $editOrList) { + private function createXMLViewByFields(string $xmlFilename, array $fields, int $editOrList) + { if (empty($fields)) { $fields = $this->askFields(); } @@ -627,8 +646,8 @@ private function createXMLViewByFields(string $xmlFilename, array $fields, int $ } $sample = '' . "\n" - . '' . "\n" - . ' ' . "\n"; + . '' . "\n" + . ' ' . "\n"; switch ($editOrList) { case 0: // Es un ListController @@ -638,8 +657,8 @@ private function createXMLViewByFields(string $xmlFilename, array $fields, int $ case 1: // Es un EditController case 2: // Es una extensión $sample .= ' ' . "\n" - . $columns - . ' ' . "\n"; + . $columns + . ' ' . "\n"; break; default: // No es ninguna de las opciones de antes @@ -647,13 +666,13 @@ private function createXMLViewByFields(string $xmlFilename, array $fields, int $ } $sample .= ' ' . "\n" - . '' . "\n"; + . '' . "\n"; file_put_contents($xmlFilename, $sample); - return; } - private function findPluginName(): string { + private function findPluginName(): string + { if ($this->isPluginFolder()) { $ini = parse_ini_file('facturascripts.ini'); return $ini['name'] ?? ''; @@ -662,45 +681,46 @@ private function findPluginName(): string { return ''; } - private function getWidget(string $name, string $type, string $order, int $tabForColums): string { + private function getWidget(string $name, string $type, string $order, int $tabForColums): string + { $spaces = str_repeat(" ", $tabForColums); $sample = ''; switch ($type) { default: $sample .= $spaces . '' . "\n" - . $spaces . ' ' . "\n"; + . $spaces . ' ' . "\n"; break; case 'double precision': case 'int': $sample .= $spaces . '' . "\n" - . $spaces . ' ' . "\n"; + . $spaces . ' ' . "\n"; break; case 'boolean': $sample .= $spaces . '' . "\n" - . $spaces . ' ' . "\n"; + . $spaces . ' ' . "\n"; break; case 'text': $sample .= $spaces . '' . "\n" - . $spaces . ' ' . "\n"; + . $spaces . ' ' . "\n"; break; case 'timestamp': $sample .= $spaces . '' . "\n" - . $spaces . ' ' . "\n"; + . $spaces . ' ' . "\n"; break; case 'date': $sample .= $spaces . '' . "\n" - . $spaces . ' ' . "\n"; + . $spaces . ' ' . "\n"; break; case 'time': $sample .= $spaces . '' . "\n" - . $spaces . ' ' . "\n"; + . $spaces . ' ' . "\n"; break; } @@ -708,7 +728,8 @@ private function getWidget(string $name, string $type, string $order, int $tabFo return $sample; } - private function getNamespace(): string { + private function getNamespace(): string + { if ($this->isCoreFolder()) { return 'Core'; } @@ -717,36 +738,40 @@ private function getNamespace(): string { return 'Plugins\\' . $ini['name']; } - private function help() { + private function help() + { echo 'FacturaScripts Maker v' . self::VERSION . "\n\n" - . "crear:\n" - . "$ fsmaker plugin\n" - . "$ fsmaker model\n" - . "$ fsmaker controller\n" - . "$ fsmaker extension\n" - . "$ fsmaker gitignore\n" - . "$ fsmaker cron\n" - . "$ fsmaker init\n\n" - . "descargar:\n" - . "$ fsmaker translations\n"; + . "crear:\n" + . "$ fsmaker plugin\n" + . "$ fsmaker model\n" + . "$ fsmaker controller\n" + . "$ fsmaker extension\n" + . "$ fsmaker gitignore\n" + . "$ fsmaker cron\n" + . "$ fsmaker init\n\n" + . "descargar:\n" + . "$ fsmaker translations\n"; } - private function isCoreFolder(): bool { + private function isCoreFolder(): bool + { return file_exists('Core/Translation') && false === file_exists('facturascripts.ini'); } - private function isPluginFolder(): bool { + private function isPluginFolder(): bool + { return file_exists('facturascripts.ini'); } - private function modifyInit(string $name, int $modelOrController) { + private function modifyInit(string $name, int $modelOrController) + { $fileName = "Init.php"; if (!file_exists($fileName)) { $this->createInit($name); } $fileStr = file_get_contents($fileName); - $toSearch = '/// se ejecutara cada vez que carga FacturaScripts (si este plugin está activado).'; + $toSearch = '// se ejecutara cada vez que carga FacturaScripts (si este plugin está activado).'; $toChange = $toSearch . "\n" . ' $this->loadExtension(new Extension\Controller\\' . $name . '());'; if ($modelOrController === 0) { $toChange = $toSearch . "\n" . ' $this->loadExtension(new Extension\Model\\' . $name . '());'; @@ -757,7 +782,8 @@ private function modifyInit(string $name, int $modelOrController) { echo '* ' . $fileName . self::OK; } - private function prompt($label, $pattern = ''): string { + private function prompt($label, $pattern = ''): string + { echo $label . ': '; $matches = []; $value = trim(fgets(STDIN)); @@ -769,7 +795,8 @@ private function prompt($label, $pattern = ''): string { return $value; } - private function updateTranslationsAction() { + private function updateTranslationsAction() + { if ($this->isPluginFolder()) { $folder = 'Translation/'; $ini = parse_ini_file('facturascripts.ini'); @@ -787,7 +814,7 @@ private function updateTranslationsAction() { return; } - /// download json from facturascripts.com + // download json from facturascripts.com foreach (explode(',', self::TRANSLATIONS) as $filename) { echo "D " . $folder . $filename . ".json"; $url = "https://facturascripts.com/EditLanguage?action=json&project=" . $project . "&code=" . $filename;