From ec91effd7e5082f15baa6b92f92b9d86360a52a9 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 13 Apr 2022 17:39:59 +1200 Subject: [PATCH] ENH PHP 8.1 compatibility --- code/PortChecker.php | 2 +- code/ServerFactory.php | 6 +++--- code/constants.php | 2 +- code/server-handler.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/code/PortChecker.php b/code/PortChecker.php index 2c53aa7..ba6aa18 100644 --- a/code/PortChecker.php +++ b/code/PortChecker.php @@ -24,7 +24,7 @@ public static function isPortOpen($host, $port) $host = 'localhost'; } - $connection = @fsockopen($host, $port); + $connection = @fsockopen($host ?? '', $port ?? 0); if (is_resource($connection)) { fclose($connection); return true; diff --git a/code/ServerFactory.php b/code/ServerFactory.php index 25137b4..9f5df65 100644 --- a/code/ServerFactory.php +++ b/code/ServerFactory.php @@ -46,13 +46,13 @@ public function launchServer($options) $port = PortChecker::findNextAvailablePort($host, $options['preferredPort']); $base = __DIR__; - $command = "exec " . escapeshellcmd($bin) . + $command = "exec " . escapeshellcmd($bin ?? '') . ' -S ' . escapeshellarg($host . ':' . $port) . - ' -t ' . escapeshellarg($this->path) . ' ' . + ' -t ' . escapeshellarg($this->path ?? '') . ' ' . escapeshellarg($base . '/server-handler.php'); if (!empty($options['bootstrapFile'])) { - $command = "SERVE_BOOTSTRAP_FILE=" . escapeshellarg($options['bootstrapFile']) . " $command"; + $command = "SERVE_BOOTSTRAP_FILE=" . escapeshellarg($options['bootstrapFile'] ?? '') . " $command"; } $server = new Server($command, $host, $port); diff --git a/code/constants.php b/code/constants.php index bf8c487..8e088d9 100644 --- a/code/constants.php +++ b/code/constants.php @@ -6,7 +6,7 @@ // Detect BASE_PATH with public-folder awareness define( 'BASE_PATH', - basename(getcwd()) === 'public' + basename(getcwd() ?? '') === 'public' ? dirname(getcwd()) : getcwd() ); diff --git a/code/server-handler.php b/code/server-handler.php index 64a63b7..ac05723 100644 --- a/code/server-handler.php +++ b/code/server-handler.php @@ -18,7 +18,7 @@ } $uri = urldecode( - parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) + parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) ?? '' ); if ($uri !== "/" && file_exists(PUBLIC_PATH . $uri) && !is_dir(PUBLIC_PATH . $uri)) {