You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced/built-in-containers.rst
+29-1Lines changed: 29 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,13 +43,41 @@ Wraps a ServiceProviderInterface and exposes its factories and extensions as a P
43
43
44
44
ConfigContainer
45
45
---------------
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'``).
This allows you to use configuration-driven service definitions and inject config values as services in your container setup.
80
+
53
81
Composing Containers
54
82
--------------------
55
83
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.
Copy file name to clipboardExpand all lines: docs/advanced/container-helper.rst
+28-3Lines changed: 28 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,10 +85,35 @@ Error Handling
85
85
86
86
If you pass an unsupported type, or a string that does not correspond to a valid class, the function will throw an InvalidArgumentException.
87
87
88
-
Advanced: Nested Config Initializers
89
-
------------------------------------
90
88
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.
0 commit comments