Skip to content

Commit

Permalink
ApplicationExtension: enabled cache for RobotLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 12, 2019
1 parent bf5d5d1 commit bea304e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"nette/tester": "^2.0.1",
"nette/di": "^v3.0",
"nette/forms": "^3.0",
"nette/robot-loader": "^3.0",
"nette/robot-loader": "^3.2",
"nette/security": "^3.0",
"latte/latte": "^2.5.1",
"tracy/tracy": "^2.6",
Expand Down
19 changes: 12 additions & 7 deletions src/Bridges/ApplicationDI/ApplicationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ final class ApplicationExtension extends Nette\DI\CompilerExtension
/** @var int */
private $invalidLinkMode;

/** @var string */
private $tempFile;
/** @var string|null */
private $tempDir;


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


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

$touch = $this->debugMode && $config['scanDirs'] ? $this->tempFile : null;
$touch = $this->debugMode && $config['scanDirs'] && $this->tempDir ? $this->tempDir . '/touch' : null;
$presenterFactory = $builder->addDefinition($this->prefix('presenterFactory'))
->setType(Nette\Application\IPresenterFactory::class)
->setFactory(Nette\Application\PresenterFactory::class, [new Nette\DI\Definitions\Statement(
Expand Down Expand Up @@ -132,11 +132,16 @@ private function findPresenters(): array
throw new Nette\NotSupportedException("RobotLoader is required to find presenters, install package `nette/robot-loader` or disable option {$this->prefix('scanDirs')}: false");
}
$robot = new Nette\Loaders\RobotLoader;
$robot->addDirectory($config['scanDirs']);
$robot->addDirectory(...$config['scanDirs']);
$robot->acceptFiles = ['*' . $config['scanFilter'] . '*.php'];
$robot->rebuild();
if ($this->tempDir) {
$robot->setTempDirectory($this->tempDir);
$robot->refresh();
} else {
$robot->rebuild();
}
$classes = array_keys($robot->getIndexedClasses());
$this->getContainerBuilder()->addDependency($this->tempFile);
$this->getContainerBuilder()->addDependency($this->tempDir . '/touch');
}

if ($config['scanComposer']) {
Expand Down

0 comments on commit bea304e

Please sign in to comment.