/** * Test to check if the Logger has been created successful * @return Logger */ public function getInstance() { $instance = Logger::getInstance(); $this->assertNotNull($instance, 'Logger instance is null'); $this->assertInstanceOf("\\PSFS\\base\\Logger", $instance, 'Instance is different than expected'); return $instance; }
/** * @POST * @route /admin/module * @return string */ public function doGenerateModule() { $form = new ModuleForm(); $form->build(); $form->hydrate(); if ($form->isValid()) { $module = $form->getFieldValue("module"); $force = $form->getFieldValue("force"); $type = $form->getFieldValue("controllerType"); $is_module = $form->getFieldValue("is_module"); try { $module = preg_replace('/(\\\\|\\/)/', '/', $module); $module = preg_replace('/^\\//', '', $module); $this->gen->createStructureModule($module, $force, $type, (bool) $is_module); Security::getInstance()->setFlash("callback_message", str_replace("%s", $module, _("Módulo %s generado correctamente"))); Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-module", true)); } catch (\Exception $e) { pre($e->getMessage(), true); Logger::getInstance()->infoLog($e->getMessage() . " [" . $e->getFile() . ":" . $e->getLine() . "]"); throw new ConfigException('Error al generar el módulo, prueba a cambiar los permisos', 403); } } return $this->render("modules.html.twig", array('properties' => $this->config->getPropelParams(), 'form' => $form)); }
/** * Servicio que guarda la configuración de la plataforma * @POST * @route /admin/config * @visible false * @return string * @throws \HttpException */ public function saveConfig() { Logger::getInstance()->infoLog(_("Guardando configuración")); /* @var $form \PSFS\base\config\ConfigForm */ $form = new ConfigForm(Router::getInstance()->getRoute('admin-config'), Config::$required, Config::$optional, Config::getInstance()->dumpConfig()); $form->build(); $form->hydrate(); if ($form->isValid()) { $debug = Config::getInstance()->getDebugMode(); $newDebug = $form->getFieldValue("debug"); if (Config::save($form->getData(), $form->getExtraData())) { Logger::log(_('Configuración guardada correctamente')); //Verificamos si tenemos que limpiar la cache del DocumentRoot if (boolval($debug) !== boolval($newDebug)) { Config::clearDocumentRoot(); } Security::getInstance()->setFlash("callback_message", _("Configuración actualizada correctamente")); Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-config", true)); } else { throw new \HttpException(_('Error al guardar la configuración, prueba a cambiar los permisos'), 403); } } return $this->render('welcome.html.twig', array('text' => _("Bienvenido a PSFS"), 'config' => $form, 'typeahead_data' => array_merge(Config::$required, Config::$optional))); }
/** * Método que guarda los datos del formulario en el modelo de datos asociado al formulario * @return bool * @throws FormException */ public function save() { if (null === $this->model) { throw new FormException("No se ha asociado ningún modelo al formulario"); } $this->model->fromArray(array($this->getData())); $save = false; try { $model = $this->getHydratedModel(); $model->save(); $save = true; Logger::getInstance()->infoLog(get_class($this->model) . " guardado con id " . $this->model->getPrimaryKey()); } catch (\Exception $e) { Logger::getInstance()->errorLog($e->getMessage()); throw new FormException($e->getMessage(), $e->getCode(), $e); } return $save; }
/** * Static method to trace logs * @param string $msg * @param int $type * @param array $context */ public static function log($msg, $type = LOG_DEBUG, $context = []) { switch ($type) { case LOG_DEBUG: Logger::getInstance()->debugLog($msg, $context); break; case LOG_WARNING: Logger::getInstance()->warningLog($msg, $context); break; case LOG_CRIT: case LOG_ERR: Logger::getInstance()->errorLog($msg, $context); break; case LOG_INFO: Logger::getInstance()->infoLog($msg, $context); break; default: Logger::getInstance()->defaultLog($msg, $context); break; } }
/** * @return array */ private function getList() { $return = array(); $total = 0; $pages = 0; try { $this->paginate(); if (null !== $this->list) { $return = $this->list->toArray(); $total = $this->list->getNbResults(); $pages = $this->list->getLastPage(); } } catch (\Exception $e) { Logger::getInstance(get_class($this))->errorLog($e->getMessage()); } return array($return, $total, $pages); }
/** * Method that extract all the needed info for each method in each API * * @param string $namespace * @param \ReflectionMethod $method * @param \ReflectionClass $reflection * * @return array */ protected function extractMethodInfo($namespace, \ReflectionMethod $method, \ReflectionClass $reflection) { $methodInfo = NULL; $docComments = $method->getDocComment(); $shortName = $reflection->getShortName(); $modelNamespace = str_replace('Api', 'Models', $namespace); if (FALSE !== $docComments && preg_match('/\\@route\\ /i', $docComments)) { $visibility = $this->extractVisibility($docComments); $route = str_replace('{__API__}', $shortName, $this->extractRoute($docComments)); if ($visibility && preg_match('/^\\/api\\//i', $route)) { try { $methodInfo = ['url' => $route, 'method' => $this->extractMethod($docComments), 'description' => str_replace('{__API__}', $shortName, $this->extractDescription($docComments)), 'return' => $this->extractReturn($modelNamespace, $docComments)]; if (in_array($methodInfo['method'], ['POST', 'PUT'])) { $methodInfo['payload'] = $this->extractPayload($modelNamespace, $docComments); } } catch (\Exception $e) { jpre($e->getMessage()); Logger::getInstance()->errorLog($e->getMessage()); } } } return $methodInfo; }