Various small improvements

pico-3.0-alpha
Daniel Rudolf 6 years ago
parent e4e6f0f5f0
commit 87bcff1654
No known key found for this signature in database
GPG Key ID: A061F02CD8DE4538
  1. 19
      lib/Pico.php

@ -2582,11 +2582,10 @@ class Pico
public function getFiles($directory, $fileExtension = '', $order = self::SORT_ASC) public function getFiles($directory, $fileExtension = '', $order = self::SORT_ASC)
{ {
$directory = rtrim($directory, '/'); $directory = rtrim($directory, '/');
$fileExtensionLength = strlen($fileExtension);
$result = array(); $result = array();
// scandir() reads files in alphabetical order
$files = scandir($directory, $order); $files = scandir($directory, $order);
$fileExtensionLength = strlen($fileExtension);
if ($files !== false) { if ($files !== false) {
foreach ($files as $file) { foreach ($files as $file) {
// exclude hidden files/dirs starting with a .; this also excludes the special dirs . and .. // 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 * Normalizes a path by taking care of '', '.' and '..' parts
* *
* @param string $path path to normalize * @param string $path path to normalize
* @param bool $allowsAbsolutePath whether absolute paths are allowed * @param bool $allowAbsolutePath whether absolute paths are allowed
* @param bool $endSlash whether to add a trailing slash to the * @param bool $endSlash whether to add a trailing slash to the
* normalized path or not (defaults to TRUE) * normalized path or not (defaults to TRUE)
* *
* @return string normalized path * @return string normalized path
@ -2685,7 +2684,7 @@ class Pico
* @throws UnexpectedValueException thrown when a absolute path is passed * @throws UnexpectedValueException thrown when a absolute path is passed
* although absolute paths aren't allowed * although absolute paths aren't allowed
*/ */
public function getNormalizedPath($path, $allowsAbsolutePath = false, $endSlash = true) public function getNormalizedPath($path, $allowAbsolutePath = false, $endSlash = true)
{ {
$absolutePath = ''; $absolutePath = '';
if (DIRECTORY_SEPARATOR === '\\') { if (DIRECTORY_SEPARATOR === '\\') {
@ -2700,7 +2699,7 @@ class Pico
} }
} }
if ($absolutePath && !$allowsAbsolutePath) { if ($absolutePath && !$allowAbsolutePath) {
throw new UnexpectedValueException( throw new UnexpectedValueException(
'Argument 1 passed to ' . __METHOD__ . ' must be a relative path, absolute path "' . $path . '" given' '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) 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)) { 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 ? '/' : ''); return rtrim($url, '/') . ($endSlash ? '/' : '');

Loading…
Cancel
Save