Exemple #1
0
 /**
  * @param array $node
  * @param ObjectStream $stream
  * @return PromiseInterface
  */
 protected function processLsDent(array $node, ObjectStream $stream)
 {
     $promiseChain = new RejectedPromise();
     foreach ($this->typeDetectors as $detector) {
         $promiseChain = $promiseChain->otherwise(function () use($node, $detector) {
             return $detector->detect($node);
         });
     }
     return $promiseChain->then(function ($callable) use($node, $stream) {
         $stream->emit('data', [$callable($node['path'])]);
     });
 }
Exemple #2
0
 /**
  * @param $sourceStream
  * @return Stream
  */
 protected function processLsRecursiveContents($sourceStream)
 {
     $stream = new ObjectStream();
     $closeCount = 0;
     $sourceStream->on('data', function (NodeInterface $node) use(&$closeCount, $stream) {
         if ($node instanceof Directory || $node instanceof File) {
             $stream->emit('data', [$node]);
         }
         if ($node instanceof Directory) {
             $this->streamLsIntoStream($node, $stream, $closeCount);
         }
     });
     $sourceStream->on('end', function () use(&$closeCount, $stream) {
         $this->adapter->getLoop()->addPeriodicTimer(0.01, function (TimerInterface $timer) use(&$closeCount, $stream) {
             if ($closeCount === 0) {
                 $timer->cancel();
                 $stream->close();
             }
         });
     });
     return $stream;
 }