@@ -29,12 +29,16 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function infoLog($msg) |
| 31 | 31 | { |
| 32 | - if ($this->verbosity) $this->log->writeln($msg); |
|
| 32 | + if ($this->verbosity) { |
|
| 33 | + $this->log->writeln($msg); |
|
| 34 | + } |
|
| 33 | 35 | } |
| 34 | 36 | } |
| 35 | 37 | } |
| 36 | 38 | |
| 37 | - if (!isset($console)) $console = new Application(); |
|
| 39 | + if (!isset($console)) { |
|
| 40 | + $console = new Application(); |
|
| 41 | + } |
|
| 38 | 42 | $console |
| 39 | 43 | ->register('psfs:create:module') |
| 40 | 44 | ->setDefinition(array( |
@@ -58,7 +62,7 @@ discard block |
||
| 58 | 62 | { |
| 59 | 63 | \PSFS\services\GeneratorService::getInstance()->createStructureModule($module, $log); |
| 60 | 64 | } |
| 61 | - }catch (\Exception $e) |
|
| 65 | + } catch (\Exception $e) |
|
| 62 | 66 | { |
| 63 | 67 | $output->writeln($e->getMessage()); |
| 64 | 68 | $output->writeln($e->getTraceAsString()); |
@@ -31,14 +31,18 @@ |
||
| 31 | 31 | //Hidratamos con los comandos de PSFS |
| 32 | 32 | $commands = new Finder(); |
| 33 | 33 | $commands->in(__DIR__)->notName("PSFSConsole.php"); |
| 34 | - foreach ($commands as $com) include_once($com->getRealPath()); |
|
| 34 | + foreach ($commands as $com) { |
|
| 35 | + include_once($com->getRealPath()); |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | //Hidratamos con los comandos de los módulos |
| 37 | 39 | if (file_exists(CORE_DIR)) |
| 38 | 40 | { |
| 39 | 41 | $commands = new Finder(); |
| 40 | 42 | $commands->in(CORE_DIR)->path("Command")->name("*.php"); |
| 41 | - foreach ($commands as $com) include_once($com->getRealPath()); |
|
| 43 | + foreach ($commands as $com) { |
|
| 44 | + include_once($com->getRealPath()); |
|
| 45 | + } |
|
| 42 | 46 | } |
| 43 | 47 | |
| 44 | 48 | $console->run(); |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | use PSFS\controller\Admin; |
| 7 | 7 | use Symfony\Component\Finder\Finder; |
| 8 | 8 | |
| 9 | - class AdminServices extends Service{ |
|
| 9 | + class AdminServices extends Service { |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * @Inyectable |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function setAdminHeaders() |
| 32 | 32 | { |
| 33 | - if("login" === $this->config->get("admin_login")) return Admin::getInstance()->adminLogin("admin-setup"); |
|
| 33 | + if ("login" === $this->config->get("admin_login")) return Admin::getInstance()->adminLogin("admin-setup"); |
|
| 34 | 34 | $platform = trim(Config::getInstance()->get("platform_name")); |
| 35 | 35 | header('HTTP/1.1 401 Unauthorized'); |
| 36 | - header('WWW-Authenticate: Basic Realm="' . $platform. '"'); |
|
| 36 | + header('WWW-Authenticate: Basic Realm="'.$platform.'"'); |
|
| 37 | 37 | echo _("Zona restringida"); |
| 38 | 38 | exit(); |
| 39 | 39 | } |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | public function getAdmins() |
| 46 | 46 | { |
| 47 | 47 | $admins = $this->security->getAdmins(); |
| 48 | - if(!empty($admins)) |
|
| 48 | + if (!empty($admins)) |
|
| 49 | 49 | { |
| 50 | - if(!$this->security->checkAdmin()) |
|
| 50 | + if (!$this->security->checkAdmin()) |
|
| 51 | 51 | { |
| 52 | 52 | $this->setAdminHeaders(); |
| 53 | 53 | } |
@@ -62,12 +62,12 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | private function parseAdmins(&$admins) |
| 64 | 64 | { |
| 65 | - if(!empty($admins)) foreach($admins as &$admin) |
|
| 65 | + if (!empty($admins)) foreach ($admins as &$admin) |
|
| 66 | 66 | { |
| 67 | - if(isset($admin["profile"])) |
|
| 67 | + if (isset($admin["profile"])) |
|
| 68 | 68 | { |
| 69 | 69 | $admin["class"] = $admin["profile"] == sha1("admin") ? 'primary' : "warning"; |
| 70 | - }else{ |
|
| 70 | + }else { |
|
| 71 | 71 | $admin["class"] = "primary"; |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -87,12 +87,12 @@ discard block |
||
| 87 | 87 | $files->files()->in(LOG_DIR)->name("*.log")->sortByModifiedTime(); |
| 88 | 88 | $logs = array(); |
| 89 | 89 | /** @var \SplFileInfo $file */ |
| 90 | - foreach($files as $file) |
|
| 90 | + foreach ($files as $file) |
|
| 91 | 91 | { |
| 92 | - $size = $file->getSize() / 8 / 1024; |
|
| 92 | + $size = $file->getSize()/8/1024; |
|
| 93 | 93 | $time = date("c", $file->getMTime()); |
| 94 | 94 | $dateTime = new \DateTime($time); |
| 95 | - if(!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
|
| 95 | + if (!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
|
| 96 | 96 | $logs[$dateTime->format("Y")][$dateTime->format("m")][$time] = array( |
| 97 | 97 | "filename" => $file->getFilename(), |
| 98 | 98 | "size" => round($size, 3) |
@@ -116,27 +116,27 @@ discard block |
||
| 116 | 116 | $files->files()->in(LOG_DIR)->name($selectedLog); |
| 117 | 117 | $file = null; |
| 118 | 118 | $log = array(); |
| 119 | - foreach($files as $match) |
|
| 119 | + foreach ($files as $match) |
|
| 120 | 120 | { |
| 121 | 121 | $file = $match; |
| 122 | 122 | break; |
| 123 | 123 | } |
| 124 | 124 | /** @var \SplFileInfo $file */ |
| 125 | - if(!empty($file)) |
|
| 125 | + if (!empty($file)) |
|
| 126 | 126 | { |
| 127 | 127 | $time = date("c", $file->getMTime()); |
| 128 | 128 | $dateTime = new \DateTime($time); |
| 129 | 129 | $monthOpen = $dateTime->format("m"); |
| 130 | - $content = file($file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename()); |
|
| 130 | + $content = file($file->getPath().DIRECTORY_SEPARATOR.$file->getFilename()); |
|
| 131 | 131 | krsort($content); |
| 132 | 132 | $detailLog = array(); |
| 133 | - foreach($content as &$line) |
|
| 133 | + foreach ($content as &$line) |
|
| 134 | 134 | { |
| 135 | 135 | list($line, $detail) = $this->parseLogLine($line, $match); |
| 136 | 136 | $detailLog[] = array_merge(array( |
| 137 | 137 | "log" => $line, |
| 138 | 138 | ), $detail); |
| 139 | - if(count($detailLog) >= 1000) break; |
|
| 139 | + if (count($detailLog) >= 1000) break; |
|
| 140 | 140 | } |
| 141 | 141 | $log = $detailLog; |
| 142 | 142 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | $type = (isset($match[1][0])) ? $match[1][0] : ''; |
| 167 | 167 | $type = explode(".", $type); |
| 168 | - $type = count($type)>1 ? $type[1] : $type[0]; |
|
| 168 | + $type = count($type) > 1 ? $type[1] : $type[0]; |
|
| 169 | 169 | switch ($type) { |
| 170 | 170 | case 'INFO': |
| 171 | 171 | $detail["type"] = "success"; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | break; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - } catch (\Exception $e) { |
|
| 184 | + }catch (\Exception $e) { |
|
| 185 | 185 | $detail = array( |
| 186 | 186 | "type" => "danger", |
| 187 | 187 | ); |
@@ -30,7 +30,9 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function setAdminHeaders() |
| 32 | 32 | { |
| 33 | - if("login" === $this->config->get("admin_login")) return Admin::getInstance()->adminLogin("admin-setup"); |
|
| 33 | + if("login" === $this->config->get("admin_login")) { |
|
| 34 | + return Admin::getInstance()->adminLogin("admin-setup"); |
|
| 35 | + } |
|
| 34 | 36 | $platform = trim(Config::getInstance()->get("platform_name")); |
| 35 | 37 | header('HTTP/1.1 401 Unauthorized'); |
| 36 | 38 | header('WWW-Authenticate: Basic Realm="' . $platform. '"'); |
@@ -62,12 +64,14 @@ discard block |
||
| 62 | 64 | */ |
| 63 | 65 | private function parseAdmins(&$admins) |
| 64 | 66 | { |
| 65 | - if(!empty($admins)) foreach($admins as &$admin) |
|
| 67 | + if(!empty($admins)) { |
|
| 68 | + foreach($admins as &$admin) |
|
| 66 | 69 | { |
| 67 | 70 | if(isset($admin["profile"])) |
| 68 | 71 | { |
| 69 | 72 | $admin["class"] = $admin["profile"] == sha1("admin") ? 'primary' : "warning"; |
| 70 | - }else{ |
|
| 73 | + } |
|
| 74 | + } else{ |
|
| 71 | 75 | $admin["class"] = "primary"; |
| 72 | 76 | } |
| 73 | 77 | } |
@@ -92,7 +96,9 @@ discard block |
||
| 92 | 96 | $size = $file->getSize() / 8 / 1024; |
| 93 | 97 | $time = date("c", $file->getMTime()); |
| 94 | 98 | $dateTime = new \DateTime($time); |
| 95 | - if(!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
|
| 99 | + if(!isset($logs[$dateTime->format("Y")])) { |
|
| 100 | + $logs[$dateTime->format("Y")] = array(); |
|
| 101 | + } |
|
| 96 | 102 | $logs[$dateTime->format("Y")][$dateTime->format("m")][$time] = array( |
| 97 | 103 | "filename" => $file->getFilename(), |
| 98 | 104 | "size" => round($size, 3) |
@@ -136,7 +142,9 @@ discard block |
||
| 136 | 142 | $detailLog[] = array_merge(array( |
| 137 | 143 | "log" => $line, |
| 138 | 144 | ), $detail); |
| 139 | - if(count($detailLog) >= 1000) break; |
|
| 145 | + if(count($detailLog) >= 1000) { |
|
| 146 | + break; |
|
| 147 | + } |
|
| 140 | 148 | } |
| 141 | 149 | $log = $detailLog; |
| 142 | 150 | } |
@@ -160,7 +168,9 @@ discard block |
||
| 160 | 168 | |
| 161 | 169 | $detail = json_decode($match[0][0], TRUE); |
| 162 | 170 | } |
| 163 | - if (empty($detail)) $detail = array(); |
|
| 171 | + if (empty($detail)) { |
|
| 172 | + $detail = array(); |
|
| 173 | + } |
|
| 164 | 174 | preg_match_all('/\>\ (.*):/i', $line, $match); |
| 165 | 175 | |
| 166 | 176 | $type = (isset($match[1][0])) ? $match[1][0] : ''; |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | { |
| 22 | 22 | $array = array(); |
| 23 | 23 | $array['fields'] = array(); |
| 24 | - foreach($this->fields as $field) { |
|
| 24 | + foreach ($this->fields as $field) { |
|
| 25 | 25 | $array['fields'][] = $field->__toArray(); |
| 26 | 26 | } |
| 27 | 27 | return $array; |
@@ -26,13 +26,13 @@ |
||
| 26 | 26 | { |
| 27 | 27 | $namespace = explode('\\', $this->getModelTableMap()); |
| 28 | 28 | $module = strtolower($namespace[0]); |
| 29 | - $secret = Config::getInstance()->get($module . '.api.secret'); |
|
| 29 | + $secret = Config::getInstance()->get($module.'.api.secret'); |
|
| 30 | 30 | if (NULL === $secret) { |
| 31 | 31 | $secret = Config::getInstance()->get("api.secret"); |
| 32 | 32 | } |
| 33 | 33 | if (NULL === $secret) { |
| 34 | 34 | $auth = TRUE; |
| 35 | - } else { |
|
| 35 | + }else { |
|
| 36 | 36 | $token = Request::getInstance()->getHeader('X-API-SEC-TOKEN'); |
| 37 | 37 | if (array_key_exists('API_TOKEN', $this->query)) { |
| 38 | 38 | $token = $this->query['API_TOKEN']; |
@@ -7,7 +7,19 @@ |
||
| 7 | 7 | * @package PSFS\base\types\interfaces |
| 8 | 8 | */ |
| 9 | 9 | interface AuthInterface { |
| 10 | + |
|
| 11 | + /** |
|
| 12 | + * @return boolean |
|
| 13 | + */ |
|
| 10 | 14 | function isLogged(); |
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @return boolean |
|
| 18 | + */ |
|
| 11 | 19 | function isAdmin(); |
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @return boolean |
|
| 23 | + */ |
|
| 12 | 24 | function canDo($action); |
| 13 | 25 | } |
@@ -7,6 +7,14 @@ |
||
| 7 | 7 | * @package PSFS\base\types\interfaces |
| 8 | 8 | */ |
| 9 | 9 | interface ControllerInterface { |
| 10 | + |
|
| 11 | + /** |
|
| 12 | + * @return string|null |
|
| 13 | + */ |
|
| 10 | 14 | public function render($template, Array $vars = null); |
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 11 | 19 | public function response($response, $type = 'text/html'); |
| 12 | 20 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | use PSFS\base\exception\SecurityException; |
| 13 | 13 | use PSFS\base\Singleton; |
| 14 | 14 | |
| 15 | - require_once __DIR__ . DIRECTORY_SEPARATOR . "bootstrap.php"; |
|
| 15 | + require_once __DIR__.DIRECTORY_SEPARATOR."bootstrap.php"; |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * Class Dispatcher |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | { |
| 83 | 83 | $this->locale = $this->config->get("default_language"); |
| 84 | 84 | // Load translations |
| 85 | - putenv("LC_ALL=" . $this->locale); |
|
| 85 | + putenv("LC_ALL=".$this->locale); |
|
| 86 | 86 | setlocale(LC_ALL, $this->locale); |
| 87 | 87 | // Load the locale path |
| 88 | - $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale'; |
|
| 88 | + $locale_path = BASE_DIR.DIRECTORY_SEPARATOR.'locale'; |
|
| 89 | 89 | Config::createDir($locale_path); |
| 90 | 90 | bindtextdomain('translations', $locale_path); |
| 91 | 91 | textdomain('translations'); |
@@ -99,23 +99,23 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | public function run() |
| 101 | 101 | { |
| 102 | - $this->log->infoLog("Begin request " . $this->parser->getRequestUri()); |
|
| 102 | + $this->log->infoLog("Begin request ".$this->parser->getRequestUri()); |
|
| 103 | 103 | // |
| 104 | 104 | try { |
| 105 | 105 | if ($this->config->isConfigured()) { |
| 106 | 106 | if (!$this->parser->isFile()) { |
| 107 | 107 | return $this->router->execute($this->actualUri); |
| 108 | 108 | } |
| 109 | - } else { |
|
| 109 | + }else { |
|
| 110 | 110 | return $this->router->getAdmin()->config(); |
| 111 | 111 | } |
| 112 | - } catch (ConfigException $c) { |
|
| 112 | + }catch (ConfigException $c) { |
|
| 113 | 113 | return $this->dumpException($c); |
| 114 | - } catch (SecurityException $s) { |
|
| 114 | + }catch (SecurityException $s) { |
|
| 115 | 115 | return $this->security->notAuthorized($this->actualUri); |
| 116 | - } catch (RouterException $r) { |
|
| 116 | + }catch (RouterException $r) { |
|
| 117 | 117 | return $this->router->httpNotFound($r); |
| 118 | - } catch (\Exception $e) { |
|
| 118 | + }catch (\Exception $e) { |
|
| 119 | 119 | return $this->dumpException($e); |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $use /= 1024; |
| 157 | 157 | break; |
| 158 | 158 | case "MBytes": |
| 159 | - $use /= (1024 * 1024); |
|
| 159 | + $use /= (1024*1024); |
|
| 160 | 160 | break; |
| 161 | 161 | case "Bytes": |
| 162 | 162 | default: |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | { |
| 182 | 182 | if ($this->config->getDebugMode()) { |
| 183 | 183 | //Warning & Notice handler |
| 184 | - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
|
| 184 | + set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
| 185 | 185 | throw new \ErrorException($errstr, 500, $errno, $errfile, $errline); |
| 186 | 186 | }); |
| 187 | 187 | } |