From fdaf09d4ae035c7c358163e32c81ebbabde764ac Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 27 Aug 2018 17:24:16 +0200 Subject: [PATCH] Make `NativeShare::getStat` private to avoid confusion with `NativeShare::stat` Closes #72 --- src/Native/NativeFileInfo.php | 20 +++++++++++++++----- src/Native/NativeShare.php | 7 +++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Native/NativeFileInfo.php b/src/Native/NativeFileInfo.php index 3466797..350b8af 100644 --- a/src/Native/NativeFileInfo.php +++ b/src/Native/NativeFileInfo.php @@ -30,7 +30,10 @@ class NativeFileInfo implements IFileInfo { /** * @var array|null */ - protected $statCache; + protected $statCache = null; + + /** @var callable|null */ + protected $statCallback = null; /** * @var int @@ -41,13 +44,20 @@ class NativeFileInfo implements IFileInfo { * @param NativeShare $share * @param string $path * @param string $name - * @param array $stat + * @param array|callable $stat */ - public function __construct($share, $path, $name, $stat = null) { + public function __construct($share, $path, $name, $stat) { $this->share = $share; $this->path = $path; $this->name = $name; - $this->statCache = $stat; + + if (is_array($stat)) { + $this->statCache = $stat; + } else if (is_callable($stat)) { + $this->statCallback = $stat; + } else { + throw new \InvalidArgumentException('$stat needs to be an array or callback'); + } } /** @@ -69,7 +79,7 @@ class NativeFileInfo implements IFileInfo { */ protected function stat() { if (is_null($this->statCache)) { - $this->statCache = $this->share->getStat($this->getPath()); + $this->statCache = call_user_func($this->statCallback); } return $this->statCache; } diff --git a/src/Native/NativeShare.php b/src/Native/NativeShare.php index 1d9d259..3984f00 100644 --- a/src/Native/NativeShare.php +++ b/src/Native/NativeShare.php @@ -93,7 +93,10 @@ class NativeShare extends AbstractShare { while ($file = $this->getState()->readdir($dh)) { $name = $file['name']; if ($name !== '.' and $name !== '..') { - $files [] = new NativeFileInfo($this, $path . '/' . $name, $name); + $fullPath = $path . '/' . $name; + $files [] = new NativeFileInfo($this, $fullPath, $name, function() use ($fullPath) { + return $this->getStat($fullPath); + }); } } @@ -109,7 +112,7 @@ class NativeShare extends AbstractShare { return new NativeFileInfo($this, $path, basename($path), $this->getStat($path)); } - public function getStat($path) { + private function getStat($path) { return $this->getState()->stat($this->buildUrl($path)); }