public function testObjectStream()
 {
     $node = $this->getMock('React\\Filesystem\\Node\\NodeInterface');
     $stream = new ObjectStream();
     $this->assertTrue($stream->isWritable());
     $this->assertTrue($stream->isReadable());
     $stream->on('data', function (NodeInterface $data) use($node) {
         $this->assertEquals($node, $data);
     });
     $stream->end($node);
     $this->assertFalse($stream->isWritable());
     $this->assertFalse($stream->isReadable());
     $stream->close();
     $this->assertFalse($stream->isWritable());
     $this->assertFalse($stream->isReadable());
 }
 protected function processLsContents($result, ObjectStream $stream)
 {
     $promises = [];
     foreach ($result as $entry) {
         $node = ['path' => $entry['path'], 'type' => $entry['type']];
         $promises[] = \React\Filesystem\detectType($this->typeDetectors, $node)->then(function (NodeInterface $node) use($stream) {
             $stream->write($node);
             return new FulfilledPromise();
         });
     }
     \React\Promise\all($promises)->then(function () use($stream) {
         $stream->close();
     });
 }
Esempio n. 3
0
 /**
  * @param $basePath
  * @param $result
  * @param ObjectStream $stream
  */
 protected function processLsContents($basePath, $result, ObjectStream $stream)
 {
     if (!isset($result['dents'])) {
         $stream->close();
         return;
     }
     $promises = [];
     foreach ($result['dents'] as $entry) {
         $path = $basePath . DIRECTORY_SEPARATOR . $entry['name'];
         $node = ['path' => $path, 'type' => $entry['type']];
         $promises[] = $this->processLsDent($node, $stream);
     }
     \React\Promise\all($promises)->then(function () use($stream) {
         $stream->close();
     });
 }