@@ -51,6 +51,9 @@ class RobotLoader
5151 /** @var array of class => [file, time] */
5252 private $ classes = [];
5353
54+ /** @var bool */
55+ private $ cacheLoaded = false ;
56+
5457 /** @var bool */
5558 private $ refreshed = false ;
5659
@@ -74,7 +77,6 @@ public function __construct()
7477 */
7578 public function register (bool $ prepend = false ): self
7679 {
77- $ this ->loadCache ();
7880 spl_autoload_register ([$ this , 'tryLoad ' ], true , $ prepend );
7981 return $ this ;
8082 }
@@ -85,6 +87,7 @@ public function register(bool $prepend = false): self
8587 */
8688 public function tryLoad (string $ type ): void
8789 {
90+ $ this ->loadCache ();
8891 $ type = ltrim ($ type , '\\' ); // PHP namespace bug #49143
8992 $ info = $ this ->classes [$ type ] ?? null ;
9093
@@ -158,6 +161,7 @@ public function excludeDirectory(...$paths): self
158161 */
159162 public function getIndexedClasses (): array
160163 {
164+ $ this ->loadCache ();
161165 $ res = [];
162166 foreach ($ this ->classes as $ class => $ info ) {
163167 $ res [$ class ] = $ info ['file ' ];
@@ -171,6 +175,7 @@ public function getIndexedClasses(): array
171175 */
172176 public function rebuild (): void
173177 {
178+ $ this ->cacheLoaded = true ;
174179 $ this ->classes = $ this ->missing = [];
175180 $ this ->refreshClasses ();
176181 if ($ this ->tempDirectory ) {
@@ -410,6 +415,11 @@ public function setTempDirectory(string $dir): self
410415 */
411416 private function loadCache (): void
412417 {
418+ if ($ this ->cacheLoaded ) {
419+ return ;
420+ }
421+ $ this ->cacheLoaded = true ;
422+
413423 $ file = $ this ->getCacheFile ();
414424
415425 // Solving atomicity to work everywhere is really pain in the ass.
0 commit comments