Skip to content

Commit b29b3db

Browse files
committed
ApplicationExtension & PresenterFactory: used clean way to refresh DI container
1 parent 7312464 commit b29b3db

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/Application/PresenterFactory.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ class PresenterFactory extends Nette\Object implements IPresenterFactory
3232
/** @var Nette\DI\Container */
3333
private $container;
3434

35-
/** @var bool */
36-
private $autoRebuild;
35+
/** @var string */
36+
private $touchToRebuild;
3737

3838

39-
public function __construct(Nette\DI\Container $container, $autoRebuild = FALSE)
39+
public function __construct(Nette\DI\Container $container, $touchToRebuild = NULL)
4040
{
4141
$this->container = $container;
42-
$this->autoRebuild = $autoRebuild;
42+
$this->touchToRebuild = $touchToRebuild;
4343
}
4444

4545

@@ -56,9 +56,8 @@ public function createPresenter($name)
5656
throw new InvalidPresenterException("Multiple services of type $class found: " . implode(', ', $services) . '.');
5757

5858
} elseif (!$services) {
59-
if ($this->autoRebuild) {
60-
$rc = new \ReflectionClass($this->container);
61-
@unlink($rc->getFileName()); // @ file may not exists
59+
if ($this->touchToRebuild) {
60+
touch($this->touchToRebuild);
6261
}
6362

6463
$presenter = $this->container->createInstance($class);

src/Bridges/ApplicationDI/ApplicationExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ public function loadConfiguration()
5656
$application->addSetup('Nette\Bridges\ApplicationTracy\RoutingPanel::initializePanel');
5757
}
5858

59+
$touchToRebuild = $this->debugMode && $config['scanDirs'] ? reset($config['scanDirs']) : NULL;
5960
$presenterFactory = $container->addDefinition($this->prefix('presenterFactory'))
6061
->setClass('Nette\Application\IPresenterFactory')
61-
->setFactory('Nette\Application\PresenterFactory', array(1 => $this->debugMode));
62+
->setFactory('Nette\Application\PresenterFactory', array(1 => $touchToRebuild));
6263

6364
if ($config['mapping']) {
6465
$presenterFactory->addSetup('setMapping', array($config['mapping']));
@@ -116,6 +117,7 @@ private function findPresenters()
116117
$robot->acceptFiles = '*' . $config['scanFilter'] . '*.php';
117118
$robot->rebuild();
118119
$classes = array_keys($robot->getIndexedClasses());
120+
$this->getContainerBuilder()->addDependency(reset($config['scanDirs']));
119121
}
120122

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

0 commit comments

Comments
 (0)