Skip to content

Commit 4e2af61

Browse files
authored
Merge pull request #58 from CharlotteDunoisLabs/sink-array
Resolve with array instead of SplObjectStorage (AdapterInterface::ls(), Node\DirectoryInterface::lsRecursive(), Node\NodeInterface::copy, ObjectStreamSink::promise())
2 parents 5ca5146 + 5990d53 commit 4e2af61

9 files changed

+20
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ List contents
124124
-------------
125125

126126
```php
127-
$filesystem->dir(__DIR__)->ls()->then(function (\SplObjectStorage $list) {
127+
$filesystem->dir(__DIR__)->ls()->then(function (array $list) {
128128
foreach ($list as $node) {
129129
echo $node->getPath(), PHP_EOL;
130130
}

examples/directory_create_recursive.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
echo 'Creating directory: ' . $dirName, PHP_EOL;
1414
$dir->createRecursive('rwxrwx---')->then(function () use ($startDir) {
1515
return $startDir->lsRecursive();
16-
})->then(function (\SplObjectStorage $list) {
16+
})->then(function (array $list) {
1717
foreach ($list as $node) {
1818
echo $node->getPath(), PHP_EOL;
1919
}

examples/directory_ls.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
$filesystem = \React\Filesystem\Filesystem::create($loop);
88
echo 'Using ', get_class($filesystem->getAdapter()), PHP_EOL;
9-
$filesystem->dir(__DIR__ . DIRECTORY_SEPARATOR . 'tmp')->ls()->then(function (\SplObjectStorage $list) {
9+
$filesystem->dir(__DIR__ . DIRECTORY_SEPARATOR . 'tmp')->ls()->then(function (array $list) {
1010
foreach ($list as $node) {
1111
echo get_class($node), ': ', $node->getPath(), PHP_EOL;
1212
}

examples/directory_ls_recursive.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
$filesystem = \React\Filesystem\Filesystem::create($loop);
88
echo 'Using ', get_class($filesystem->getAdapter()), PHP_EOL;
9-
$filesystem->dir(dirname(__DIR__))->lsRecursive()->then(function (\SplObjectStorage $list) {
9+
$filesystem->dir(dirname(__DIR__))->lsRecursive()->then(function (array $list) {
1010
foreach ($list as $node) {
1111
echo $node->getPath(), PHP_EOL;
1212
}

examples/directory_ls_recursive_regexp_interfaces.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
$filesystem = \React\Filesystem\Filesystem::create($loop);
88
echo 'Using ', get_class($filesystem->getAdapter()), PHP_EOL;
9-
$filesystem->dir(dirname(__DIR__))->lsRecursive()->then(function (\SplObjectStorage $list) {
10-
$interfaces = new RegexIterator($list, '/.*?Interface.php$/');
9+
$filesystem->dir(dirname(__DIR__))->lsRecursive()->then(function (array $list) {
10+
$iterator = new ArrayIterator($list);
11+
$interfaces = new RegexIterator($iterator, '/.*?Interface.php$/');
12+
1113
foreach ($interfaces as $node) {
1214
echo $node->getPath(), PHP_EOL;
1315
}

src/ObjectStreamSink.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ class ObjectStreamSink
1313
public static function promise(ObjectStream $stream)
1414
{
1515
$deferred = new Deferred();
16-
$list = new \SplObjectStorage();
16+
$list = array();
1717

18-
$stream->on('data', function ($object) use ($list) {
19-
$list->attach($object);
18+
$stream->on('data', function ($object) use (&$list) {
19+
$list[] = $object;
2020
});
21-
$stream->on('end', function () use ($deferred, $list) {
21+
$stream->on('end', function () use ($deferred, &$list) {
2222
$deferred->resolve($list);
2323
});
2424

tests/Adapters/DirectoryTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ public function testLs(LoopInterface $loop, FilesystemInterface $filesystem)
2121
$path = $this->tmpDir . 'path';
2222
touch($path);
2323
$listing = $this->await($filesystem->dir($this->tmpDir)->ls(), $loop);
24-
$listing->rewind();
25-
$this->assertSame(1, $listing->count());
26-
$this->assertSame($path, $listing->current()->getPath());
24+
$this->assertSame(1, count($listing));
25+
$this->assertSame($path, reset($listing)->getPath());
2726
}
2827

2928
/**

tests/ChildProcess/AdapterTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,8 @@ public function testLs()
319319
]);
320320

321321
$nodes = $this->await($promise, $loop);
322-
$nodes->rewind();
323322

324-
$this->assertEquals(new File('foo.bar/bar.foo', $fs), $nodes->current());
323+
$this->assertEquals(new File('foo.bar/bar.foo', $fs), reset($nodes));
325324
}
326325

327326
public function testLsStream()

tests/ObjectStreamSinkTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ public function testSink()
1515
$this->assertInstanceOf('React\Promise\PromiseInterface', $sink);
1616
$stream->emit('data', [$node]);
1717
$stream->close();
18+
1819
$nodes = null;
19-
$sink->then(function (\SplObjectStorage $list) use (&$nodes) {
20+
$sink->then(function ($list) use (&$nodes) {
2021
$nodes = $list;
2122
});
22-
$nodes->rewind();
23-
$this->assertSame(1, $nodes->count());
24-
$this->assertSame($node, $nodes->current());
23+
24+
$this->assertSame(1, count($nodes));
25+
$this->assertSame($node, reset($nodes));
2526
}
2627
}

0 commit comments

Comments
 (0)