-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved LocationFilter, Added more tests
- Loading branch information
Showing
9 changed files
with
110 additions
and
62 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
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
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,29 @@ | ||
<?php | ||
|
||
namespace Xspf\Filter; | ||
|
||
class FileUrlFilter | ||
{ | ||
/** | ||
* @param string $location | ||
* @param string $directorySeparator | ||
* | ||
* @return string | ||
*/ | ||
public static function filter($location, $directorySeparator = DIRECTORY_SEPARATOR) | ||
{ | ||
$parts = explode($directorySeparator, $location); | ||
list($first) = $parts; | ||
$parts = array_map('rawurlencode', $parts); | ||
|
||
// Check if windows | ||
if (preg_match('/^[A-Z]\:$/', $first)) { | ||
$parts[0] = '/' . $first; | ||
} elseif ($first == '' && isset($parts[1], $parts[2]) && $parts[1] == 'cygdrive' && preg_match('/^[a-z]$/', $parts[2])) { | ||
$parts[0] = '/' . strtoupper($parts[2]) . ':'; | ||
unset($parts[1], $parts[2]); | ||
} | ||
|
||
return 'file://' . implode('/', $parts); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace Xspf\Filter; | ||
|
||
class LocalFileFilter | ||
{ | ||
/** | ||
* @param string $location | ||
* @param string $directorySeparator | ||
* | ||
* @return string | ||
*/ | ||
public static function filter($location, $directorySeparator = DIRECTORY_SEPARATOR) | ||
{ | ||
// file-"protocol" | ||
$scheme = 'file://'; | ||
if (strpos($location, $scheme) === 0) { | ||
$location = urldecode($location); | ||
$location = str_replace(['/', '\\', $directorySeparator], $directorySeparator, substr($location, strlen($scheme))); | ||
} | ||
|
||
// Windows path | ||
if (strpos($location, '\\') === 0) { | ||
$location = substr($location, 1); | ||
} | ||
|
||
return $location; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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,35 @@ | ||
<?php | ||
|
||
namespace XspfTest\Filter; | ||
|
||
use Xspf\Filter\LocalFileFilter; | ||
|
||
class LocalFileFilterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function localFileDataProvider() | ||
{ | ||
return [ | ||
// Windows | ||
['file:///C:/Video/video.mp4', '\\', 'C:\Video\video.mp4'], | ||
['file:///C:/Video/spaces%20video.mp4', '\\', 'C:\Video\spaces video.mp4'], | ||
['file:///C:/Video/%28strange%29%20symbols%20video.mp4', '\\', 'C:\Video\(strange) symbols video.mp4'], | ||
|
||
// Linux | ||
['file:///home/user/video/video.mp4', '/', '/home/user/video/video.mp4'], | ||
['file:///home/user/video/spaces%20video.mp4', '/', '/home/user/video/spaces video.mp4'], | ||
['file:///home/user/video/%28strange%29%20symbols%20video.mp4', '/', '/home/user/video/(strange) symbols video.mp4'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider localFileDataProvider | ||
* | ||
* @param string $fileUrl | ||
* @param string $directorySeparator | ||
* @param string $expectedLocalFile | ||
*/ | ||
public function testFilter($fileUrl, $directorySeparator, $expectedLocalFile) | ||
{ | ||
$this->assertEquals($expectedLocalFile, LocalFileFilter::filter($fileUrl, $directorySeparator)); | ||
} | ||
} |
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