Skip to content

Commit

Permalink
ApplicationExtension: uses external RobotLoader, 'scanDir' is depreca…
Browse files Browse the repository at this point in the history
…ted [Closes #227]
  • Loading branch information
dg committed Aug 15, 2019
1 parent af851cb commit 9483f43
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"mockery/mockery": "^1.0"
},
"conflict": {
"nette/bootstrap": "<3.0.1",
"nette/di": "<3.0-stable",
"nette/forms": "<3.0",
"nette/latte": "<3.0"
Expand Down
30 changes: 11 additions & 19 deletions src/Bridges/ApplicationDI/ApplicationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ final class ApplicationExtension extends Nette\DI\CompilerExtension
/** @var bool */
private $debugMode;

/** @var array */
private $scanDirs;
/** @var Nette\Loaders\RobotLoader|null */
private $robotLoader;

/** @var int */
private $invalidLinkMode;
Expand All @@ -35,10 +35,10 @@ final class ApplicationExtension extends Nette\DI\CompilerExtension
private $tempDir;


public function __construct(bool $debugMode = false, array $scanDirs = null, string $tempDir = null)
public function __construct(bool $debugMode = false, Nette\Loaders\RobotLoader $robotLoader = null, string $tempDir = null)
{
$this->debugMode = $debugMode;
$this->scanDirs = (array) $scanDirs;
$this->robotLoader = $robotLoader;
$this->tempDir = $tempDir;
}

Expand All @@ -50,7 +50,7 @@ public function getConfigSchema(): Nette\Schema\Schema
'errorPresenter' => Expect::string('Nette:Error')->dynamic(),
'catchExceptions' => Expect::bool(!$this->debugMode)->dynamic(),
'mapping' => Expect::arrayOf('string|array'),
'scanDirs' => Expect::anyOf(Expect::arrayOf('string'), false)->default($this->scanDirs),
'scanDirs' => Expect::anyOf(Expect::arrayOf('string'), false), // deprecated
'scanComposer' => Expect::bool(class_exists(ClassLoader::class)),
'scanFilter' => Expect::string('Presenter'),
'silentLinks' => Expect::bool(),
Expand Down Expand Up @@ -78,7 +78,7 @@ public function loadConfiguration()
}
$this->compiler->addExportedType(Nette\Application\Application::class);

$touch = $this->debugMode && $config->scanDirs && $this->tempDir ? $this->tempDir . '/touch' : null;
$touch = $this->debugMode && $this->robotLoader && $this->tempDir ? $this->tempDir . '/touch' : null;
$presenterFactory = $builder->addDefinition($this->prefix('presenterFactory'))
->setType(Nette\Application\IPresenterFactory::class)
->setFactory(Nette\Application\PresenterFactory::class, [new Definitions\Statement(
Expand Down Expand Up @@ -136,19 +136,11 @@ private function findPresenters(): array
$classes = [];

if ($config->scanDirs) {
if (!class_exists(Nette\Loaders\RobotLoader::class)) {
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->acceptFiles = ['*' . $config->scanFilter . '*.php'];
if ($this->tempDir) {
$robot->setTempDirectory($this->tempDir);
$robot->refresh();
} else {
$robot->rebuild();
}
$classes = array_keys($robot->getIndexedClasses());
trigger_error("Option 'scanDir' has no effect and is deprecated.", E_USER_DEPRECATED);
}

if ($this->robotLoader) {
$classes = array_keys($this->robotLoader->getIndexedClasses());
$this->getContainerBuilder()->addDependency($this->tempDir . '/touch');
}

Expand Down

0 comments on commit 9483f43

Please # to comment.