Skip to content

Commit 0bd4dcf

Browse files
committed
Add discovery config
1 parent 215671f commit 0bd4dcf

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Tempest\Core\DiscoveryConfig;
6+
7+
return new DiscoveryConfig();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Tempest\Core;
4+
5+
final class DiscoveryConfig
6+
{
7+
public function __construct(
8+
public array $skipDiscovery = [],
9+
) {}
10+
11+
public function shouldBeSkipped(string $pathOrClassName): bool
12+
{
13+
return in_array($pathOrClassName, $this->skipDiscovery);
14+
}
15+
}

packages/core/src/Kernel/LoadDiscoveryClasses.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Tempest\Cache\DiscoveryCacheStrategy;
1212
use Tempest\Container\Container;
1313
use Tempest\Core\DiscoveryCache;
14+
use Tempest\Core\DiscoveryConfig;
1415
use Tempest\Core\DiscoveryDiscovery;
1516
use Tempest\Core\Kernel;
1617
use Tempest\Discovery\DiscoversPath;
@@ -21,6 +22,8 @@
2122
use Tempest\Reflection\ClassReflector;
2223
use Throwable;
2324

25+
use function Tempest\Support\Arr\contains;
26+
2427
/** @internal */
2528
final class LoadDiscoveryClasses
2629
{
@@ -29,6 +32,7 @@ final class LoadDiscoveryClasses
2932
public function __construct(
3033
private readonly Kernel $kernel,
3134
private readonly Container $container,
35+
private readonly DiscoveryConfig $discoveryConfig,
3236
private readonly DiscoveryCache $discoveryCache,
3337
) {}
3438

@@ -114,6 +118,10 @@ private function buildDiscovery(string $discoveryClass): Discovery
114118

115119
$input = $file->getPathname();
116120

121+
if ($this->discoveryConfig->shouldBeSkipped($input)) {
122+
continue;
123+
}
124+
117125
// We assume that any PHP file that starts with an uppercase letter will be a class
118126
if ($file->getExtension() === 'php' && ucfirst($fileName) === $fileName) {
119127
$className = $location->toClassName($file->getPathname());
@@ -165,6 +173,10 @@ private function applyDiscovery(Discovery $discovery): void
165173
*/
166174
private function shouldSkipDiscoveryForClass(Discovery $discovery, ClassReflector $input): bool
167175
{
176+
if ($this->discoveryConfig->shouldBeSkipped($input->getName())) {
177+
return true;
178+
}
179+
168180
$attribute = $input->getAttribute(SkipDiscovery::class);
169181

170182
if ($attribute === null) {

0 commit comments

Comments
 (0)