Skip to content

Commit

Permalink
added $topLevelOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 6, 2023
1 parent 9ac9cd8 commit 729684f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/RobotLoader/RobotLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class RobotLoader

/** @var string[] */
public array $acceptFiles = ['*.php'];
public bool $topLevelOnly = true;
private bool $autoRebuild = true;
private bool $reportParseErrors = true;

Expand Down Expand Up @@ -361,7 +362,7 @@ private function scanPhp(string $file): array
$namespace = $name ? $name . '\\' : '';
$minLevel = $token->text === '{' ? 1 : 0;

} elseif ($name && $level === $minLevel) {
} elseif ($name && ($level === $minLevel || !$this->topLevelOnly)) {
$classes[] = $namespace . $name;
}

Expand Down
22 changes: 22 additions & 0 deletions tests/Loaders/RobotLoader.topLevel.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* Test: Nette\Loaders\RobotLoader top level.
*/

declare(strict_types=1);

use Nette\Loaders\RobotLoader;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


$loader = new RobotLoader;
$loader->setTempDirectory(getTempDir());
$loader->topLevelOnly = false;
$loader->addDirectory(__DIR__ . '/files');
$loader->register();

Assert::true(class_exists('ConditionalClass')); // files/conditional.class.php
2 changes: 1 addition & 1 deletion tests/Loaders/files/conditional.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

if (false) {
if (true) {
class ConditionalClass
{
}
Expand Down

0 comments on commit 729684f

Please sign in to comment.