-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleConfiguration.php
More file actions
59 lines (52 loc) · 1.75 KB
/
Copy pathModuleConfiguration.php
File metadata and controls
59 lines (52 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
/*
* This file is part of the univeros/framework
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Altair\Module;
use Altair\Configuration\Contracts\ConfigurationInterface;
use Altair\Container\Container;
use Altair\Module\Contracts\ModuleInterface;
use Override;
/**
* Registers a list of modules into the host container.
*
* For each module it (1) binds the instance and tags it {@see self::MODULE_TAG}
* so framework consumers can discover it via `Container::tagged()`, then (2)
* runs the module's own `apply()` to register its service bindings. This is the
* single entry point a host adds to `config/modules.php`:
*
* ```php
* return [
* new Acme\UserManagement\UserManagementModule(),
* ];
* ```
*
* Mirrors {@see \Altair\Configuration\Collection\ConfigurationCollection}; kept
* separate so the module tag and the host-facing "modules" concept have a home.
*/
final readonly class ModuleConfiguration implements ConfigurationInterface
{
/**
* Container tag under which every registered module is discoverable.
*
* Consumers in other packages reference this value (the string literal,
* to avoid a hard dependency on `univeros/module`) when collecting modules.
*/
public const string MODULE_TAG = 'altair.module';
/**
* @param list<ModuleInterface> $modules
*/
public function __construct(private array $modules = []) {}
#[Override]
public function apply(Container $container): void
{
foreach ($this->modules as $module) {
$container->instance($module::class, $module)->tag(self::MODULE_TAG);
$module->apply($container);
}
}
}