Skip to content

Commit

Permalink
Altered implementation of the last PR and added it to the changelog.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Sep 5, 2015
1 parent 400091a commit 7323424
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
8 changes: 7 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

## 1.0.11 - 2014-07-18
## 1.0.12 - 2015-09-05

### Fixed

* [Util::pathinfo] Now checks for existence of the dirname key, it's missing in some PHP versions.

## 1.0.11 - 2015-07-18

### Fixed

Expand Down
23 changes: 13 additions & 10 deletions src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ class Util
public static function pathinfo($path)
{
$pathinfo = pathinfo($path) + compact('path');

if (!array_key_exists('dirname', $pathinfo)) {
$pathinfo['dirname'] = '';
} else {
$pathinfo['dirname'] = static::normalizeDirname($pathinfo['dirname']);
}
$pathinfo['dirname'] = array_key_exists('dirname', $pathinfo)
? static::normalizeDirname($pathinfo['dirname'])
: '';

return $pathinfo;
}
Expand Down Expand Up @@ -94,7 +91,9 @@ public static function normalizePath($path)
$normalized = static::normalizeRelativePath($normalized);

if (preg_match('#/\.{2}|^\.{2}/|^\.{2}$#', $normalized)) {
throw new LogicException('Path is outside of the defined root, path: ['.$path.'], resolved: ['.$normalized.']');
throw new LogicException(
'Path is outside of the defined root, path: [' . $path . '], resolved: [' . $normalized . ']'
);
}

$normalized = preg_replace('#\\\{2,}#', '\\', trim($normalized, '\\'));
Expand Down Expand Up @@ -135,7 +134,7 @@ public static function normalizeRelativePath($path)
*/
public static function normalizePrefix($prefix, $separator)
{
return rtrim($prefix, $separator).$separator;
return rtrim($prefix, $separator) . $separator;
}

/**
Expand Down Expand Up @@ -186,7 +185,11 @@ public static function emulateDirectories(array $listing)
$listedDirectories = [];

foreach ($listing as $object) {
list($directories, $listedDirectories) = static::emulateObjectDirectories($object, $directories, $listedDirectories);
list($directories, $listedDirectories) = static::emulateObjectDirectories(
$object,
$directories,
$listedDirectories
);
}

$directories = array_diff(array_unique($directories), array_unique($listedDirectories));
Expand Down Expand Up @@ -274,7 +277,7 @@ protected static function emulateObjectDirectories(array $object, array $directo

$parent = $object['dirname'];

while (!empty($parent) && !in_array($parent, $directories)) {
while (! empty($parent) && ! in_array($parent, $directories)) {
$directories[] = $parent;
$parent = static::dirname($parent);
}
Expand Down

0 comments on commit 7323424

Please sign in to comment.