1111use Tempest \Cache \DiscoveryCacheStrategy ;
1212use Tempest \Container \Container ;
1313use Tempest \Core \DiscoveryCache ;
14+ use Tempest \Core \DiscoveryConfig ;
1415use Tempest \Core \DiscoveryDiscovery ;
1516use Tempest \Core \Kernel ;
1617use Tempest \Discovery \DiscoversPath ;
@@ -29,6 +30,7 @@ final class LoadDiscoveryClasses
2930 public function __construct (
3031 private readonly Kernel $ kernel ,
3132 private readonly Container $ container ,
33+ private readonly DiscoveryConfig $ discoveryConfig ,
3234 private readonly DiscoveryCache $ discoveryCache ,
3335 ) {}
3436
@@ -100,6 +102,7 @@ private function buildDiscovery(string $discoveryClass): Discovery
100102 /** @var SplFileInfo $file */
101103 foreach ($ files as $ file ) {
102104 $ fileName = $ file ->getFilename ();
105+
103106 if ($ fileName === '' ) {
104107 continue ;
105108 }
@@ -112,7 +115,11 @@ private function buildDiscovery(string $discoveryClass): Discovery
112115 continue ;
113116 }
114117
115- $ input = $ file ->getPathname ();
118+ $ input = $ file ->getRealPath ();
119+
120+ if ($ this ->shouldSkipBasedOnConfig ($ input )) {
121+ continue ;
122+ }
116123
117124 // We assume that any PHP file that starts with an uppercase letter will be a class
118125 if ($ file ->getExtension () === 'php ' && ucfirst ($ fileName ) === $ fileName ) {
@@ -131,14 +138,18 @@ private function buildDiscovery(string $discoveryClass): Discovery
131138 }
132139 }
133140
141+ if ($ this ->shouldSkipBasedOnConfig ($ input )) {
142+ continue ;
143+ }
144+
134145 if ($ input instanceof ClassReflector) {
135146 // If the input is a class, we'll call `discover`
136147 if (! $ this ->shouldSkipDiscoveryForClass ($ discovery , $ input )) {
137148 $ discovery ->discover ($ location , $ input );
138149 }
139150 } elseif ($ discovery instanceof DiscoversPath) {
140151 // If the input is NOT a class, AND the discovery class can discover paths, we'll call `discoverPath`
141- $ discovery ->discoverPath ($ location , realpath ( $ input) );
152+ $ discovery ->discoverPath ($ location , $ input );
142153 }
143154 }
144155 }
@@ -160,6 +171,15 @@ private function applyDiscovery(Discovery $discovery): void
160171 $ this ->appliedDiscovery [$ discovery ::class] = true ;
161172 }
162173
174+ private function shouldSkipBasedOnConfig (ClassReflector |string $ input ): bool
175+ {
176+ if ($ input instanceof ClassReflector) {
177+ $ input = $ input ->getName ();
178+ }
179+
180+ return $ this ->discoveryConfig ->shouldSkip ($ input );
181+ }
182+
163183 /**
164184 * Check whether discovery for a specific class should be skipped based on the #[SkipDiscovery] attribute
165185 */
0 commit comments