Skip to content

Commit c3e0a43

Browse files
committed
ApplicationExtension: enabled cache for RobotLoader
1 parent 34a6417 commit c3e0a43

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"nette/tester": "^2.0.1",
3030
"nette/di": "^v3.0",
3131
"nette/forms": "^3.0",
32-
"nette/robot-loader": "^3.0",
32+
"nette/robot-loader": "^3.2",
3333
"nette/security": "^3.0",
3434
"latte/latte": "^2.5.1",
3535
"tracy/tracy": "^2.6",

src/Bridges/ApplicationDI/ApplicationExtension.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ final class ApplicationExtension extends Nette\DI\CompilerExtension
3737
/** @var int */
3838
private $invalidLinkMode;
3939

40-
/** @var string */
41-
private $tempFile;
40+
/** @var string|null */
41+
private $tempDir;
4242

4343

4444
public function __construct(bool $debugMode = false, array $scanDirs = null, string $tempDir = null)
@@ -48,7 +48,7 @@ public function __construct(bool $debugMode = false, array $scanDirs = null, str
4848
$this->defaults['scanComposer'] = class_exists(ClassLoader::class);
4949
$this->defaults['catchExceptions'] = !$debugMode;
5050
$this->debugMode = $debugMode;
51-
$this->tempFile = $tempDir ? $tempDir . '/' . urlencode(__CLASS__) : null;
51+
$this->tempDir = $tempDir;
5252
}
5353

5454

@@ -71,7 +71,7 @@ public function loadConfiguration()
7171
$application->addSetup([Nette\Bridges\ApplicationTracy\RoutingPanel::class, 'initializePanel']);
7272
}
7373

74-
$touch = $this->debugMode && $config['scanDirs'] ? $this->tempFile : null;
74+
$touch = $this->debugMode && $config['scanDirs'] && $this->tempDir ? $this->tempDir . '/touch' : null;
7575
$presenterFactory = $builder->addDefinition($this->prefix('presenterFactory'))
7676
->setType(Nette\Application\IPresenterFactory::class)
7777
->setFactory(Nette\Application\PresenterFactory::class, [new Nette\DI\Definitions\Statement(
@@ -132,11 +132,16 @@ private function findPresenters(): array
132132
throw new Nette\NotSupportedException("RobotLoader is required to find presenters, install package `nette/robot-loader` or disable option {$this->prefix('scanDirs')}: false");
133133
}
134134
$robot = new Nette\Loaders\RobotLoader;
135-
$robot->addDirectory($config['scanDirs']);
135+
$robot->addDirectory(...$config['scanDirs']);
136136
$robot->acceptFiles = ['*' . $config['scanFilter'] . '*.php'];
137-
$robot->rebuild();
137+
if ($this->tempDir) {
138+
$robot->setTempDirectory($this->tempDir);
139+
$robot->refresh();
140+
} else {
141+
$robot->rebuild();
142+
}
138143
$classes = array_keys($robot->getIndexedClasses());
139-
$this->getContainerBuilder()->addDependency($this->tempFile);
144+
$this->getContainerBuilder()->addDependency($this->tempDir . '/touch');
140145
}
141146

142147
if ($config['scanComposer']) {

0 commit comments

Comments
 (0)