Skip to content

Commit 8fb8451

Browse files
committed
Update docs
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent 4b9d289 commit 8fb8451

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

docs/advanced/built-in-containers.rst

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,41 @@ Wraps a ServiceProviderInterface and exposes its factories and extensions as a P
4343
4444
ConfigContainer
4545
---------------
46-
Wraps a ConfigInterface and exposes its configuration as services in a PSR-11 container. Useful for integrating configuration-driven service definitions.
46+
47+
**Note:** ConfigContainer is part of the `fast-forward/config` library, not this package. It is fully compatible and can be used together with FastForward Container.
48+
49+
ConfigContainer wraps any object implementing ``ConfigInterface`` and exposes its configuration as services in a PSR-11 container. The config object must implement the methods ``has($key)`` and ``get($key)``, where keys use dot notation for nested access (e.g., ``'database.host'``).
50+
51+
Example:
4752

4853
.. code-block:: php
4954
55+
use FastForward\Config\ArrayConfig;
5056
use FastForward\Config\Container\ConfigContainer;
57+
58+
$config = new ArrayConfig([
59+
'app' => [
60+
'env' => 'dev',
61+
'db' => [
62+
'host' => 'localhost',
63+
'port' => 3306,
64+
],
65+
],
66+
]);
67+
5168
$container = new ConfigContainer($config);
5269
70+
// Access config values as services:
71+
$env = $container->get('config.app.env'); // 'dev'
72+
$host = $container->get('config.app.db.host'); // 'localhost'
73+
74+
The config object must support:
75+
76+
- ``$config->has('app.db.host')`` // returns true
77+
- ``$config->get('app.db.host')`` // returns 'localhost'
78+
79+
This allows you to use configuration-driven service definitions and inject config values as services in your container setup.
80+
5381
Composing Containers
5482
--------------------
5583
You can freely compose these containers. For example, you can wrap an AggregateContainer with an AutowireContainer, or use ServiceProviderContainer inside an AggregateContainer. The ``container()`` helper does this automatically for you.

docs/advanced/container-helper.rst

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,35 @@ Error Handling
8585

8686
If you pass an unsupported type, or a string that does not correspond to a valid class, the function will throw an InvalidArgumentException.
8787

88-
Advanced: Nested Config Initializers
89-
------------------------------------
9088

91-
If you use a ConfigContainer, it may provide a special config key (``ConfigContainer::ALIAS.ContainerInterface::class``) containing additional initializers. These will be resolved and appended automatically. This allows for advanced, modular configuration setups.
89+
Advanced: Using Config to Register Providers
90+
--------------------------------------------
91+
92+
If you use a ConfigContainer (from the `fast-forward/config` library), it can provide a special config key (``ConfigContainer::ALIAS.ContainerInterface::class``) containing an array of service providers or containers. The container() helper will automatically resolve and append each of these to the AggregateContainer.
93+
94+
This allows you to register providers or containers via configuration, making your setup more modular and dynamic.
95+
96+
Example:
97+
98+
.. code-block:: php
99+
100+
use FastForward\Config\ArrayConfig;
101+
use FastForward\Container\ServiceProvider\ArrayServiceProvider;
102+
use FastForward\Container\container;
103+
use FastForward\Container\ContainerInterface;
104+
105+
$config = new ArrayConfig([
106+
ContainerInterface::class => [
107+
new ArrayServiceProvider([
108+
'foo' => fn() => 'bar',
109+
]),
110+
],
111+
]);
112+
113+
$container = container($config);
114+
$foo = $container->get('foo'); // 'bar'
115+
116+
In this example, the config provides the special key for providers (using the fully qualified class name as the key). The container() helper will extract and register all providers listed there, just as if you had passed them directly.
92117

93118
Return Value
94119
------------

0 commit comments

Comments
 (0)