Skip to content

Commit de33ae3

Browse files
committed
ApplicationExtension: option 'scanFilter' changed to pattern, default is '*Presenter'
1 parent c6ca4af commit de33ae3

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/Bridges/ApplicationDI/ApplicationExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getConfigSchema(): Nette\Schema\Schema
6060
'mapping' => Expect::arrayOf('string|array'),
6161
'scanDirs' => Expect::anyOf(Expect::arrayOf('string'), false)->default($this->scanDirs),
6262
'scanComposer' => Expect::bool(class_exists(ClassLoader::class)),
63-
'scanFilter' => Expect::string('Presenter'),
63+
'scanFilter' => Expect::string('*Presenter'),
6464
'silentLinks' => Expect::bool(),
6565
]);
6666
}
@@ -156,7 +156,7 @@ private function findPresenters(): array
156156
}
157157
$robot = new Nette\Loaders\RobotLoader;
158158
$robot->addDirectory(...$config->scanDirs);
159-
$robot->acceptFiles = ['*' . $config->scanFilter . '*.php'];
159+
$robot->acceptFiles = [$config->scanFilter . '.php'];
160160
if ($this->tempDir) {
161161
$robot->setTempDirectory($this->tempDir);
162162
$robot->refresh();
@@ -188,7 +188,7 @@ private function findPresenters(): array
188188
$presenters = [];
189189
foreach (array_unique($classes) as $class) {
190190
if (
191-
strpos($class, $config->scanFilter) !== false
191+
fnmatch($config->scanFilter, $class)
192192
&& class_exists($class)
193193
&& ($rc = new \ReflectionClass($class))
194194
&& $rc->implementsInterface(Nette\Application\IPresenter::class)

tests/Bridges.DI/ApplicationExtension.scan.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ test('', function () {
4040
$code = $compiler->addConfig([
4141
'application' => [
4242
'scanDirs' => [__DIR__ . '/files'],
43+
'scanFilter' => '*Presenter*',
4344
],
4445
])->setClassName('Container2')->compile();
4546
eval($code);
@@ -61,6 +62,9 @@ test('', function () {
6162
$builder->addDefinition('myHttpResponse')->setFactory(Nette\Http\Response::class);
6263
$loader = new DI\Config\Loader;
6364
$config = $loader->load(Tester\FileMock::create('
65+
application:
66+
scanFilter: *Presenter*
67+
6468
services:
6569
-
6670
factory: Presenter1

0 commit comments

Comments
 (0)