diff --git a/README.md b/README.md index da0e9fa5..ee0ec2b3 100644 --- a/README.md +++ b/README.md @@ -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; } diff --git a/examples/directory_create_recursive.php b/examples/directory_create_recursive.php index 82476cbf..7077617c 100644 --- a/examples/directory_create_recursive.php +++ b/examples/directory_create_recursive.php @@ -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; } diff --git a/examples/directory_ls.php b/examples/directory_ls.php index 21d9609d..593aa2dc 100644 --- a/examples/directory_ls.php +++ b/examples/directory_ls.php @@ -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; } diff --git a/examples/directory_ls_recursive.php b/examples/directory_ls_recursive.php index 3759a405..c9ba1f36 100644 --- a/examples/directory_ls_recursive.php +++ b/examples/directory_ls_recursive.php @@ -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; } diff --git a/examples/directory_ls_recursive_regexp_interfaces.php b/examples/directory_ls_recursive_regexp_interfaces.php index 12e7203f..064ff704 100644 --- a/examples/directory_ls_recursive_regexp_interfaces.php +++ b/examples/directory_ls_recursive_regexp_interfaces.php @@ -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; } diff --git a/src/ObjectStreamSink.php b/src/ObjectStreamSink.php index 6eb90350..74613639 100644 --- a/src/ObjectStreamSink.php +++ b/src/ObjectStreamSink.php @@ -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); }); diff --git a/tests/Adapters/DirectoryTest.php b/tests/Adapters/DirectoryTest.php index d4382357..befb28c1 100644 --- a/tests/Adapters/DirectoryTest.php +++ b/tests/Adapters/DirectoryTest.php @@ -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()); } /** diff --git a/tests/ChildProcess/AdapterTest.php b/tests/ChildProcess/AdapterTest.php index 3835a1d5..9fa07a51 100644 --- a/tests/ChildProcess/AdapterTest.php +++ b/tests/ChildProcess/AdapterTest.php @@ -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() diff --git a/tests/ObjectStreamSinkTest.php b/tests/ObjectStreamSinkTest.php index 079d2aa2..efb0dd4d 100644 --- a/tests/ObjectStreamSinkTest.php +++ b/tests/ObjectStreamSinkTest.php @@ -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)); } }