/** * {@inheritdoc} */ public function stat($path) { $this->reactor->addRef(); $promisor = new Deferred(); \uv_fs_stat($this->loop, $path, function ($fh, $stat) use($promisor) { if ($fh) { $stat["isdir"] = (bool) ($stat["mode"] & \UV::S_IFDIR); $stat["isfile"] = empty($stat["isdir"]); } else { $stat = null; } $this->reactor->delRef(); $promisor->succeed($stat); }); return $promisor->promise(); }
<?php uv_fs_stat(uv_default_loop(), __FILE__, function ($result, $da) { var_dump($da); }); uv_run();
/** * {@inheritdoc} */ public function stat($path) { if ($stat = StatCache::get($path)) { return new Success($stat); } $this->reactor->addRef(); $promisor = new Deferred(); \uv_fs_stat($this->loop, $path, function ($fh, $stat) use($promisor, $path) { if (empty($fh)) { $stat = null; } else { StatCache::set($path, $stat); } $this->reactor->delRef(); $promisor->succeed($stat); }); return $promisor->promise(); }
/** * @todo * @param string $path * @param callable $callback * @return $this */ public function stat($path, callable $callback = null) { $self = $this; \uv_fs_stat($this->getLoop()->getBackend(), $path, function ($fd) use($callback, $self) { $callback($self, $fd); }); return $this; }