From 2a677c440d1efdde2b412613d815ddad5f8ce70b Mon Sep 17 00:00:00 2001 From: David Grudl <david@grudl.com> Date: Tue, 15 Sep 2020 17:10:59 +0200 Subject: [PATCH 1/4] RobotLoader: getRealPath() can return false (in PHAR) --- src/RobotLoader/RobotLoader.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/RobotLoader/RobotLoader.php b/src/RobotLoader/RobotLoader.php index 3f3bfca..7d93240 100644 --- a/src/RobotLoader/RobotLoader.php +++ b/src/RobotLoader/RobotLoader.php @@ -257,11 +257,16 @@ private function createFileIterator(string $dir): Nette\Utils\Finder $iterator = Nette\Utils\Finder::findFiles($acceptFiles) ->filter(function (SplFileInfo $file) use (&$disallow) { - return !isset($disallow[str_replace('\\', '/', $file->getRealPath())]); + return $file->getRealPath() === false + ? true + : !isset($disallow[str_replace('\\', '/', $file->getRealPath())]); }) ->from($dir) ->exclude($ignoreDirs) ->filter($filter = function (SplFileInfo $dir) use (&$disallow) { + if ($dir->getRealPath() === false) { + return true; + } $path = str_replace('\\', '/', $dir->getRealPath()); if (is_file("$path/netterobots.txt")) { foreach (file("$path/netterobots.txt") as $s) { From 5c2cdff58aa9dce082ae59c9b593ee99f03aba33 Mon Sep 17 00:00:00 2001 From: David Grudl <david@grudl.com> Date: Thu, 30 Jul 2020 21:16:17 +0200 Subject: [PATCH 2/4] compatibility with PHP 8.0 --- .travis.yml | 2 ++ composer.json | 2 +- readme.md | 4 +--- src/RobotLoader/RobotLoader.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3a1d7bc..1f0ebb2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ php: - 7.2 - 7.3 - 7.4 + - 8.0snapshot before_install: # turn off XDebug @@ -60,6 +61,7 @@ jobs: allow_failures: - stage: Static Analysis (informative) - stage: Code Coverage + - php: nightly sudo: false diff --git a/composer.json b/composer.json index 9ec736f..b04b159 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.1", + "php": ">=7.1 <8.1", "ext-tokenizer": "*", "nette/finder": "^2.5 || ^3.0", "nette/utils": "^3.0" diff --git a/readme.md b/readme.md index 3904401..f819802 100644 --- a/readme.md +++ b/readme.md @@ -22,8 +22,6 @@ RobotLoader is a tool that gives you comfort of automated class loading for your RobotLoader is incredibly comfortable and addictive! -It requires PHP version 7.1 and supports PHP up to 7.4. - If you like Nette, **[please make a donation now](https://nette.org/donate)**. Thank you! So we can forget about those famous code blocks: @@ -50,7 +48,7 @@ The recommended way to install is via Composer: composer require nette/robot-loader ``` -It requires PHP version 7.1. +It requires PHP version 7.1 and supports PHP up to 8.0. Usage diff --git a/src/RobotLoader/RobotLoader.php b/src/RobotLoader/RobotLoader.php index 7d93240..1b72043 100644 --- a/src/RobotLoader/RobotLoader.php +++ b/src/RobotLoader/RobotLoader.php @@ -338,8 +338,8 @@ private function scanPhp(string $file): array case T_WHITESPACE: continue 2; - case T_NS_SEPARATOR: case T_STRING: + case PHP_VERSION_ID < 80000 ? T_NS_SEPARATOR : T_NAME_QUALIFIED: if ($expected) { $name .= $token[1]; } From cb635b37f24af6334f5d1a2a089906f816245f3c Mon Sep 17 00:00:00 2001 From: David Grudl <david@grudl.com> Date: Sat, 6 Mar 2021 16:49:24 +0100 Subject: [PATCH 3/4] removed workraround for fixed bug --- src/RobotLoader/RobotLoader.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/RobotLoader/RobotLoader.php b/src/RobotLoader/RobotLoader.php index 1b72043..8d56033 100644 --- a/src/RobotLoader/RobotLoader.php +++ b/src/RobotLoader/RobotLoader.php @@ -85,7 +85,6 @@ public function register(bool $prepend = false): self */ public function tryLoad(string $type): void { - $type = ltrim($type, '\\'); // PHP namespace bug #49143 $info = $this->classes[$type] ?? null; if ($this->autoRebuild) { From 067157399d219afd936641512b713bdb12dae40c Mon Sep 17 00:00:00 2001 From: David Grudl <david@grudl.com> Date: Sat, 6 Mar 2021 16:49:44 +0100 Subject: [PATCH 4/4] fixed buggy behavior after 788ab3ec --- src/RobotLoader/RobotLoader.php | 39 +++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/RobotLoader/RobotLoader.php b/src/RobotLoader/RobotLoader.php index 8d56033..36fbd0c 100644 --- a/src/RobotLoader/RobotLoader.php +++ b/src/RobotLoader/RobotLoader.php @@ -85,28 +85,39 @@ public function register(bool $prepend = false): self */ public function tryLoad(string $type): void { + $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) {