Skip to content

Commit 8cd3f23

Browse files
committed
ApplicationExtension: option 'scanFilter' changed to pattern, default is '*Presenter'
1 parent 2fa7ff4 commit 8cd3f23

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
@@ -56,7 +56,7 @@ public function getConfigSchema(): Nette\Schema\Schema
5656
'mapping' => Expect::arrayOf('string|array'),
5757
'scanDirs' => Expect::anyOf(Expect::arrayOf('string'), false)->default($this->scanDirs),
5858
'scanComposer' => Expect::bool(class_exists(ClassLoader::class)),
59-
'scanFilter' => Expect::string('Presenter'),
59+
'scanFilter' => Expect::string('*Presenter'),
6060
'silentLinks' => Expect::bool(),
6161
]);
6262
}
@@ -151,7 +151,7 @@ private function findPresenters(): array
151151
}
152152
$robot = new Nette\Loaders\RobotLoader;
153153
$robot->addDirectory(...$config->scanDirs);
154-
$robot->acceptFiles = ['*' . $config->scanFilter . '*.php'];
154+
$robot->acceptFiles = [$config->scanFilter . '.php'];
155155
if ($this->tempDir) {
156156
$robot->setTempDirectory($this->tempDir);
157157
$robot->refresh();
@@ -183,7 +183,7 @@ private function findPresenters(): array
183183
$presenters = [];
184184
foreach (array_unique($classes) as $class) {
185185
if (
186-
strpos($class, $config->scanFilter) !== false
186+
fnmatch($config->scanFilter, $class)
187187
&& class_exists($class)
188188
&& ($rc = new \ReflectionClass($class))
189189
&& $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)