Created
September 17, 2014 20:25
-
-
Save WyriHaximus/bfbfa48602d11832a48b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected $recursiveInvoker; | |
protected function getRecursiveInvoker() { | |
if ($this->recursiveInvoker instanceof RecursiveInvoker) { | |
return $this->recursiveInvoker; | |
} | |
$this->recursiveInvoker = new RecursiveInvoker($this); | |
return $this->recursiveInvoker; | |
} | |
public function chownRecursive($uid = -1, $gid = -1) { | |
return $this->getRecursiveInvoker('chown', $uid, $gid); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace React\Filesystem; | |
class RecursiveInvoker { | |
protected $node; | |
public function __construct(Directory $node) { | |
$this->node = $node; | |
} | |
public function execute($method, $args) { | |
$deferred = new Deferred(); | |
$this->ls()->then(function($list) use ($deferred, $method, $args) { | |
$this->filesystem->getLoop()->futureTick(function() use ($list, $deferred, $method, $args) { | |
$this->iterateNode($list, $deferred, $method, $args); | |
}); | |
}); | |
return $deferred->promise(); | |
} | |
protected function iterateNode($list, $deferred, $method, $args) { | |
$promises = []; | |
foreach ($list as $node) { | |
if ($node instanceof Directory) { | |
$promises[] = call_user_func_array([$node, $method . 'Recursive'], $args); | |
} else { | |
$promises[] = call_user_func_array([$node, $method], $args); | |
} | |
} | |
\React\Promise\all($promises)->then(function() use ($deferred, $method, $args) { | |
call_user_func_array([$this, $method], $args)->then(function() use ($deferred) { | |
$deferred->resolve(); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment