This repository has been archived by the owner on Aug 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marvin Kuhn
authored
Dec 26, 2017
1 parent
044344d
commit 85aa81d
Showing
4 changed files
with
120 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
namespace Breadlesscode\ErrorPages\Utility; | ||
|
||
class PathUtility | ||
{ | ||
public static function cutLastPart($path, $delimiter = '/') | ||
{ | ||
$pos = strrpos($path, $delimiter); | ||
|
||
if ($pos === false || $pos === 1) { | ||
return null; | ||
} | ||
|
||
return substr($path, 0, $pos); | ||
} | ||
public static function path2array($path, $delimiter = '/') | ||
{ | ||
$array = [$path]; | ||
|
||
while ($path = self::cutLastPart($path)) | ||
{ | ||
$array[] = $path; | ||
} | ||
|
||
if (\end($array) !== "") { | ||
$array[] = ''; | ||
} | ||
return $array; | ||
} | ||
public static function compare($pathOne, $pathTwo, $delimiter = '/') | ||
{ | ||
$pathOne = self::path2array($pathOne); | ||
$pathTwo = self::path2array($pathTwo); | ||
|
||
for ($distance = 0; $distance < count($pathOne); $distance++) { | ||
for ($p2index = 0; $p2index < count($pathTwo); $p2index++) { | ||
if ($pathOne[$distance] === $pathTwo[$p2index]) { | ||
return $distance + $p2index; | ||
} | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters