Skip to content

Commit 13aae20

Browse files
authored
Merge pull request #1 from panicdevs/develop
Add 'modules' alias for ModuleService and implement findOrFail method
2 parents 8cc4111 + 1db8075 commit 13aae20

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Providers/ModulesServiceProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function register(): void
3232
$this->app->singleton(ModuleService::class, fn ($app): ModuleService
3333
=> new ModuleService($app->make(ManifestBuilder::class)));
3434

35+
// Bind 'modules' alias for app('modules') access
36+
$this->app->alias(ModuleService::class, 'modules');
37+
3538
// Don't register autoloading here - defer to boot phase
3639
}
3740

src/Services/ModuleService.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ public function find(string $name): ?array
5151
return $modules[$name] ?? null;
5252
}
5353

54+
/**
55+
* Get a specific module by name or throw an exception if not found
56+
*
57+
* @throws \InvalidArgumentException
58+
*/
59+
public function findOrFail(string $name): array
60+
{
61+
$module = $this->find($name);
62+
63+
if (null === $module) {
64+
throw new \InvalidArgumentException("Module '{$name}' not found.");
65+
}
66+
67+
return $module;
68+
}
69+
5470
/**
5571
* Check if a module exists and is enabled
5672
*/

0 commit comments

Comments
 (0)