mirror of
https://codeberg.org/icewind/streams.git
synced 2026-06-03 16:44:07 +02:00
formatting
This commit is contained in:
parent
a0abe86651
commit
fdc0e3f113
21 changed files with 118 additions and 111 deletions
|
|
@ -63,11 +63,11 @@ class CallbackWrapper extends Wrapper {
|
|||
*/
|
||||
public static function wrap($source, $read = null, $write = null, $close = null, $readDir = null, $preClose = null) {
|
||||
$context = [
|
||||
'source' => $source,
|
||||
'read' => $read,
|
||||
'write' => $write,
|
||||
'close' => $close,
|
||||
'readDir' => $readDir,
|
||||
'source' => $source,
|
||||
'read' => $read,
|
||||
'write' => $write,
|
||||
'close' => $close,
|
||||
'readDir' => $readDir,
|
||||
'preClose' => $preClose,
|
||||
];
|
||||
return self::wrapSource($source, $context);
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class CountWrapper extends Wrapper {
|
|||
throw new \InvalidArgumentException('Invalid or missing callback');
|
||||
}
|
||||
return self::wrapSource($source, [
|
||||
'source' => $source,
|
||||
'source' => $source,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
namespace Icewind\Streams;
|
||||
|
||||
|
||||
abstract class HashWrapper extends Wrapper {
|
||||
|
||||
/**
|
||||
|
|
@ -48,7 +47,7 @@ abstract class HashWrapper extends Wrapper {
|
|||
*/
|
||||
public static function wrap($source, $hash, $callback) {
|
||||
$context = [
|
||||
'hash' => $hash,
|
||||
'hash' => $hash,
|
||||
'callback' => $callback,
|
||||
];
|
||||
return self::wrapSource($source, $context);
|
||||
|
|
@ -76,5 +75,4 @@ abstract class HashWrapper extends Wrapper {
|
|||
}
|
||||
return parent::stream_close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class IteratorDirectory extends WrapperHandler implements Directory {
|
|||
$context = parent::loadContext($name);
|
||||
if (isset($context['iterator'])) {
|
||||
$this->iterator = $context['iterator'];
|
||||
} else if (isset($context['array'])) {
|
||||
} elseif (isset($context['array'])) {
|
||||
$this->iterator = new \ArrayIterator($context['array']);
|
||||
} else {
|
||||
throw new \BadMethodCallException('Invalid context, iterator or array not set');
|
||||
|
|
@ -101,7 +101,7 @@ class IteratorDirectory extends WrapperHandler implements Directory {
|
|||
$options = [
|
||||
'iterator' => $source
|
||||
];
|
||||
} else if (is_array($source)) {
|
||||
} elseif (is_array($source)) {
|
||||
$options = [
|
||||
'array' => $source
|
||||
];
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class SeekableWrapper extends Wrapper {
|
|||
public function stream_seek($offset, $whence = SEEK_SET) {
|
||||
if ($whence === SEEK_SET) {
|
||||
$target = $offset;
|
||||
} else if ($whence === SEEK_CUR) {
|
||||
} elseif ($whence === SEEK_CUR) {
|
||||
$current = ftell($this->cache);
|
||||
$target = $current + $offset;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -48,17 +48,25 @@ class UrlCallback extends Wrapper implements Url {
|
|||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public static function wrap($source, $fopen = null, $opendir = null, $mkdir = null, $rename = null, $rmdir = null,
|
||||
$unlink = null, $stat = null) {
|
||||
public static function wrap(
|
||||
$source,
|
||||
$fopen = null,
|
||||
$opendir = null,
|
||||
$mkdir = null,
|
||||
$rename = null,
|
||||
$rmdir = null,
|
||||
$unlink = null,
|
||||
$stat = null
|
||||
) {
|
||||
return new Path(static::class, [
|
||||
'source' => $source,
|
||||
'fopen' => $fopen,
|
||||
'source' => $source,
|
||||
'fopen' => $fopen,
|
||||
'opendir' => $opendir,
|
||||
'mkdir' => $mkdir,
|
||||
'rename' => $rename,
|
||||
'rmdir' => $rmdir,
|
||||
'unlink' => $unlink,
|
||||
'stat' => $stat
|
||||
'mkdir' => $mkdir,
|
||||
'rename' => $rename,
|
||||
'rmdir' => $rmdir,
|
||||
'unlink' => $unlink,
|
||||
'stat' => $stat
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
namespace Icewind\Streams;
|
||||
|
||||
|
||||
class WrapperHandler {
|
||||
const NO_SOURCE_DIR = 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ class WriteHashWrapper extends HashWrapper {
|
|||
$this->updateHash($data);
|
||||
return parent::stream_write($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class CallbackWrapperTest extends WrapperTest {
|
|||
}
|
||||
|
||||
public function testWrapInvalidSource() {
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
$this->wrapSource('foo');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
namespace Icewind\Streams\Tests;
|
||||
|
||||
|
||||
use Icewind\Streams\CountWrapper;
|
||||
|
||||
class CountWrapperTest extends WrapperTest {
|
||||
|
|
|
|||
|
|
@ -9,36 +9,39 @@ namespace Icewind\Streams\Tests;
|
|||
|
||||
class DirectoryFilter extends \PHPUnit_Framework_TestCase {
|
||||
public function testFilterAcceptAll() {
|
||||
$this->filter(array('a', 'b', 'c'),
|
||||
$this->filter(
|
||||
['a', 'b', 'c'],
|
||||
function () {
|
||||
return true;
|
||||
},
|
||||
array('a', 'b', 'c')
|
||||
['a', 'b', 'c']
|
||||
);
|
||||
}
|
||||
|
||||
public function testFilterRejectAll() {
|
||||
$this->filter(array('a', 'b', 'c'),
|
||||
$this->filter(
|
||||
['a', 'b', 'c'],
|
||||
function () {
|
||||
return false;
|
||||
},
|
||||
array()
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
public function testFilterRejectLong() {
|
||||
$this->filter(array('a', 'bb', 'c'),
|
||||
$this->filter(
|
||||
['a', 'bb', 'c'],
|
||||
function ($file) {
|
||||
return strlen($file) < 2;
|
||||
},
|
||||
array('a', 'c')
|
||||
['a', 'c']
|
||||
);
|
||||
}
|
||||
|
||||
private function filter(array $files, callable $filter, array $expected) {
|
||||
$source = \Icewind\Streams\IteratorDirectory::wrap($files);
|
||||
$filtered = \Icewind\Streams\DirectoryFilter::wrap($source, $filter);
|
||||
$result = array();
|
||||
$result = [];
|
||||
while (($file = readdir($filtered)) !== false) {
|
||||
$result[] = $file;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ class DirectoryWrapper extends IteratorDirectory {
|
|||
}
|
||||
|
||||
public function testManipulateContent() {
|
||||
$source = \Icewind\Streams\IteratorDirectory::wrap(array('asd', 'bar'));
|
||||
$source = \Icewind\Streams\IteratorDirectory::wrap(['asd', 'bar']);
|
||||
$wrapped = DirectoryWrapperDummy::wrap($source);
|
||||
$result = array();
|
||||
$result = [];
|
||||
while (($file = readdir($wrapped)) !== false) {
|
||||
$result[] = $file;
|
||||
}
|
||||
$this->assertEquals(array('asd_', 'bar_'), $result);
|
||||
$this->assertEquals(['asd_', 'bar_'], $result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,15 +22,15 @@
|
|||
namespace Icewind\Streams\Tests;
|
||||
|
||||
class DirectoryWrapperDummy extends \Icewind\Streams\DirectoryWrapper {
|
||||
public static function wrap($source) {
|
||||
return self::wrapSource($source);
|
||||
}
|
||||
public static function wrap($source) {
|
||||
return self::wrapSource($source);
|
||||
}
|
||||
|
||||
public function dir_readdir() {
|
||||
$file = parent::dir_readdir();
|
||||
if ($file !== false) {
|
||||
$file .= '_';
|
||||
}
|
||||
return $file;
|
||||
}
|
||||
public function dir_readdir() {
|
||||
$file = parent::dir_readdir();
|
||||
if ($file !== false) {
|
||||
$file .= '_';
|
||||
}
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
namespace Icewind\Streams\Tests;
|
||||
|
||||
class DirectoryWrapperNull extends \Icewind\Streams\DirectoryWrapper {
|
||||
public static function wrap($source) {
|
||||
return self::wrapSource($source);
|
||||
}
|
||||
public static function wrap($source) {
|
||||
return self::wrapSource($source);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,15 +22,15 @@
|
|||
namespace Icewind\Streams\Tests;
|
||||
|
||||
class FailWrapper extends \Icewind\Streams\NullWrapper {
|
||||
public static function wrap($source) {
|
||||
return self::wrapSource($source);
|
||||
}
|
||||
public static function wrap($source) {
|
||||
return self::wrapSource($source);
|
||||
}
|
||||
|
||||
public function stream_read($count) {
|
||||
return false;
|
||||
}
|
||||
public function stream_read($count) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function stream_write($data) {
|
||||
return false;
|
||||
}
|
||||
public function stream_write($data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,12 +72,12 @@ class HashWrapperTest extends TestCase {
|
|||
*/
|
||||
public function testReadHash($algorithm, $expectedHash) {
|
||||
$obtainedHash = null;
|
||||
$callback = function($hash) use (&$obtainedHash) {
|
||||
$callback = function ($hash) use (&$obtainedHash) {
|
||||
$obtainedHash = $hash;
|
||||
};
|
||||
|
||||
$stream = $this->wrapSourceRead($this->getSource(), $algorithm, $callback);
|
||||
while(feof($stream) === false) {
|
||||
while (feof($stream) === false) {
|
||||
fread($stream, 20);
|
||||
}
|
||||
fclose($stream);
|
||||
|
|
@ -93,7 +93,7 @@ class HashWrapperTest extends TestCase {
|
|||
*/
|
||||
public function testWriteHash($algorithm, $expectedHash) {
|
||||
$obtainedHash = null;
|
||||
$callback = function($hash) use (&$obtainedHash) {
|
||||
$callback = function ($hash) use (&$obtainedHash) {
|
||||
$obtainedHash = $hash;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class IteratorDirectory extends \PHPUnit_Framework_TestCase {
|
|||
* @expectedException \BadMethodCallException
|
||||
*/
|
||||
public function testNoContext() {
|
||||
$context = stream_context_create(array());
|
||||
$context = stream_context_create([]);
|
||||
stream_wrapper_register('iterator', '\Icewind\Streams\IteratorDirectory');
|
||||
try {
|
||||
opendir('iterator://', $context);
|
||||
|
|
@ -36,11 +36,11 @@ class IteratorDirectory extends \PHPUnit_Framework_TestCase {
|
|||
* @expectedException \BadMethodCallException
|
||||
*/
|
||||
public function testNoSource() {
|
||||
$context = stream_context_create(array(
|
||||
'dir' => array(
|
||||
$context = stream_context_create([
|
||||
'dir' => [
|
||||
'foo' => 'bar'
|
||||
)
|
||||
));
|
||||
]
|
||||
]);
|
||||
stream_wrapper_register('iterator', '\Icewind\Streams\IteratorDirectory');
|
||||
try {
|
||||
opendir('iterator://', $context);
|
||||
|
|
@ -60,16 +60,16 @@ class IteratorDirectory extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
public function fileListProvider() {
|
||||
$longList = array_fill(0, 500, 'foo');
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
[
|
||||
'foo',
|
||||
'bar',
|
||||
'qwerty'
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'with spaces',
|
||||
'under_scores',
|
||||
'日本語',
|
||||
|
|
@ -78,24 +78,24 @@ class IteratorDirectory extends \PHPUnit_Framework_TestCase {
|
|||
'0',
|
||||
'double "quotes"',
|
||||
"single 'quotes'"
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'single item'
|
||||
)
|
||||
),
|
||||
array(
|
||||
]
|
||||
],
|
||||
[
|
||||
$longList
|
||||
),
|
||||
array(
|
||||
array()
|
||||
)
|
||||
);
|
||||
],
|
||||
[
|
||||
[]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
protected function basicTest($fileList, $dh) {
|
||||
$result = array();
|
||||
$result = [];
|
||||
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
$result[] = $file;
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ class NullWrapperTest extends WrapperTest {
|
|||
}
|
||||
|
||||
public function testNoContext() {
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
stream_wrapper_register('null', '\Icewind\Streams\NullWrapper');
|
||||
$context = stream_context_create(array());
|
||||
$context = stream_context_create([]);
|
||||
try {
|
||||
fopen('null://', 'r+', false, $context);
|
||||
stream_wrapper_unregister('null');
|
||||
|
|
@ -31,13 +31,13 @@ class NullWrapperTest extends WrapperTest {
|
|||
}
|
||||
|
||||
public function testNoSource() {
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
stream_wrapper_register('null', '\Icewind\Streams\NullWrapper');
|
||||
$context = stream_context_create(array(
|
||||
'null' => array(
|
||||
$context = stream_context_create([
|
||||
'null' => [
|
||||
'source' => 'bar'
|
||||
)
|
||||
));
|
||||
]
|
||||
]);
|
||||
try {
|
||||
fopen('null://', 'r+', false, $context);
|
||||
} catch (\Exception $e) {
|
||||
|
|
@ -47,7 +47,7 @@ class NullWrapperTest extends WrapperTest {
|
|||
}
|
||||
|
||||
public function testWrapInvalidSource() {
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
$this->wrapSource('foo');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,17 +22,17 @@
|
|||
namespace Icewind\Streams\Tests;
|
||||
|
||||
class PartialWrapper extends \Icewind\Streams\NullWrapper {
|
||||
public static function wrap($source) {
|
||||
return self::wrapSource($source);
|
||||
}
|
||||
public static function wrap($source) {
|
||||
return self::wrapSource($source);
|
||||
}
|
||||
|
||||
public function stream_read($count) {
|
||||
$count = min($count, 2); // return as most 2 bytes
|
||||
return parent::stream_read($count);
|
||||
}
|
||||
public function stream_read($count) {
|
||||
$count = min($count, 2); // return as most 2 bytes
|
||||
return parent::stream_read($count);
|
||||
}
|
||||
|
||||
public function stream_write($data) {
|
||||
$data = substr($data, 0, 2); //write as most 2 bytes
|
||||
return parent::stream_write($data);
|
||||
}
|
||||
public function stream_write($data) {
|
||||
$data = substr($data, 0, 2); //write as most 2 bytes
|
||||
return parent::stream_write($data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
namespace Icewind\Streams\Tests;
|
||||
|
||||
class UrlCallback extends \PHPUnit_Framework_TestCase {
|
||||
protected $tempDirs = array();
|
||||
protected $tempDirs = [];
|
||||
|
||||
protected function getTempDir() {
|
||||
$dir = sys_get_temp_dir() . '/streams_' . uniqid();
|
||||
|
|
@ -30,7 +30,7 @@ class UrlCallback extends \PHPUnit_Framework_TestCase {
|
|||
* @var \SplFileInfo $file
|
||||
*/
|
||||
foreach ($iterator as $file) {
|
||||
if (in_array($file->getBasename(), array('.', '..'))) {
|
||||
if (in_array($file->getBasename(), ['.', '..'])) {
|
||||
continue;
|
||||
} elseif ($file->isDir()) {
|
||||
rmdir($file->getPathname());
|
||||
|
|
|
|||
|
|
@ -104,12 +104,12 @@ abstract class WrapperTest extends TestCase {
|
|||
stream_set_blocking($wrapped, 0);
|
||||
stream_set_timeout($wrapped, 1, 0);
|
||||
stream_set_write_buffer($wrapped, 0);
|
||||
$this->assertTrue(true);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testReadDir() {
|
||||
$source = opendir(__DIR__);
|
||||
$content = array();
|
||||
$content = [];
|
||||
while (($name = readdir($source)) !== false) {
|
||||
$content[] = $name;
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ abstract class WrapperTest extends TestCase {
|
|||
|
||||
$source = opendir(__DIR__);
|
||||
$wrapped = $this->wrapSource($source);
|
||||
$wrappedContent = array();
|
||||
$wrappedContent = [];
|
||||
while (($name = readdir($wrapped)) !== false) {
|
||||
$wrappedContent[] = $name;
|
||||
}
|
||||
|
|
@ -126,7 +126,7 @@ abstract class WrapperTest extends TestCase {
|
|||
|
||||
public function testRewindDir() {
|
||||
$source = opendir(__DIR__);
|
||||
$content = array();
|
||||
$content = [];
|
||||
while (($name = readdir($source)) !== false) {
|
||||
$content[] = $name;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue