Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 0a44d0a

Browse files
committed
Overhauled configuration mechanism
Modules now require a composite container factory and can create composite containers. This functionality previously existed in `AbstractBaseModularModule` and has now been shifted to `AbstractBaseModule`. Descendants can now create a composite container and return it from `setup()`. This composite container can contain the config, by attaching two child containers: - one having the service definitions - the other having the config (such as the result of `_loadPhpConfigFile()`) This allows modules to have configuration within their container, which is then attached to a composite container by a parent modular module. Since the top-level composite container is then passed to each module's `run()` method and as the argument for all service definitions, all config is made available via the container's `get()` method.
1 parent 94a59a9 commit 0a44d0a

3 files changed

Lines changed: 59 additions & 89 deletions

File tree

‎src/Module/AbstractBaseModularModule.php‎

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22

33
namespace RebelCode\Modular\Module;
44

5-
use ArrayAccess;
6-
use Dhii\Data\Container\ContainerFactoryInterface;
75
use Dhii\Modular\Module\ModuleInterface;
8-
use Dhii\Util\String\StringableInterface as Stringable;
9-
use Psr\Container\ContainerInterface;
10-
use stdClass;
11-
use Traversable;
126

137
/**
148
* Base functionality for modular modules.it
@@ -24,37 +18,6 @@ abstract class AbstractBaseModularModule extends AbstractBaseModule
2418
*/
2519
use ModularModuleTrait;
2620

27-
/**
28-
* The factory to use for creating composite containers.
29-
*
30-
* @since [*next-version*]
31-
*
32-
* @var ContainerFactoryInterface
33-
*/
34-
protected $compContainerFactory;
35-
36-
/**
37-
* Initializes the modular module with all required information.
38-
*
39-
* @since [*next-version*]
40-
*
41-
* @param ContainerFactoryInterface $compContainerFactory The composite container factory.
42-
* @param ContainerFactoryInterface $containerFactory The container factory.
43-
* @param string|Stringable $key The module key.
44-
* @param string[]|Stringable[] $dependencies The module dependencies.
45-
* @param array|ArrayAccess|stdClass|ContainerInterface $config The module config.
46-
*/
47-
protected function _initModularModule(
48-
ContainerFactoryInterface $compContainerFactory,
49-
ContainerFactoryInterface $containerFactory,
50-
$key,
51-
$dependencies = [],
52-
$config = []
53-
) {
54-
$this->_setCompositeContainerFactory($compContainerFactory);
55-
$this->_initModule($containerFactory, $key, $dependencies, $config);
56-
}
57-
5821
/**
5922
* {@inheritdoc}
6023
*
@@ -64,42 +27,4 @@ protected function _getModuleServiceKey(ModuleInterface $module)
6427
{
6528
return sprintf('%s_module', $module->getKey());
6629
}
67-
68-
/**
69-
* Retrieves the composite container factory associated with this module.
70-
*
71-
* @since [*next-version*]
72-
*
73-
* @return ContainerFactoryInterface The composite container factory instance.
74-
*/
75-
protected function _getCompositeContainerFactory()
76-
{
77-
return $this->compContainerFactory;
78-
}
79-
80-
/**
81-
* Sets the composite container factory for this module.
82-
*
83-
* @since [*next-version*]
84-
*
85-
* @param ContainerFactoryInterface $compContainerFactory The composite container factory instance.
86-
*/
87-
protected function _setCompositeContainerFactory(ContainerFactoryInterface $compContainerFactory)
88-
{
89-
$this->compContainerFactory = $compContainerFactory;
90-
}
91-
92-
/**
93-
* Creates a composite container with the given children container instances.
94-
*
95-
* @since [*next-version*]
96-
*
97-
* @param ContainerInterface[]|Traversable $containers The children container instances.
98-
*
99-
* @return ContainerInterface The created composite container instance.
100-
*/
101-
protected function _createCompositeContainer($containers)
102-
{
103-
return $this->_getCompositeContainerFactory()->make(['containers' => $containers]);
104-
}
10530
}

‎src/Module/AbstractBaseModule.php‎

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use RebelCode\Modular\Events\EventsFunctionalityTrait;
3434
use RuntimeException;
3535
use stdClass;
36+
use Traversable;
3637

3738
/**
3839
* Common base functionality for modules.
@@ -167,22 +168,35 @@ abstract class AbstractBaseModule implements
167168
*/
168169
protected $containerFactory;
169170

171+
/**
172+
* The factory to use for creating composite containers.
173+
*
174+
* @since [*next-version*]
175+
*
176+
* @var ContainerFactoryInterface
177+
*/
178+
protected $compContainerFactory;
179+
170180
/**
171181
* Initializes the module with all required information.
172182
*
173183
* @since [*next-version*]
174184
*
175-
* @param ContainerFactoryInterface|null $containerFactory The container factory, or null.
176-
* @param string|Stringable $key The module key.
177-
* @param string[]|Stringable[] $dependencies The module dependencies.
178-
* @param array|ArrayAccess|stdClass|ContainerInterface $config The module config.
185+
* @param string|Stringable $key The module key.
186+
* @param string[]|Stringable[] $dependencies The module dependencies.
187+
* @param ContainerFactoryInterface $compContainerFactory The composite container factory.
188+
* @param ContainerFactoryInterface $containerFactory The container factory.
179189
*/
180-
protected function _initModule($containerFactory, $key, $dependencies = [], $config = [])
181-
{
190+
protected function _initModule(
191+
$key,
192+
$dependencies = [],
193+
ContainerFactoryInterface $compContainerFactory,
194+
ContainerFactoryInterface $containerFactory
195+
) {
182196
$this->_setKey($key);
183197
$this->_setDependencies($dependencies);
184-
$this->_setConfig($config);
185198
$this->_setContainerFactory($containerFactory);
199+
$this->_setCompositeContainerFactory($compContainerFactory);
186200
}
187201

188202
/**
@@ -232,6 +246,30 @@ protected function _setContainerFactory($containerFactory)
232246
$this->containerFactory = $containerFactory;
233247
}
234248

249+
/**
250+
* Retrieves the composite container factory associated with this module.
251+
*
252+
* @since [*next-version*]
253+
*
254+
* @return ContainerFactoryInterface The composite container factory instance.
255+
*/
256+
protected function _getCompositeContainerFactory()
257+
{
258+
return $this->compContainerFactory;
259+
}
260+
261+
/**
262+
* Sets the composite container factory for this module.
263+
*
264+
* @since [*next-version*]
265+
*
266+
* @param ContainerFactoryInterface $compContainerFactory The composite container factory instance.
267+
*/
268+
protected function _setCompositeContainerFactory(ContainerFactoryInterface $compContainerFactory)
269+
{
270+
$this->compContainerFactory = $compContainerFactory;
271+
}
272+
235273
/**
236274
* Creates a container instance with the given service definitions.
237275
*
@@ -261,6 +299,20 @@ protected function _createContainer($definitions = [], ContainerInterface $paren
261299
return $containerFactory->make(['definitions' => $definitions, 'parent' => $parent]);
262300
}
263301

302+
/**
303+
* Creates a composite container with the given children container instances.
304+
*
305+
* @since [*next-version*]
306+
*
307+
* @param ContainerInterface[]|Traversable $containers The children container instances.
308+
*
309+
* @return ContainerInterface The created composite container instance.
310+
*/
311+
protected function _createCompositeContainer($containers)
312+
{
313+
return $this->_getCompositeContainerFactory()->make(['containers' => $containers]);
314+
}
315+
264316
/**
265317
* Loads a PHP config file and returns the configuration.
266318
*

‎src/Module/ModuleTrait.php‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,4 @@ trait ModuleTrait
2525
* @since [*next-version*]
2626
*/
2727
use DependenciesAwareTrait;
28-
29-
/*
30-
* Provides awareness and storage functionality for a configuration container.
31-
*
32-
* @since [*next-version*]
33-
*/
34-
use ConfigAwareTrait;
3528
}

0 commit comments

Comments
 (0)