From 9ad3afdd0d2422db7a58aee76e8b3b7a82f31af5 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 6 Mar 2021 16:49:44 +0100 Subject: [PATCH] fixed buggy behavior after 788ab3ec --- src/RobotLoader/RobotLoader.php | 40 +++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/RobotLoader/RobotLoader.php b/src/RobotLoader/RobotLoader.php index 8fb3145..88bcf31 100644 --- a/src/RobotLoader/RobotLoader.php +++ b/src/RobotLoader/RobotLoader.php @@ -88,28 +88,40 @@ public function register(bool $prepend = false): self public function tryLoad(string $type): void { $this->loadCache(); + + $missing = $this->missing[$type] ?? null; + if ($missing >= self::RETRY_LIMIT) { + return; + } + $info = $this->classes[$type] ?? null; if ($this->autoRebuild) { - if (!$info || !is_file($info['file'])) { - $missing = &$this->missing[$type]; - $missing++; - if (!$this->refreshed && $missing <= self::RETRY_LIMIT) { + $save = false; + + if (!$this->refreshed) { + if (!$info || !is_file($info['file'])) { $this->refreshClasses(); - $this->saveCache(); - } elseif ($info) { - unset($this->classes[$type]); - $this->saveCache(); - } + $info = $this->classes[$type] ?? null; + $save = true; - } elseif (!$this->refreshed && filemtime($info['file']) !== $info['time']) { - $this->updateFile($info['file']); - if (empty($this->classes[$type])) { - $this->missing[$type] = 0; + } elseif (filemtime($info['file']) !== $info['time']) { + $this->updateFile($info['file']); + $info = $this->classes[$type] ?? null; + $save = true; } + } + + if (!$info || !is_file($info['file'])) { + $this->missing[$type] = ++$missing; + $save = $save || $info || ($missing <= self::RETRY_LIMIT); + unset($this->classes[$type]); + $info = null; + } + + if ($save) { $this->saveCache(); } - $info = $this->classes[$type] ?? null; } if ($info) {