From b340fe3569d1cb3dee82578c72383c20f1f1bc8f Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Mon, 11 May 2015 12:20:09 +0200 Subject: [PATCH] Refactor PHP. Switch to explicit string literals where possible. --- .../server/php/inc/ext/class-archive.php | 32 +++++++++---------- src/_h5ai/server/php/inc/ext/class-custom.php | 26 +++++++-------- src/_h5ai/server/php/inc/ext/class-search.php | 2 +- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/_h5ai/server/php/inc/ext/class-archive.php b/src/_h5ai/server/php/inc/ext/class-archive.php index 9ad70a8c..1a98b6fb 100644 --- a/src/_h5ai/server/php/inc/ext/class-archive.php +++ b/src/_h5ai/server/php/inc/ext/class-archive.php @@ -3,8 +3,8 @@ class Archive { private static $SEGMENT_SIZE = 16777216; // 1024 * 1024 * 16 = 16MiB - private static $TAR_PASSTHRU_CMD = "cd [ROOTDIR] && tar --no-recursion -c -- [DIRS] [FILES]"; - private static $ZIP_PASSTHRU_CMD = "cd [ROOTDIR] && zip - -- [FILES]"; + private static $TAR_PASSTHRU_CMD = 'cd [ROOTDIR] && tar --no-recursion -c -- [DIRS] [FILES]'; + private static $ZIP_PASSTHRU_CMD = 'cd [ROOTDIR] && zip - -- [FILES]'; private $app, $base_path, $dirs, $files; @@ -28,22 +28,22 @@ class Archive { $this->add_hrefs($hrefs); if (count($this->dirs) === 0 && count($this->files) === 0) { - if ($type === "php-tar") { - $this->add_dir($this->base_path, "/"); + if ($type === 'php-tar') { + $this->add_dir($this->base_path, '/'); } else { - $this->add_dir($this->base_path, "."); + $this->add_dir($this->base_path, '.'); } } - if ($type === "php-tar") { + if ($type === 'php-tar') { return $this->php_tar($this->dirs, $this->files); - } else if ($type === "shell-tar") { + } else if ($type === 'shell-tar') { return $this->shell_cmd(Archive::$TAR_PASSTHRU_CMD); - } else if ($type === "shell-zip") { + } else if ($type === 'shell-zip') { return $this->shell_cmd(Archive::$ZIP_PASSTHRU_CMD); } @@ -53,9 +53,9 @@ class Archive { private function shell_cmd($cmd) { - $cmd = str_replace("[ROOTDIR]", escapeshellarg($this->base_path), $cmd); - $cmd = str_replace("[DIRS]", count($this->dirs) ? implode(" ", array_map("escapeshellarg", $this->dirs)) : "", $cmd); - $cmd = str_replace("[FILES]", count($this->files) ? implode(" ", array_map("escapeshellarg", $this->files)) : "", $cmd); + $cmd = str_replace('[ROOTDIR]', escapeshellarg($this->base_path), $cmd); + $cmd = str_replace('[DIRS]', count($this->dirs) ? implode(' ', array_map('escapeshellarg', $this->dirs)) : '', $cmd); + $cmd = str_replace('[FILES]', count($this->files) ? implode(' ', array_map('escapeshellarg', $this->files)) : '', $cmd); try { Util::passthru_cmd($cmd); } catch (Exeption $err) { @@ -80,7 +80,7 @@ class Archive { } } - header("Content-Length: " . $total_size); + header('Content-Length: ' . $total_size); foreach ($dirs as $archived_dir) { @@ -154,7 +154,7 @@ class Archive { foreach ($hrefs as $href) { - if (trim($href) === "") { + if (trim($href) === '') { continue; } @@ -164,7 +164,7 @@ class Archive { if ($this->app->is_managed_href($d) && !$this->app->is_hidden($n)) { $real_file = $this->app->to_path($href); - $archived_file = preg_replace("!^" . preg_quote(Util::normalize_path($this->base_path, true)) . "!", "", $real_file); + $archived_file = preg_replace('!^' . preg_quote(Util::normalize_path($this->base_path, true)) . '!', '', $real_file); if (is_dir($real_file)) { $this->add_dir($real_file, $archived_file); @@ -192,8 +192,8 @@ class Archive { $files = $this->app->read_dir($real_dir); foreach ($files as $file) { - $real_file = $real_dir . "/" . $file; - $archived_file = $archived_dir . "/" . $file; + $real_file = $real_dir . '/' . $file; + $archived_file = $archived_dir . '/' . $file; if (is_dir($real_file)) { $this->add_dir($real_file, $archived_file); diff --git a/src/_h5ai/server/php/inc/ext/class-custom.php b/src/_h5ai/server/php/inc/ext/class-custom.php index f78a05a7..55f64235 100644 --- a/src/_h5ai/server/php/inc/ext/class-custom.php +++ b/src/_h5ai/server/php/inc/ext/class-custom.php @@ -2,7 +2,7 @@ class Custom { - private static $extensions = ["html", "md"]; + private static $extensions = ['html', 'md']; function __construct($app) { @@ -11,10 +11,10 @@ class Custom { private function read_custom_file($path, $name, &$content, &$type) { - $file_prefix = $this->app->get_setup()->get("FILE_PREFIX"); + $file_prefix = $this->app->get_setup()->get('FILE_PREFIX'); foreach (Custom::$extensions as $ext) { - $file = "${path}/${file_prefix}.${name}.${ext}"; + $file = $path . '/' . $file_prefix . '.' . $name . '.' . $ext; if (is_readable($file)) { $content = file_get_contents($file); $type = $ext; @@ -25,14 +25,14 @@ class Custom { public function get_customizations($href) { - if (!$this->app->query_option("custom.enabled", false)) { + if (!$this->app->query_option('custom.enabled', false)) { return [ - "header" => ["content" => null, "type" => null], - "footer" => ["content" => null, "type" => null] + 'header' => ['content' => null, 'type' => null], + 'footer' => ['content' => null, 'type' => null] ]; } - $root_path = $this->app->get_setup()->get("FILE_PREFIX"); + $root_path = $this->app->get_setup()->get('FILE_PREFIX'); $path = $this->app->to_path($href); $header = null; @@ -40,16 +40,16 @@ class Custom { $footer = null; $footer_type = null; - $this->read_custom_file($path, "header", $header, $header_type); - $this->read_custom_file($path, "footer", $footer, $footer_type); + $this->read_custom_file($path, 'header', $header, $header_type); + $this->read_custom_file($path, 'footer', $footer, $footer_type); while ($header === null || $footer === null) { if ($header === null) { - $this->read_custom_file($path, "headers", $header, $header_type); + $this->read_custom_file($path, 'headers', $header, $header_type); } if ($footer === null) { - $this->read_custom_file($path, "footers", $footer, $footer_type); + $this->read_custom_file($path, 'footers', $footer, $footer_type); } if ($path === $root_path) { @@ -63,8 +63,8 @@ class Custom { } return [ - "header" => ["content" => $header, "type" => $header_type], - "footer" => ["content" => $footer, "type" => $footer_type] + 'header' => ['content' => $header, 'type' => $header_type], + 'footer' => ['content' => $footer, 'type' => $footer_type] ]; } } diff --git a/src/_h5ai/server/php/inc/ext/class-search.php b/src/_h5ai/server/php/inc/ext/class-search.php index afd61086..597f356d 100644 --- a/src/_h5ai/server/php/inc/ext/class-search.php +++ b/src/_h5ai/server/php/inc/ext/class-search.php @@ -14,7 +14,7 @@ class Search { $re = Util::wrap_pattern($pattern); $names = $this->app->read_dir($root); foreach ($names as $name) { - $path = $root . "/" . $name; + $path = $root . '/' . $name; if (preg_match($re, @basename($path))) { $paths[] = $path; }