Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ List contents
-------------

```php
$filesystem->dir(__DIR__)->ls()->then(function (\SplObjectStorage $list) {
$filesystem->dir(__DIR__)->ls()->then(function (array $list) {
foreach ($list as $node) {
echo $node->getPath(), PHP_EOL;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/directory_create_recursive.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
echo 'Creating directory: ' . $dirName, PHP_EOL;
$dir->createRecursive('rwxrwx---')->then(function () use ($startDir) {
return $startDir->lsRecursive();
})->then(function (\SplObjectStorage $list) {
})->then(function (array $list) {
foreach ($list as $node) {
echo $node->getPath(), PHP_EOL;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/directory_ls.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$filesystem = \React\Filesystem\Filesystem::create($loop);
echo 'Using ', get_class($filesystem->getAdapter()), PHP_EOL;
$filesystem->dir(__DIR__ . DIRECTORY_SEPARATOR . 'tmp')->ls()->then(function (\SplObjectStorage $list) {
$filesystem->dir(__DIR__ . DIRECTORY_SEPARATOR . 'tmp')->ls()->then(function (array $list) {
foreach ($list as $node) {
echo get_class($node), ': ', $node->getPath(), PHP_EOL;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/directory_ls_recursive.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$filesystem = \React\Filesystem\Filesystem::create($loop);
echo 'Using ', get_class($filesystem->getAdapter()), PHP_EOL;
$filesystem->dir(dirname(__DIR__))->lsRecursive()->then(function (\SplObjectStorage $list) {
$filesystem->dir(dirname(__DIR__))->lsRecursive()->then(function (array $list) {
foreach ($list as $node) {
echo $node->getPath(), PHP_EOL;
}
Expand Down
6 changes: 4 additions & 2 deletions examples/directory_ls_recursive_regexp_interfaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

$filesystem = \React\Filesystem\Filesystem::create($loop);
echo 'Using ', get_class($filesystem->getAdapter()), PHP_EOL;
$filesystem->dir(dirname(__DIR__))->lsRecursive()->then(function (\SplObjectStorage $list) {
$interfaces = new RegexIterator($list, '/.*?Interface.php$/');
$filesystem->dir(dirname(__DIR__))->lsRecursive()->then(function (array $list) {
$iterator = new ArrayIterator($list);
$interfaces = new RegexIterator($iterator, '/.*?Interface.php$/');

foreach ($interfaces as $node) {
echo $node->getPath(), PHP_EOL;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ObjectStreamSink.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class ObjectStreamSink
public static function promise(ObjectStream $stream)
{
$deferred = new Deferred();
$list = new \SplObjectStorage();
$list = array();

$stream->on('data', function ($object) use ($list) {
$list->attach($object);
$stream->on('data', function ($object) use (&$list) {
$list[] = $object;
});
$stream->on('end', function () use ($deferred, $list) {
$stream->on('end', function () use ($deferred, &$list) {
$deferred->resolve($list);
});

Expand Down
5 changes: 2 additions & 3 deletions tests/Adapters/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ public function testLs(LoopInterface $loop, FilesystemInterface $filesystem)
$path = $this->tmpDir . 'path';
touch($path);
$listing = $this->await($filesystem->dir($this->tmpDir)->ls(), $loop);
$listing->rewind();
$this->assertSame(1, $listing->count());
$this->assertSame($path, $listing->current()->getPath());
$this->assertSame(1, count($listing));
$this->assertSame($path, reset($listing)->getPath());
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/ChildProcess/AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,8 @@ public function testLs()
]);

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

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

public function testLsStream()
Expand Down
9 changes: 5 additions & 4 deletions tests/ObjectStreamSinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ public function testSink()
$this->assertInstanceOf('React\Promise\PromiseInterface', $sink);
$stream->emit('data', [$node]);
$stream->close();

$nodes = null;
$sink->then(function (\SplObjectStorage $list) use (&$nodes) {
$sink->then(function ($list) use (&$nodes) {
$nodes = $list;
});
$nodes->rewind();
$this->assertSame(1, $nodes->count());
$this->assertSame($node, $nodes->current());

$this->assertSame(1, count($nodes));
$this->assertSame($node, reset($nodes));
}
}