Skip to content

Commit 4302b22

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

6 files changed

Lines changed: 56 additions & 14 deletions

File tree

docs/examples/basic.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Basic Usage
33
===========
44

55
Registering and Fetching Services
6-
=================================
6+
---------------------------------
77

88
This example shows how to register and retrieve services using the container helper.
99

@@ -22,7 +22,7 @@ This example shows how to register and retrieve services using the container hel
2222
$pdo = $container->get('pdo');
2323
2424
Using Configuration to Register Providers
25-
========================================
25+
-----------------------------------------
2626

2727
You can use a configuration object to register providers dynamically:
2828

@@ -44,7 +44,7 @@ You can use a configuration object to register providers dynamically:
4444
$cache = $container->get('cache');
4545
4646
Autowiring a Service (using PHP-DI)
47-
===================================
47+
-----------------------------------
4848

4949
The container supports autowiring for classes with type-hinted dependencies:
5050

docs/examples/factories.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Using Factories
33
===============
44

55
Using CallableFactory for Dependency Injection
6-
==============================================
6+
----------------------------------------------
77

88
.. code-block:: php
99
@@ -13,7 +13,7 @@ Using CallableFactory for Dependency Injection
1313
$mailer = $factory($container);
1414
1515
Aliasing Services with AliasFactory
16-
==================================
16+
-----------------------------------
1717

1818
.. code-block:: php
1919
@@ -23,7 +23,7 @@ Aliasing Services with AliasFactory
2323
$sameMailer = $factory($container); // Returns the same as $container->get('mailer')
2424
2525
Invoking Classes with InvokableFactory
26-
=====================================
26+
--------------------------------------
2727

2828
.. code-block:: php
2929
@@ -33,7 +33,7 @@ Invoking Classes with InvokableFactory
3333
$service = $factory($container);
3434
3535
Calling Static Methods with MethodFactory
36-
========================================
36+
-----------------------------------------
3737

3838
.. code-block:: php
3939
@@ -43,7 +43,7 @@ Calling Static Methods with MethodFactory
4343
$service = $factory($container);
4444
4545
Wrapping Existing Instances with ServiceFactory
46-
==============================================
46+
-----------------------------------------------
4747

4848
.. code-block:: php
4949

docs/examples/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ Examples
66

77
basic
88
providers
9+
providers-testing
10+
providers-feature-toggle
911
factories
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Runtime Feature Toggle
2+
=====================
3+
4+
This example demonstrates how to use providers to enable or disable features at runtime.
5+
6+
.. code-block:: php
7+
8+
use FastForward\Container\ServiceProvider\ArrayServiceProvider;
9+
use FastForward\Container\container;
10+
11+
$featureEnabled = true;
12+
13+
$provider = new ArrayServiceProvider([
14+
'feature' => fn() => $featureEnabled ? new RealFeature() : new NullFeature(),
15+
]);
16+
17+
$container = container($provider);
18+
$feature = $container->get('feature');
19+
$feature->run();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Testing with Providers
2+
====================
3+
4+
This example shows how to use providers to swap implementations for testing.
5+
6+
.. code-block:: php
7+
8+
use FastForward\Container\ServiceProvider\ArrayServiceProvider;
9+
use FastForward\Container\container;
10+
11+
class DummyMailer {
12+
public function send($to, $msg) { /* test logic */ }
13+
}
14+
15+
$testProvider = new ArrayServiceProvider([
16+
'mailer' => fn() => new DummyMailer(),
17+
]);
18+
19+
$container = container($testProvider);
20+
$mailer = $container->get('mailer');
21+
$mailer->send('test@example.com', 'Hello!');

docs/examples/providers.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Registering Providers
22
=====================
33

44
Registering Multiple Providers
5-
=============================
5+
------------------------------
66

77
.. code-block:: php
88
@@ -22,7 +22,7 @@ Registering Multiple Providers
2222
$notifier = $container->get('notifier');
2323
2424
Extending Services with Providers
25-
=================================
25+
---------------------------------
2626

2727
.. code-block:: php
2828
@@ -47,7 +47,7 @@ Extending Services with Providers
4747
$repo = $container->get('user_repo');
4848
4949
Composing Providers for Feature Modules
50-
======================================
50+
---------------------------------------
5151

5252
.. code-block:: php
5353
@@ -70,7 +70,7 @@ Composing Providers for Feature Modules
7070
7171
7272
Using Providers with Config
73-
==========================
73+
---------------------------
7474

7575
.. code-block:: php
7676
@@ -94,7 +94,7 @@ Using Providers with Config
9494
9595
9696
Provider Returning a Factory
97-
===========================
97+
----------------------------
9898

9999
.. code-block:: php
100100
@@ -111,7 +111,7 @@ Provider Returning a Factory
111111
112112
113113
Provider with Extension for Caching
114-
==================================
114+
-----------------------------------
115115

116116
.. code-block:: php
117117

0 commit comments

Comments
 (0)