mirror of
https://github.com/adlawson/php-vfs.git
synced 2024-11-22 04:25:12 +00:00
Update URL parsing implementation
Better supports `scheme:///path` and `scheme:///`.
This commit is contained in:
parent
aee858c1c4
commit
ecbce78baf
@ -99,10 +99,13 @@ abstract class AbstractHandle implements HandleInterface
|
||||
$scheme = null;
|
||||
|
||||
if (isset($parts['scheme'])) {
|
||||
$path = substr($url, strlen($parts['scheme'] . ':/'));
|
||||
$scheme = $parts['scheme'];
|
||||
} else {
|
||||
$scheme = strstr($url, '://', true);
|
||||
}
|
||||
|
||||
$path = '/' . ltrim(substr($url, strlen($scheme)), ':\/');
|
||||
|
||||
return [$scheme, $path];
|
||||
}
|
||||
|
||||
|
@ -338,7 +338,7 @@ class StreamWrapper
|
||||
protected function getFileSystemForUrl($url)
|
||||
{
|
||||
$parts = parse_url($url);
|
||||
$scheme = isset($parts['scheme']) ? $parts['scheme'] : null;
|
||||
$scheme = isset($parts['scheme']) ? $parts['scheme'] : strstr($url, '://', true);
|
||||
|
||||
return FileSystemRegistry::getInstance()->get($scheme);
|
||||
}
|
||||
|
@ -13,31 +13,31 @@ class FileGetContentsAcceptanceTest extends AcceptanceTestCase
|
||||
|
||||
public function testGetDirectory()
|
||||
{
|
||||
$this->assertEquals('', file_get_contents("$this->scheme://foo"));
|
||||
$this->assertEquals('', file_get_contents("$this->scheme:///foo"));
|
||||
}
|
||||
|
||||
public function testGetFile()
|
||||
{
|
||||
$this->assertEquals($this->tree['foo']['bar'], file_get_contents("$this->scheme://foo/bar"));
|
||||
$this->assertEquals($this->tree['foo']['bar'], file_get_contents("$this->scheme:///foo/bar"));
|
||||
}
|
||||
|
||||
public function testPutFile()
|
||||
{
|
||||
file_put_contents("$this->scheme://foo/bar", 'bar');
|
||||
file_put_contents("$this->scheme:///foo/bar", 'bar');
|
||||
|
||||
$this->assertEquals('bar', $this->fs->get('/foo/bar')->getContent());
|
||||
}
|
||||
|
||||
public function testPutExistingFile()
|
||||
{
|
||||
file_put_contents("$this->scheme://foo/bar", '_updated');
|
||||
file_put_contents("$this->scheme:///foo/bar", '_updated');
|
||||
|
||||
$this->assertEquals('_updated', $this->fs->get('/foo/bar')->getContent());
|
||||
}
|
||||
|
||||
public function testPutAppendExistingFile()
|
||||
{
|
||||
file_put_contents("$this->scheme://foo/bar", '_updated', FILE_APPEND);
|
||||
file_put_contents("$this->scheme:///foo/bar", '_updated', FILE_APPEND);
|
||||
|
||||
$this->assertEquals($this->tree['foo']['bar'] . '_updated', $this->fs->get('/foo/bar')->getContent());
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class FopenAcceptanceTest extends AcceptanceTestCase
|
||||
*/
|
||||
public function testFopenFile($mode)
|
||||
{
|
||||
$this->assertTrue(is_resource(fopen("$this->scheme://foo/bar", $mode)));
|
||||
$this->assertTrue(is_resource(fopen("$this->scheme:///foo/bar", $mode)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,7 +60,7 @@ class FopenAcceptanceTest extends AcceptanceTestCase
|
||||
{
|
||||
$this->setExpectedException('PHPUnit_Framework_Error_Warning');
|
||||
|
||||
fopen("$this->scheme://foo/bar", $mode);
|
||||
fopen("$this->scheme:///foo/bar", $mode);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +68,7 @@ class FopenAcceptanceTest extends AcceptanceTestCase
|
||||
*/
|
||||
public function testFopenMissingFile($mode)
|
||||
{
|
||||
$this->assertTrue(is_resource(fopen("$this->scheme://foo/baz", $mode)));
|
||||
$this->assertTrue(is_resource(fopen("$this->scheme:///foo/baz", $mode)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,7 +78,7 @@ class FopenAcceptanceTest extends AcceptanceTestCase
|
||||
{
|
||||
$this->setExpectedException('PHPUnit_Framework_Error_Warning');
|
||||
|
||||
fopen("$this->scheme://foo/baz", $mode);
|
||||
fopen("$this->scheme:///foo/baz", $mode);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,7 +86,7 @@ class FopenAcceptanceTest extends AcceptanceTestCase
|
||||
*/
|
||||
public function testFopenDirectory($mode)
|
||||
{
|
||||
$this->assertTrue(is_resource(fopen("$this->scheme://foo", $mode)));
|
||||
$this->assertTrue(is_resource(fopen("$this->scheme:///foo", $mode)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,7 +96,7 @@ class FopenAcceptanceTest extends AcceptanceTestCase
|
||||
{
|
||||
$this->setExpectedException('PHPUnit_Framework_Error_Warning');
|
||||
|
||||
fopen("$this->scheme://foo", $mode);
|
||||
fopen("$this->scheme:///foo", $mode);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +104,7 @@ class FopenAcceptanceTest extends AcceptanceTestCase
|
||||
*/
|
||||
public function testFopenMissingDirectory($mode)
|
||||
{
|
||||
$this->assertTrue(is_resource(fopen("$this->scheme://baz", $mode)));
|
||||
$this->assertTrue(is_resource(fopen("$this->scheme:///baz", $mode)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,6 +114,6 @@ class FopenAcceptanceTest extends AcceptanceTestCase
|
||||
{
|
||||
$this->setExpectedException('PHPUnit_Framework_Error_Warning');
|
||||
|
||||
fopen("$this->scheme://baz", $mode);
|
||||
fopen("$this->scheme:///baz", $mode);
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class FreadAcceptanceTest extends AcceptanceTestCase
|
||||
*/
|
||||
public function testFreadFile($mode, $content, $size, $expectation)
|
||||
{
|
||||
$resource = fopen("$this->scheme://foo/bar", $mode);
|
||||
$resource = fopen("$this->scheme:///foo/bar", $mode);
|
||||
|
||||
$this->assertEquals($expectation, fread($resource, $size));
|
||||
|
||||
@ -74,7 +74,7 @@ class FreadAcceptanceTest extends AcceptanceTestCase
|
||||
*/
|
||||
public function testFreadMissingFile($mode)
|
||||
{
|
||||
$resource = fopen("$this->scheme://bar", $mode);
|
||||
$resource = fopen("$this->scheme:///bar", $mode);
|
||||
|
||||
$this->assertEquals('', fread($resource, 10));
|
||||
|
||||
|
@ -16,18 +16,18 @@ class RequireAcceptanceTest extends AcceptanceTestCase
|
||||
|
||||
public function testIncludeFile()
|
||||
{
|
||||
$this->assertEquals('baz', include "$this->scheme://foo/bar.php");
|
||||
$this->assertEquals('baz', include "$this->scheme:///foo/bar.php");
|
||||
}
|
||||
|
||||
public function testRequireFile()
|
||||
{
|
||||
$this->assertEquals('baz', require "$this->scheme://foo/bar.php");
|
||||
$this->assertEquals('baz', require "$this->scheme:///foo/bar.php");
|
||||
}
|
||||
|
||||
public function testIncludeMissingFile()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit_Framework_Error_Warning');
|
||||
|
||||
include "$this->scheme://bar.php";
|
||||
include "$this->scheme:///bar.php";
|
||||
}
|
||||
}
|
||||
|
@ -13,11 +13,11 @@ class StatAcceptanceTest extends AcceptanceTestCase
|
||||
|
||||
public function testIsDir()
|
||||
{
|
||||
$this->assertTrue(is_dir("$this->scheme://foo"));
|
||||
$this->assertTrue(is_dir("$this->scheme:///foo"));
|
||||
}
|
||||
|
||||
public function testIsFile()
|
||||
{
|
||||
$this->assertTrue(is_file("$this->scheme://foo/bar"));
|
||||
$this->assertTrue(is_file("$this->scheme:///foo/bar"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user