-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add PathWrapper to get a virtual path for an existing file
- Loading branch information
1 parent
d3620e8
commit 5981b1b
Showing
4 changed files
with
55 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2016 Robin Appelman <icewind@owncloud.com> | ||
* This file is licensed under the Licensed under the MIT license: | ||
* http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace Icewind\Streams; | ||
|
||
/** | ||
* A string-like object that maps to an existing stream when opened | ||
*/ | ||
class PathWrapper extends NullWrapper { | ||
/** | ||
* @param resource $source | ||
* @return Path|string | ||
*/ | ||
public static function getPath($source) { | ||
return new Path(__CLASS__, [ | ||
'null' => [ | ||
'source' => $source | ||
] | ||
]); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2016 Robin Appelman <icewind@owncloud.com> | ||
* This file is licensed under the Licensed under the MIT license: | ||
* http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace Icewind\Streams\Tests; | ||
|
||
class PathWrapper extends \PHPUnit_Framework_TestCase { | ||
private function getDataStream($data) { | ||
$stream = fopen('php://temp', 'w+'); | ||
fwrite($stream, $data); | ||
rewind($stream); | ||
return $stream; | ||
} | ||
|
||
public function testFileGetContents() { | ||
$data = 'foobar'; | ||
$stream = $this->getDataStream($data); | ||
$path = \Icewind\Streams\PathWrapper::getPath($stream); | ||
$this->assertEquals($data, file_get_contents($path)); | ||
} | ||
} |