@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once __DIR__ . "/../vendor/autoload.php"; |
|
| 3 | +require_once __DIR__."/../vendor/autoload.php"; |
|
| 4 | 4 | |
| 5 | 5 | use PSFS\base\SingletonRegistry; |
| 6 | 6 | use PSFS\Dispatcher; |
@@ -12,19 +12,19 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | $server = new Server("0.0.0.0", $port, SWOOLE_BASE); |
| 14 | 14 | $server->set([ |
| 15 | - 'worker_num' => 4, // varios workers para ver diferencias entre ellos |
|
| 16 | - 'max_request' => 5000, // no reinicia workers |
|
| 15 | + 'worker_num' => 4, // varios workers para ver diferencias entre ellos |
|
| 16 | + 'max_request' => 5000, // no reinicia workers |
|
| 17 | 17 | 'log_level' => SWOOLE_LOG_INFO, |
| 18 | 18 | 'daemonize' => 0, |
| 19 | 19 | ]); |
| 20 | 20 | |
| 21 | -$server->on("request", function (Request $req, Response $res) { |
|
| 21 | +$server->on("request", function(Request $req, Response $res) { |
|
| 22 | 22 | $req->server[SingletonRegistry::CONTEXT_SESSION] = bin2hex(random_bytes(16)); |
| 23 | 23 | $_SERVER = []; |
| 24 | 24 | foreach ($req->server as $k => $v) { |
| 25 | 25 | $_SERVER[strtoupper($k)] = $v; |
| 26 | 26 | } |
| 27 | - register_shutdown_function(function () { |
|
| 27 | + register_shutdown_function(function() { |
|
| 28 | 28 | SingletonRegistry::clear(); |
| 29 | 29 | }); |
| 30 | 30 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | ob_start(); // por si hay output accidental |
| 33 | 33 | // tu framework procesando la request |
| 34 | 34 | Dispatcher::getInstance()->run(); |
| 35 | - } catch (\Throwable $e) { |
|
| 35 | + }catch (\Throwable $e) { |
|
| 36 | 36 | // tu error handler |
| 37 | 37 | $res->status($e->getCode()); |
| 38 | 38 | } finally { |
@@ -22,15 +22,15 @@ discard block |
||
| 22 | 22 | // 2. Detect execution environment |
| 23 | 23 | // ----------------------------------------------------------------------------- |
| 24 | 24 | |
| 25 | -$bootstrapDir = __DIR__; // .../psfs/core/src |
|
| 26 | -$vendorDir = dirname($bootstrapDir, 2) . '/vendor'; |
|
| 25 | +$bootstrapDir = __DIR__; // .../psfs/core/src |
|
| 26 | +$vendorDir = dirname($bootstrapDir, 2).'/vendor'; |
|
| 27 | 27 | $projectRoot = dirname($bootstrapDir, 2); // When running as vendor |
| 28 | 28 | |
| 29 | 29 | // Standalone mode: PSFS cloned and executed directly (no vendor/) |
| 30 | 30 | $standaloneRoot = dirname($bootstrapDir, 1); // .../psfs-core |
| 31 | 31 | |
| 32 | 32 | // Detect vendor mode (framework inside vendor/) |
| 33 | -$runningAsVendor = file_exists($vendorDir . '/autoload.php'); |
|
| 33 | +$runningAsVendor = file_exists($vendorDir.'/autoload.php'); |
|
| 34 | 34 | |
| 35 | 35 | // Detect standalone mode |
| 36 | 36 | $runningStandalone = !$runningAsVendor; |
@@ -43,21 +43,21 @@ discard block |
||
| 43 | 43 | defined('SOURCE_DIR') or define('SOURCE_DIR', $bootstrapDir); |
| 44 | 44 | if ($runningAsVendor) { |
| 45 | 45 | // PSFS is being executed as a dependency in another project |
| 46 | - defined('BASE_DIR') or define('BASE_DIR', dirname($vendorDir, 1)); // The root of the host project |
|
| 47 | - defined('CORE_DIR') or define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'src'); |
|
| 46 | + defined('BASE_DIR') or define('BASE_DIR', dirname($vendorDir, 1)); // The root of the host project |
|
| 47 | + defined('CORE_DIR') or define('CORE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'src'); |
|
| 48 | 48 | defined('PSFS_AS_VENDOR') or define('PSFS_AS_VENDOR', true); |
| 49 | -} else { |
|
| 49 | +}else { |
|
| 50 | 50 | // Standalone development mode |
| 51 | 51 | defined('BASE_DIR') or define('BASE_DIR', $standaloneRoot); |
| 52 | - defined('CORE_DIR') or define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'modules'); |
|
| 52 | + defined('CORE_DIR') or define('CORE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'modules'); |
|
| 53 | 53 | defined('PSFS_AS_VENDOR') or define('PSFS_AS_VENDOR', false); |
| 54 | 54 | } |
| 55 | -defined('VENDOR_DIR') or define('VENDOR_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'vendor'); |
|
| 56 | -defined('LOG_DIR') or define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
| 57 | -defined('CACHE_DIR') or define('CACHE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'cache'); |
|
| 58 | -defined('CONFIG_DIR') or define('CONFIG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'config'); |
|
| 59 | -defined('WEB_DIR') or define('WEB_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'html'); |
|
| 60 | -defined('LOCALE_DIR') or define('LOCALE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
| 55 | +defined('VENDOR_DIR') or define('VENDOR_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'vendor'); |
|
| 56 | +defined('LOG_DIR') or define('LOG_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
| 57 | +defined('CACHE_DIR') or define('CACHE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'cache'); |
|
| 58 | +defined('CONFIG_DIR') or define('CONFIG_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'config'); |
|
| 59 | +defined('WEB_DIR') or define('WEB_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'html'); |
|
| 60 | +defined('LOCALE_DIR') or define('LOCALE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
| 61 | 61 | |
| 62 | 62 | // ----------------------------------------------------------------------------- |
| 63 | 63 | // 4. Load Composer autoload |
@@ -65,10 +65,10 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | if ($runningAsVendor) { |
| 67 | 67 | // Autoload from the host project's vendor directory |
| 68 | - require_once $vendorDir . '/autoload.php'; |
|
| 69 | -} else { |
|
| 68 | + require_once $vendorDir.'/autoload.php'; |
|
| 69 | +}else { |
|
| 70 | 70 | // Standalone mode: PSFS itself is the project root |
| 71 | - $standaloneAutoload = BASE_DIR . '/vendor/autoload.php'; |
|
| 71 | + $standaloneAutoload = BASE_DIR.'/vendor/autoload.php'; |
|
| 72 | 72 | if (!file_exists($standaloneAutoload)) { |
| 73 | 73 | throw new RuntimeException( |
| 74 | 74 | "Composer autoload not found. Run 'composer install' in the PSFS root directory." |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | // ----------------------------------------------------------------------------- |
| 82 | 82 | // 5. Global helper functions |
| 83 | 83 | // ----------------------------------------------------------------------------- |
| 84 | -require_once SOURCE_DIR . '/functions.php'; |
|
| 84 | +require_once SOURCE_DIR.'/functions.php'; |
|
| 85 | 85 | |
| 86 | 86 | |
| 87 | 87 | // ----------------------------------------------------------------------------- |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function __construct() |
| 30 | 30 | { |
| 31 | - Inspector::stats(static::class . ' constructor invoked'); |
|
| 31 | + Inspector::stats(static::class.' constructor invoked'); |
|
| 32 | 32 | $this->init(); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -87,14 +87,14 @@ discard block |
||
| 87 | 87 | $calledClass = static::class; |
| 88 | 88 | try { |
| 89 | 89 | $instance = InjectorHelper::constructInjectableInstance($variable, $singleton, $classNameSpace, $calledClass); |
| 90 | - $setter = 'set' . ucfirst($variable); |
|
| 90 | + $setter = 'set'.ucfirst($variable); |
|
| 91 | 91 | if (method_exists($calledClass, $setter)) { |
| 92 | 92 | $this->$setter($instance); |
| 93 | - } else { |
|
| 93 | + }else { |
|
| 94 | 94 | $this->$variable = $instance; |
| 95 | 95 | } |
| 96 | - } catch (Exception $e) { |
|
| 97 | - Logger::log($e->getMessage() . ': ' . $e->getFile() . ' [' . $e->getLine() . ']', LOG_ERR); |
|
| 96 | + }catch (Exception $e) { |
|
| 97 | + Logger::log($e->getMessage().': '.$e->getFile().' ['.$e->getLine().']', LOG_ERR); |
|
| 98 | 98 | throw $e; |
| 99 | 99 | } |
| 100 | 100 | return $this; |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | { |
| 110 | 110 | if (!$this->isLoaded()) { |
| 111 | 111 | $filename = sha1(get_class($this)); |
| 112 | - $cacheFilename = 'reflections' . DIRECTORY_SEPARATOR . substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2) . DIRECTORY_SEPARATOR . $filename . '.json'; |
|
| 112 | + $cacheFilename = 'reflections'.DIRECTORY_SEPARATOR.substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2).DIRECTORY_SEPARATOR.$filename.'.json'; |
|
| 113 | 113 | /** @var Cache $cacheService */ |
| 114 | 114 | $cacheService = Cache::getInstance(); |
| 115 | 115 | /** @var Config $configService */ |
@@ -127,8 +127,8 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | $this->setLoaded(); |
| 130 | - } else { |
|
| 131 | - Logger::log(get_class($this) . ' already loaded', LOG_INFO); |
|
| 130 | + }else { |
|
| 131 | + Logger::log(get_class($this).' already loaded', LOG_INFO); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | } |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | { |
| 28 | 28 | $class = static::class; |
| 29 | 29 | $instance = SingletonRegistry::get($class); |
| 30 | - if(!$instance) { |
|
| 30 | + if (!$instance) { |
|
| 31 | 31 | $instance = new $class($args[0] ?? null); |
| 32 | 32 | SingletonRegistry::register($instance); |
| 33 | 33 | self::initiate($instance); |
@@ -26,10 +26,10 @@ discard block |
||
| 26 | 26 | $objects = scandir($dir); |
| 27 | 27 | foreach ($objects as $object) { |
| 28 | 28 | if ($object != "." && $object != "..") { |
| 29 | - if (filetype($dir . "/" . $object) == "dir") { |
|
| 30 | - self::deleteDir($dir . "/" . $object); |
|
| 31 | - } else { |
|
| 32 | - unlink($dir . "/" . $object); |
|
| 29 | + if (filetype($dir."/".$object) == "dir") { |
|
| 30 | + self::deleteDir($dir."/".$object); |
|
| 31 | + }else { |
|
| 32 | + unlink($dir."/".$object); |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | } |
@@ -45,10 +45,10 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $rootDirs = array("css", "js", "media", "font"); |
| 47 | 47 | foreach ($rootDirs as $dir) { |
| 48 | - if (file_exists(WEB_DIR . DIRECTORY_SEPARATOR . $dir)) { |
|
| 48 | + if (file_exists(WEB_DIR.DIRECTORY_SEPARATOR.$dir)) { |
|
| 49 | 49 | try { |
| 50 | - self::deleteDir(WEB_DIR . DIRECTORY_SEPARATOR . $dir); |
|
| 51 | - } catch (\Exception $e) { |
|
| 50 | + self::deleteDir(WEB_DIR.DIRECTORY_SEPARATOR.$dir); |
|
| 51 | + }catch (\Exception $e) { |
|
| 52 | 52 | syslog(LOG_INFO, $e->getMessage()); |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | if (!empty($dir)) { |
| 66 | 66 | try { |
| 67 | 67 | if (!is_dir($dir) && @mkdir($dir, 0775, true) === false) { |
| 68 | - throw new Exception(t('Can\'t create directory ') . $dir); |
|
| 68 | + throw new Exception(t('Can\'t create directory ').$dir); |
|
| 69 | 69 | } |
| 70 | - } catch (\Exception $e) { |
|
| 70 | + }catch (\Exception $e) { |
|
| 71 | 71 | syslog(LOG_WARNING, $e->getMessage()); |
| 72 | 72 | if (!file_exists(dirname($dir))) { |
| 73 | - throw new GeneratorException($e->getMessage() . $dir); |
|
| 73 | + throw new GeneratorException($e->getMessage().$dir); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public static function getTemplatePath(): string |
| 84 | 84 | { |
| 85 | - $path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; |
|
| 85 | + $path = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR; |
|
| 86 | 86 | return realpath($path); |
| 87 | 87 | } |
| 88 | 88 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | } elseif (!$reflector->isAbstract()) { |
| 111 | 111 | throw new GeneratorException(t('La clase definida debe ser abstracta'), 501); |
| 112 | 112 | } |
| 113 | - } else { |
|
| 113 | + }else { |
|
| 114 | 114 | throw new GeneratorException(t('La clase definida para extender la API no existe'), 501); |
| 115 | 115 | } |
| 116 | 116 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | GeneratorHelper::createDir($path); |
| 133 | 133 | $paths = array("js", "css", "img", "media", "font"); |
| 134 | 134 | foreach ($paths as $htmlPath) { |
| 135 | - GeneratorHelper::createDir($path . DIRECTORY_SEPARATOR . $htmlPath); |
|
| 135 | + GeneratorHelper::createDir($path.DIRECTORY_SEPARATOR.$htmlPath); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Generates the root needed files |
@@ -142,35 +142,35 @@ discard block |
||
| 142 | 142 | 'crossdomain' => 'crossdomain.xml', |
| 143 | 143 | 'humans' => 'humans.txt', |
| 144 | 144 | 'robots' => 'robots.txt', |
| 145 | - 'docker' => '..' . DIRECTORY_SEPARATOR . 'docker-compose.yml', |
|
| 145 | + 'docker' => '..'.DIRECTORY_SEPARATOR.'docker-compose.yml', |
|
| 146 | 146 | ]; |
| 147 | 147 | $verificable = ['humans', 'robots', 'docker']; |
| 148 | 148 | if (!$quiet) { |
| 149 | 149 | $output->writeln('Start creating html files'); |
| 150 | 150 | } |
| 151 | 151 | foreach ($files as $template => $filename) { |
| 152 | - if (in_array($template, $verificable) && file_exists($path . DIRECTORY_SEPARATOR . $filename)) { |
|
| 152 | + if (in_array($template, $verificable) && file_exists($path.DIRECTORY_SEPARATOR.$filename)) { |
|
| 153 | 153 | if (!$quiet) { |
| 154 | - $output->writeln($filename . ' already exists'); |
|
| 154 | + $output->writeln($filename.' already exists'); |
|
| 155 | 155 | } |
| 156 | 156 | continue; |
| 157 | 157 | } |
| 158 | - $text = Template::getInstance()->dump("generator/html/" . $template . '.html.twig', ['PSFS_AS_VENDOR' => PSFS_AS_VENDOR]); |
|
| 159 | - if (false === file_put_contents($path . DIRECTORY_SEPARATOR . $filename, $text)) { |
|
| 158 | + $text = Template::getInstance()->dump("generator/html/".$template.'.html.twig', ['PSFS_AS_VENDOR' => PSFS_AS_VENDOR]); |
|
| 159 | + if (false === file_put_contents($path.DIRECTORY_SEPARATOR.$filename, $text)) { |
|
| 160 | 160 | if (!$quiet) { |
| 161 | - $output->writeln('Can\t create the file ' . $filename); |
|
| 161 | + $output->writeln('Can\t create the file '.$filename); |
|
| 162 | 162 | } |
| 163 | - } else { |
|
| 163 | + }else { |
|
| 164 | 164 | if (!$quiet) { |
| 165 | - $output->writeln($filename . ' created successfully'); |
|
| 165 | + $output->writeln($filename.' created successfully'); |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | //Export base locale translations |
| 171 | - if (!file_exists(BASE_DIR . DIRECTORY_SEPARATOR . 'locale')) { |
|
| 172 | - GeneratorHelper::createDir(BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
| 173 | - self::copyr(SOURCE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'locale', BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
| 171 | + if (!file_exists(BASE_DIR.DIRECTORY_SEPARATOR.'locale')) { |
|
| 172 | + GeneratorHelper::createDir(BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
| 173 | + self::copyr(SOURCE_DIR.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'locale', BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
@@ -186,12 +186,12 @@ discard block |
||
| 186 | 186 | { |
| 187 | 187 | if (file_exists($filenamePath)) { |
| 188 | 188 | $destfolder = basename($filenamePath); |
| 189 | - if (!file_exists(WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder) || $debug || $force) { |
|
| 189 | + if (!file_exists(WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder) || $debug || $force) { |
|
| 190 | 190 | if (is_dir($filenamePath)) { |
| 191 | - self::copyr($filenamePath, WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder); |
|
| 192 | - } else { |
|
| 193 | - if (@copy($filenamePath, WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder) === FALSE) { |
|
| 194 | - throw new ConfigException("Can't copy " . $filenamePath . " to " . WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder); |
|
| 191 | + self::copyr($filenamePath, WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder); |
|
| 192 | + }else { |
|
| 193 | + if (@copy($filenamePath, WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder) === FALSE) { |
|
| 194 | + throw new ConfigException("Can't copy ".$filenamePath." to ".WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder); |
|
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | } |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | self::createDir($dst); |
| 211 | 211 | while (false !== ($file = readdir($dir))) { |
| 212 | 212 | if (($file != '.') && ($file != '..')) { |
| 213 | - if (is_dir($src . '/' . $file)) { |
|
| 214 | - self::copyr($src . '/' . $file, $dst . '/' . $file); |
|
| 215 | - } elseif (@copy($src . '/' . $file, $dst . '/' . $file) === false) { |
|
| 216 | - throw new ConfigException("Can't copy " . $src . " to " . $dst); |
|
| 213 | + if (is_dir($src.'/'.$file)) { |
|
| 214 | + self::copyr($src.'/'.$file, $dst.'/'.$file); |
|
| 215 | + } elseif (@copy($src.'/'.$file, $dst.'/'.$file) === false) { |
|
| 216 | + throw new ConfigException("Can't copy ".$src." to ".$dst); |
|
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | } |