|
21 | 21 | * $loader = new Nette\Loaders\RobotLoader; |
22 | 22 | * $loader->addDirectory('app'); |
23 | 23 | * $loader->excludeDirectory('app/exclude'); |
24 | | - * $loader->setTempDirectory('temp'); |
| 24 | + * $loader->setCacheDirectory('temp'); |
25 | 25 | * $loader->register(); |
26 | 26 | * </code> |
27 | 27 | */ |
@@ -53,7 +53,7 @@ class RobotLoader |
53 | 53 |
|
54 | 54 | /** @var array<string, int> file => mtime */ |
55 | 55 | private array $emptyFiles = []; |
56 | | - private ?string $tempDirectory = null; |
| 56 | + private ?string $cacheDirectory = null; |
57 | 57 | private bool $needSave = false; |
58 | 58 |
|
59 | 59 |
|
@@ -175,7 +175,7 @@ public function rebuild(): void |
175 | 175 | $this->cacheLoaded = true; |
176 | 176 | $this->classes = $this->missingClasses = $this->emptyFiles = []; |
177 | 177 | $this->refreshClasses(); |
178 | | - if ($this->tempDirectory) { |
| 178 | + if ($this->cacheDirectory) { |
179 | 179 | $this->saveCache(); |
180 | 180 | } |
181 | 181 | } |
@@ -390,19 +390,26 @@ public function setAutoRefresh(bool $state = true): static |
390 | 390 |
|
391 | 391 |
|
392 | 392 | /** |
393 | | - * Sets path to temporary directory. |
| 393 | + * Sets the directory for storing cache. |
394 | 394 | */ |
395 | | - public function setTempDirectory(string $dir): static |
| 395 | + public function setCacheDirectory(string $dir): static |
396 | 396 | { |
397 | 397 | if (!FileSystem::isAbsolute($dir)) { |
398 | | - throw new Nette\InvalidArgumentException("Temporary directory must be absolute, '$dir' given."); |
| 398 | + throw new Nette\InvalidArgumentException("Cache directory must be absolute, '$dir' given."); |
399 | 399 | } |
400 | 400 | FileSystem::createDir($dir); |
401 | | - $this->tempDirectory = $dir; |
| 401 | + $this->cacheDirectory = $dir; |
402 | 402 | return $this; |
403 | 403 | } |
404 | 404 |
|
405 | 405 |
|
| 406 | + /** @deprecated use setCacheDirectory() */ |
| 407 | + public function setTempDirectory(string $dir): static |
| 408 | + { |
| 409 | + return $this->setCacheDirectory($dir); |
| 410 | + } |
| 411 | + |
| 412 | + |
406 | 413 | /** |
407 | 414 | * Loads class list from cache. |
408 | 415 | */ |
@@ -499,11 +506,11 @@ private function acquireLock(string $file, int $mode) |
499 | 506 |
|
500 | 507 | private function generateCacheFileName(): string |
501 | 508 | { |
502 | | - if (!$this->tempDirectory) { |
503 | | - throw new \LogicException('Set path to temporary directory using setTempDirectory().'); |
| 509 | + if (!$this->cacheDirectory) { |
| 510 | + throw new \LogicException('Set path to temporary directory using setCacheDirectory().'); |
504 | 511 | } |
505 | 512 |
|
506 | | - return $this->tempDirectory . '/' . hash('xxh128', serialize($this->generateCacheKey())) . '.php'; |
| 513 | + return $this->cacheDirectory . '/' . hash('xxh128', serialize($this->generateCacheKey())) . '.php'; |
507 | 514 | } |
508 | 515 |
|
509 | 516 |
|
|
0 commit comments