@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | { |
| 56 | 56 | GeneratorHelper::createDir(dirname($path)); |
| 57 | 57 | if (false === FileHelper::writeFile($path, $data)) { |
| 58 | - throw new ConfigException(t('No se tienen los permisos suficientes para escribir en el fichero ') . $path); |
|
| 58 | + throw new ConfigException(t('No se tienen los permisos suficientes para escribir en el fichero ').$path); |
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | Inspector::stats('[Cache] Gathering data from cache'); |
| 71 | 71 | $data = null; |
| 72 | - $absolutePath = $absolute ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
| 72 | + $absolutePath = $absolute ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
| 73 | 73 | if (file_exists($absolutePath)) { |
| 74 | 74 | $data = FileHelper::readFile($absolutePath); |
| 75 | 75 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | private function hasExpiredCache($path, $expires = 300, $absolute = false) |
| 86 | 86 | { |
| 87 | 87 | Inspector::stats('[Cache] Checking expiration'); |
| 88 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
| 88 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
| 89 | 89 | $lasModificationDate = filemtime($absolutePath); |
| 90 | 90 | return ($lasModificationDate + $expires <= time()); |
| 91 | 91 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | { |
| 153 | 153 | Inspector::stats('[Cache] Store data in cache'); |
| 154 | 154 | $data = self::transformData($data, $transform); |
| 155 | - $absolutePath = $absolute ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
| 155 | + $absolutePath = $absolute ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
| 156 | 156 | $this->saveTextToFile($data, $absolutePath); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | public function readFromCache($path, $expires = 300, $function = null, $transform = Cache::TEXT) |
| 169 | 169 | { |
| 170 | 170 | $data = null; |
| 171 | - Inspector::stats('[Cache] Reading data from cache: ' . json_encode(['path' => $path])); |
|
| 172 | - if (file_exists(CACHE_DIR . DIRECTORY_SEPARATOR . $path)) { |
|
| 171 | + Inspector::stats('[Cache] Reading data from cache: '.json_encode(['path' => $path])); |
|
| 172 | + if (file_exists(CACHE_DIR.DIRECTORY_SEPARATOR.$path)) { |
|
| 173 | 173 | if (is_callable($function) && $this->hasExpiredCache($path, $expires)) { |
| 174 | 174 | $data = $function(); |
| 175 | 175 | $this->storeData($path, $data, $transform, false, $expires); |
| 176 | - } else { |
|
| 176 | + }else { |
|
| 177 | 177 | $data = $this->getDataFromFile($path, $transform); |
| 178 | 178 | } |
| 179 | 179 | } |
@@ -219,20 +219,20 @@ discard block |
||
| 219 | 219 | $query[Api::HEADER_API_LANG] = Request::header(Api::HEADER_API_LANG, 'es'); |
| 220 | 220 | $filename = FileHelper::generateHashFilename($action['http'], $action['slug'], $query); |
| 221 | 221 | $hashPath = FileHelper::generateCachePath($action, $query); |
| 222 | - Inspector::stats('[Cache] Cache file calculated: ' . json_encode(['file' => $filename, 'hash' => $hashPath])); |
|
| 222 | + Inspector::stats('[Cache] Cache file calculated: '.json_encode(['file' => $filename, 'hash' => $hashPath])); |
|
| 223 | 223 | Logger::log('Cache file calculated', LOG_DEBUG, ['file' => $filename, 'hash' => $hashPath]); |
| 224 | 224 | } |
| 225 | 225 | return [$hashPath, $filename]; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | public function flushCache() { |
| 229 | - if(Config::getParam('cache.data.enable', false)) { |
|
| 229 | + if (Config::getParam('cache.data.enable', false)) { |
|
| 230 | 230 | Inspector::stats('[Cache] Flushing cache'); |
| 231 | 231 | $action = Security::getInstance()->getSessionKey(self::CACHE_SESSION_VAR); |
| 232 | - if(is_array($action)) { |
|
| 233 | - $hashPath = FileHelper::generateCachePath($action, $action['params']) . '..' . DIRECTORY_SEPARATOR . ' .. ' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
| 234 | - if(!file_exists($hashPath)) { |
|
| 235 | - $hashPath = CACHE_DIR . DIRECTORY_SEPARATOR . $hashPath; |
|
| 232 | + if (is_array($action)) { |
|
| 233 | + $hashPath = FileHelper::generateCachePath($action, $action['params']).'..'.DIRECTORY_SEPARATOR.' .. '.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
| 234 | + if (!file_exists($hashPath)) { |
|
| 235 | + $hashPath = CACHE_DIR.DIRECTORY_SEPARATOR.$hashPath; |
|
| 236 | 236 | } |
| 237 | 237 | FileHelper::deleteDir($hashPath); |
| 238 | 238 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | { |
| 63 | 63 | if (preg_match('/^asc$/i', $direction)) { |
| 64 | 64 | return self::ASC; |
| 65 | - } else { |
|
| 65 | + }else { |
|
| 66 | 66 | return self::DESC; |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function fromArray(array $object = array()) |
| 83 | 83 | { |
| 84 | - foreach($object as $field => $order) { |
|
| 84 | + foreach ($object as $field => $order) { |
|
| 85 | 85 | $this->addOrder($field, $order); |
| 86 | 86 | } |
| 87 | 87 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | public function __construct($hydrate = true) |
| 20 | 20 | { |
| 21 | 21 | parent::__construct(); |
| 22 | - if($hydrate) { |
|
| 22 | + if ($hydrate) { |
|
| 23 | 23 | $this->fromArray(Request::getInstance()->getData()); |
| 24 | 24 | } |
| 25 | 25 | } |
@@ -47,22 +47,22 @@ discard block |
||
| 47 | 47 | /** @var \ReflectionProperty $property */ |
| 48 | 48 | foreach ($properties as $property) { |
| 49 | 49 | $value = $property->getValue($this); |
| 50 | - if(is_object($value) && method_exists($value, 'toArray')) { |
|
| 50 | + if (is_object($value) && method_exists($value, 'toArray')) { |
|
| 51 | 51 | $dto[$property->getName()] = $value->toArray(); |
| 52 | - } elseif(is_array($value)) { |
|
| 53 | - foreach($value as &$arrValue) { |
|
| 54 | - if($arrValue instanceof Dto) { |
|
| 52 | + } elseif (is_array($value)) { |
|
| 53 | + foreach ($value as &$arrValue) { |
|
| 54 | + if ($arrValue instanceof Dto) { |
|
| 55 | 55 | $arrValue = $arrValue->toArray(); |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | $dto[$property->getName()] = $value; |
| 59 | - } else { |
|
| 59 | + }else { |
|
| 60 | 60 | $dto[$property->getName()] = $property->getValue($this); |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | - } catch (\Exception $e) { |
|
| 65 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
| 64 | + }catch (\Exception $e) { |
|
| 65 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
| 66 | 66 | } |
| 67 | 67 | return $dto; |
| 68 | 68 | } |
@@ -85,26 +85,26 @@ discard block |
||
| 85 | 85 | protected function parseDtoField(array $properties, $key, $value = null) { |
| 86 | 86 | list($type, $isArray) = $this->extractTypes($properties, $key); |
| 87 | 87 | $reflector = (class_exists($type)) ? new \ReflectionClass($type) : null; |
| 88 | - if(null !== $reflector && $reflector->isSubclassOf(Dto::class)) { |
|
| 89 | - if(null !== $value && is_array($value)) { |
|
| 90 | - if(!array_key_exists($type, $this->__cache)) { |
|
| 88 | + if (null !== $reflector && $reflector->isSubclassOf(Dto::class)) { |
|
| 89 | + if (null !== $value && is_array($value)) { |
|
| 90 | + if (!array_key_exists($type, $this->__cache)) { |
|
| 91 | 91 | $this->__cache[$type] = new $type(false); |
| 92 | 92 | } |
| 93 | - if($isArray) { |
|
| 93 | + if ($isArray) { |
|
| 94 | 94 | $this->$key = []; |
| 95 | - foreach($value as $data) { |
|
| 96 | - if(null !== $data && is_array($data)) { |
|
| 95 | + foreach ($value as $data) { |
|
| 96 | + if (null !== $data && is_array($data)) { |
|
| 97 | 97 | $dto = clone $this->__cache[$type]; |
| 98 | 98 | $dto->fromArray($data); |
| 99 | 99 | array_push($this->$key, $dto); |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | - } else { |
|
| 102 | + }else { |
|
| 103 | 103 | $this->$key = clone $this->__cache[$type]; |
| 104 | 104 | $this->$key->fromArray($value); |
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | - } else { |
|
| 107 | + }else { |
|
| 108 | 108 | $this->castValue($key, $value, $type); |
| 109 | 109 | } |
| 110 | 110 | } |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | public static function parseRawData($type, $params) { |
| 18 | - switch($type) { |
|
| 18 | + switch ($type) { |
|
| 19 | 19 | default: |
| 20 | 20 | case self::TYPE_HTTP: |
| 21 | 21 | $parsedParams = http_build_query($params); |
@@ -141,7 +141,7 @@ |
||
| 141 | 141 | $tmp = []; |
| 142 | 142 | if (null === $node) { |
| 143 | 143 | $node = $value; |
| 144 | - } else { |
|
| 144 | + }else { |
|
| 145 | 145 | $tmp = $this->getTmpAttribute($node); |
| 146 | 146 | } |
| 147 | 147 | if (null !== $node) { |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | $customKey = $customKey ?: Security::getInstance()->getSessionKey(self::CUSTOM_LOCALE_SESSION_KEY); |
| 55 | 55 | } |
| 56 | 56 | if (null !== $customKey) { |
| 57 | - Logger::log('[' . self::class . '] Custom key detected: ' . $customKey, LOG_INFO); |
|
| 58 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $customKey, self::$locale . '.json']); |
|
| 59 | - } else { |
|
| 60 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', self::$locale . '.json']); |
|
| 57 | + Logger::log('['.self::class.'] Custom key detected: '.$customKey, LOG_INFO); |
|
| 58 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $customKey, self::$locale.'.json']); |
|
| 59 | + }else { |
|
| 60 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', self::$locale.'.json']); |
|
| 61 | 61 | } |
| 62 | 62 | if (file_exists(self::$filename)) { |
| 63 | - Logger::log('[' . self::class . '] Custom locale detected: ' . $customKey . ' [' . self::$locale . ']', LOG_INFO); |
|
| 63 | + Logger::log('['.self::class.'] Custom locale detected: '.$customKey.' ['.self::$locale.']', LOG_INFO); |
|
| 64 | 64 | self::$translations = json_decode(file_get_contents(self::$filename), true); |
| 65 | 65 | } elseif (null !== $customKey) { |
| 66 | 66 | self::checkLoad(null, $forceReload, true); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | public function getFilters() |
| 82 | 82 | { |
| 83 | 83 | return array( |
| 84 | - new TwigFilter('trans', function ($message) { |
|
| 84 | + new TwigFilter('trans', function($message) { |
|
| 85 | 85 | return self::_($message); |
| 86 | 86 | }), |
| 87 | 87 | ); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | self::checkLoad($customKey, $forceReload); |
| 107 | 107 | if (array_key_exists($message, self::$translations)) { |
| 108 | 108 | $translation = self::$translations[$message]; |
| 109 | - } else { |
|
| 109 | + }else { |
|
| 110 | 110 | $translation = gettext($message); |
| 111 | 111 | } |
| 112 | 112 | if (self::$generate) { |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | protected $isMultipart = false; |
| 71 | 71 | |
| 72 | 72 | private function closeConnection() { |
| 73 | - if(null !== $this->con) { |
|
| 73 | + if (null !== $this->con) { |
|
| 74 | 74 | curl_close($this->con); |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | */ |
| 234 | 234 | public function setIsJson($isJson = true) { |
| 235 | 235 | $this->isJson = $isJson; |
| 236 | - if($isJson) { |
|
| 236 | + if ($isJson) { |
|
| 237 | 237 | $this->setIsMultipart(false); |
| 238 | 238 | } |
| 239 | 239 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | public function setIsMultipart($isMultipart = true) { |
| 252 | 252 | $this->isMultipart = $isMultipart; |
| 253 | - if($isMultipart) { |
|
| 253 | + if ($isMultipart) { |
|
| 254 | 254 | $this->setIsJson(false); |
| 255 | 255 | } |
| 256 | 256 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $this->url = NULL; |
| 271 | 271 | $this->params = array(); |
| 272 | 272 | $this->headers = array(); |
| 273 | - Logger::log('Context service for ' . static::class . ' cleared!'); |
|
| 273 | + Logger::log('Context service for '.static::class.' cleared!'); |
|
| 274 | 274 | $this->closeConnection(); |
| 275 | 275 | } |
| 276 | 276 | |
@@ -313,18 +313,18 @@ discard block |
||
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | protected function applyOptions() { |
| 316 | - if(count($this->options)) { |
|
| 316 | + if (count($this->options)) { |
|
| 317 | 317 | curl_setopt_array($this->con, $this->options); |
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | protected function applyHeaders() { |
| 322 | 322 | $headers = []; |
| 323 | - foreach($this->headers as $key => $value) { |
|
| 324 | - $headers[] = $key . ': ' . $value; |
|
| 323 | + foreach ($this->headers as $key => $value) { |
|
| 324 | + $headers[] = $key.': '.$value; |
|
| 325 | 325 | } |
| 326 | 326 | $headers[self::PSFS_TRACK_HEADER] = Logger::getUid(); |
| 327 | - if(count($headers)) { |
|
| 327 | + if (count($headers)) { |
|
| 328 | 328 | curl_setopt($this->con, CURLOPT_HTTPHEADER, $headers); |
| 329 | 329 | } |
| 330 | 330 | } |
@@ -333,10 +333,10 @@ discard block |
||
| 333 | 333 | * @return int |
| 334 | 334 | */ |
| 335 | 335 | private function parseServiceType() { |
| 336 | - if($this->getIsJson()) { |
|
| 336 | + if ($this->getIsJson()) { |
|
| 337 | 337 | return ServiceHelper::TYPE_JSON; |
| 338 | 338 | } |
| 339 | - if($this->getIsMultipart()) { |
|
| 339 | + if ($this->getIsMultipart()) { |
|
| 340 | 340 | return ServiceHelper::TYPE_MULTIPART; |
| 341 | 341 | } |
| 342 | 342 | return ServiceHelper::TYPE_HTTP; |
@@ -349,9 +349,9 @@ discard block |
||
| 349 | 349 | case Request::VERB_GET: |
| 350 | 350 | default: |
| 351 | 351 | $this->addOption(CURLOPT_CUSTOMREQUEST, Request::VERB_GET); |
| 352 | - if(!empty($this->params)) { |
|
| 352 | + if (!empty($this->params)) { |
|
| 353 | 353 | $sep = false === strpos($this->getUrl(), '?') ? '?' : ''; |
| 354 | - $this->url = $this->url . $sep . http_build_query($this->params); |
|
| 354 | + $this->url = $this->url.$sep.http_build_query($this->params); |
|
| 355 | 355 | } |
| 356 | 356 | break; |
| 357 | 357 | case Request::VERB_POST: |
@@ -383,14 +383,14 @@ discard block |
||
| 383 | 383 | $this->applyOptions(); |
| 384 | 384 | $this->applyHeaders(); |
| 385 | 385 | $verbose = null; |
| 386 | - if('debug' === Config::getParam('log.level')) { |
|
| 386 | + if ('debug' === Config::getParam('log.level')) { |
|
| 387 | 387 | curl_setopt($this->con, CURLOPT_VERBOSE, true); |
| 388 | 388 | $verbose = fopen('php://temp', 'wb+'); |
| 389 | 389 | curl_setopt($this->con, CURLOPT_STDERR, $verbose); |
| 390 | 390 | } |
| 391 | 391 | $result = curl_exec($this->con); |
| 392 | 392 | $this->setResult($this->isJson ? json_decode($result, true) : $result); |
| 393 | - if('debug' === Config::getParam('log.level')) { |
|
| 393 | + if ('debug' === Config::getParam('log.level')) { |
|
| 394 | 394 | rewind($verbose); |
| 395 | 395 | $verboseLog = stream_get_contents($verbose); |
| 396 | 396 | Logger::log($verboseLog, LOG_DEBUG, [ |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | ]); |
| 401 | 401 | $this->info['verbose'] = $verboseLog; |
| 402 | 402 | } |
| 403 | - Logger::log($this->url . ' response: ', LOG_DEBUG, is_array($this->result) ? $this->result : [$this->result]); |
|
| 403 | + Logger::log($this->url.' response: ', LOG_DEBUG, is_array($this->result) ? $this->result : [$this->result]); |
|
| 404 | 404 | $this->info = array_merge($this->info, curl_getinfo($this->con)); |
| 405 | 405 | } |
| 406 | 406 | |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | public static function updateCacheVar() { |
| 18 | 18 | $now = new \DateTime(null, new \DateTimeZone(Config::getParam('project.timezone', 'Europe/Madrid'))); |
| 19 | 19 | $config = Config::getInstance()->dumpConfig(); |
| 20 | - $config[self::CACHE_VAR_TAG] = 'v' . $now->format('Ymd.His'); |
|
| 20 | + $config[self::CACHE_VAR_TAG] = 'v'.$now->format('Ymd.His'); |
|
| 21 | 21 | Config::save($config); |
| 22 | 22 | return $config[self::CACHE_VAR_TAG]; |
| 23 | 23 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function generateModule() |
| 30 | 30 | { |
| 31 | - Logger::log("Arranque generador de módulos al solicitar " . $this->getRequest()->getRequestUri()); |
|
| 31 | + Logger::log("Arranque generador de módulos al solicitar ".$this->getRequest()->getRequestUri()); |
|
| 32 | 32 | /* @var $form \PSFS\base\config\ConfigForm */ |
| 33 | 33 | $form = new ModuleForm(); |
| 34 | 34 | $form->build(); |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | $this->gen->createStructureModule($module, false, $type, $apiClass); |
| 61 | 61 | Security::getInstance()->setFlash("callback_message", str_replace("%s", $module, t("Módulo %s generado correctamente"))); |
| 62 | 62 | // Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-module", true)); |
| 63 | - } catch (\Exception $e) { |
|
| 64 | - Logger::log($e->getMessage() . " [" . $e->getFile() . ":" . $e->getLine() . "]"); |
|
| 63 | + }catch (\Exception $e) { |
|
| 64 | + Logger::log($e->getMessage()." [".$e->getFile().":".$e->getLine()."]"); |
|
| 65 | 65 | Security::getInstance()->setFlash("callback_message", htmlentities($e->getMessage())); |
| 66 | 66 | } |
| 67 | 67 | } |