Skip to content

Commit

Permalink
SearchExtension: added 'exclude -> files'
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 21, 2023
1 parent e00a8fc commit 01e5f40
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/DI/Extensions/SearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([]),
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions tests/SearchExtension/files.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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));

0 comments on commit 01e5f40

Please sign in to comment.