diff --git a/src/DI/Extensions/SearchExtension.php b/src/DI/Extensions/SearchExtension.php index 6cfa58caf..9c717ca6d 100644 --- a/src/DI/Extensions/SearchExtension.php +++ b/src/DI/Extensions/SearchExtension.php @@ -40,6 +40,7 @@ public function getConfigSchema(): Nette\Schema\Schema 'extends' => Expect::anyOf(Expect::listOf('string'), Expect::string()->castTo('array'))->default([]), 'implements' => Expect::anyOf(Expect::listOf('string'), Expect::string()->castTo('array'))->default([]), 'exclude' => Expect::structure([ + 'files' => Expect::anyOf(Expect::listOf('string'), Expect::string()->castTo('array'))->default([]), 'classes' => Expect::anyOf(Expect::listOf('string'), Expect::string()->castTo('array'))->default([]), 'extends' => Expect::anyOf(Expect::listOf('string'), Expect::string()->castTo('array'))->default([]), 'implements' => Expect::anyOf(Expect::listOf('string'), Expect::string()->castTo('array'))->default([]), @@ -73,15 +74,16 @@ public function loadConfiguration() public function findClasses(\stdClass $config): array { + $exclude = $config->exclude; $robot = new RobotLoader; $robot->setTempDirectory($this->tempDir); $robot->addDirectory($config->in); $robot->acceptFiles = $config->files ?: ['*.php']; + $robot->ignoreDirs = array_merge($robot->ignoreDirs, $exclude->files); $robot->reportParseErrors(false); $robot->refresh(); $classes = array_unique(array_keys($robot->getIndexedClasses())); - $exclude = $config->exclude; $acceptRE = self::buildNameRegexp($config->classes); $rejectRE = self::buildNameRegexp($exclude->classes); $acceptParent = array_merge($config->extends, $config->implements); diff --git a/tests/SearchExtension/files.phpt b/tests/SearchExtension/files.phpt index 47da5db92..de56a95af 100644 --- a/tests/SearchExtension/files.phpt +++ b/tests/SearchExtension/files.phpt @@ -61,3 +61,22 @@ Assert::same([ 'Foo\\ClassBar', 'InterfaceOk1', ], array_keys($services)); + + + +$services = check(' +search: + in: fixtures + exclude: + files: + - Foo*.* + - ./subdir/* +'); + +Assert::same([ + 'ClassOk1', + 'ClassOk2', + 'CountableClass', + 'ExtendsStdClass', + 'InterfaceOk1', +], array_keys($services));