Skip to content

Commit 75d3e1c

Browse files
committed
Update docs
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent bf8f2ec commit 75d3e1c

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

docs/examples/providers.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,72 @@ Composing Providers for Feature Modules
6464
6565
$aggregate = new AggregateServiceProvider($userProvider, $authProvider);
6666
$container = container($aggregate);
67+
6768
$userService = $container->get('user_service');
6869
$authService = $container->get('auth_service');
70+
71+
72+
Using Providers with Config
73+
==========================
74+
75+
.. code-block:: php
76+
77+
use FastForward\Config\ArrayConfig;
78+
use FastForward\Container\container;
79+
use FastForward\Container\ServiceProvider\ArrayServiceProvider;
80+
81+
$config = new ArrayConfig([
82+
FastForward\Container\ContainerInterface::class => [
83+
new ArrayServiceProvider([
84+
'settings' => fn() => [
85+
'debug' => true,
86+
'timezone' => 'UTC',
87+
],
88+
]),
89+
],
90+
]);
91+
92+
$container = container($config);
93+
$settings = $container->get('settings');
94+
95+
96+
Provider Returning a Factory
97+
===========================
98+
99+
.. code-block:: php
100+
101+
use FastForward\Container\ServiceProvider\ArrayServiceProvider;
102+
use FastForward\Container\Factory\InvokableFactory;
103+
use FastForward\Container\container;
104+
105+
$provider = new ArrayServiceProvider([
106+
'service' => new InvokableFactory(MyService::class, 'arg1'),
107+
]);
108+
109+
$container = container($provider);
110+
$service = $container->get('service');
111+
112+
113+
Provider with Extension for Caching
114+
==================================
115+
116+
.. code-block:: php
117+
118+
use FastForward\Container\ServiceProvider\ArrayServiceProvider;
119+
use FastForward\Container\container;
120+
121+
class Cache {
122+
public function enable() { /* ... */ }
123+
}
124+
125+
$provider = new ArrayServiceProvider([
126+
'cache' => fn() => new Cache(),
127+
], [
128+
'cache' => function ($container, $cache) {
129+
$cache->enable();
130+
return $cache;
131+
},
132+
]);
133+
134+
$container = container($provider);
135+
$cache = $container->get('cache');

0 commit comments

Comments
 (0)