From 87bcff16548b7ddc00a186f3661071174bac8670 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sat, 12 Oct 2019 15:51:17 +0200 Subject: [PATCH] Various small improvements --- lib/Pico.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/Pico.php b/lib/Pico.php index f44f42f..1026c4e 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -2582,11 +2582,10 @@ class Pico public function getFiles($directory, $fileExtension = '', $order = self::SORT_ASC) { $directory = rtrim($directory, '/'); + $fileExtensionLength = strlen($fileExtension); $result = array(); - // scandir() reads files in alphabetical order $files = scandir($directory, $order); - $fileExtensionLength = strlen($fileExtension); if ($files !== false) { foreach ($files as $file) { // exclude hidden files/dirs starting with a .; this also excludes the special dirs . and .. @@ -2675,9 +2674,9 @@ class Pico /** * Normalizes a path by taking care of '', '.' and '..' parts * - * @param string $path path to normalize - * @param bool $allowsAbsolutePath whether absolute paths are allowed - * @param bool $endSlash whether to add a trailing slash to the + * @param string $path path to normalize + * @param bool $allowAbsolutePath whether absolute paths are allowed + * @param bool $endSlash whether to add a trailing slash to the * normalized path or not (defaults to TRUE) * * @return string normalized path @@ -2685,7 +2684,7 @@ class Pico * @throws UnexpectedValueException thrown when a absolute path is passed * although absolute paths aren't allowed */ - public function getNormalizedPath($path, $allowsAbsolutePath = false, $endSlash = true) + public function getNormalizedPath($path, $allowAbsolutePath = false, $endSlash = true) { $absolutePath = ''; if (DIRECTORY_SEPARATOR === '\\') { @@ -2700,7 +2699,7 @@ class Pico } } - if ($absolutePath && !$allowsAbsolutePath) { + if ($absolutePath && !$allowAbsolutePath) { throw new UnexpectedValueException( 'Argument 1 passed to ' . __METHOD__ . ' must be a relative path, absolute path "' . $path . '" given' ); @@ -2743,12 +2742,8 @@ class Pico */ public function getAbsoluteUrl($url, $baseUrl = null, $endSlash = true) { - if ($baseUrl === null) { - $baseUrl = $this->getBaseUrl(); - } - if (($url[0] !== '/') && !preg_match('#^[A-Za-z][A-Za-z0-9+\-.]*://#', $url)) { - $url = $baseUrl . $url; + $url = (($baseUrl !== null) ? $baseUrl : $this->getBaseUrl()) . $url; } return rtrim($url, '/') . ($endSlash ? '/' : '');