diff --git a/src/Discoverer.php b/src/Discoverer.php index 06a2d72..e4707d2 100644 --- a/src/Discoverer.php +++ b/src/Discoverer.php @@ -282,7 +282,15 @@ public function getIterator(): Traversable } /** - * Handle dynamic calls to the retrieved classes. + * Handle dynamic property access to the retrieved classes Collection. + */ + public function __get(string $name): mixed + { + return $this->classes()->{$name}; + } + + /** + * Handle dynamic calls to the retrieved classes Collection. */ public function __call(string $name, array $arguments): mixed { diff --git a/tests/DiscoverTest.php b/tests/DiscoverTest.php index c763490..a6e0835 100644 --- a/tests/DiscoverTest.php +++ b/tests/DiscoverTest.php @@ -255,4 +255,18 @@ public function test_iterator_is_collection(): void static::assertInstanceOf(Collection::class, Discover::in('Events')->getIterator()); } + + public function test_forwards_property_access_to_collection(): void + { + $this->mockAllFiles(); + + static::assertInstanceOf(Collection::class, Discover::in('Events')->map->name); + } + + public function test_forwards_call_to_collection(): void + { + $this->mockAllFiles(); + + static::assertInstanceOf(Collection::class, Discover::in('Events')->map(fn($c) => $c->name)); + } }