Update URL parsing implementation

Better supports `scheme:///path` and `scheme:///`.
This commit is contained in:
adlawson 2014-09-07 00:44:12 +01:00
parent aee858c1c4
commit ecbce78baf
7 changed files with 25 additions and 22 deletions

View File

@ -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];
}

View File

@ -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);
}

View File

@ -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());
}

View File

@ -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);
}
}

View File

@ -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));

View File

@ -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";
}
}

View File

@ -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"));
}
}