Skip to content

Commit 42949e8

Browse files
committed
Documentation
1 parent 3ef74b4 commit 42949e8

File tree

3 files changed

+56
-31
lines changed

3 files changed

+56
-31
lines changed

docs/source/components.rst

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,19 @@
11
Components
22
==========
33

4-
PHP++ id a set of reusable components. You can use all of them of just the one you need.
4+
PHP++ est un ensemble de composants.
55

6-
Contracts components
7-
--------------------
8-
9-
When it's possible, a component has it's counterpart ``-contract`` with only interfaces.
10-
11-
If you don't need to use our implementation of this interfaces
12-
(you just need a typehint, you want to create your own implementation etc),
13-
use the ``-contract`` dependency and work with interfaces.
14-
15-
Example:
16-
17-
.. code-block:: php
18-
:emphasize-lines: 4
19-
20-
<?php
21-
// If you need a StringCollection to work with it,
22-
// don't use StringCollection but StringCollectionInterface
23-
function foo(StringCollectionInterface $strings): void
24-
{
25-
// Do some stuff here with $strings
26-
}
6+
Vous pouvez utiliser chaque composant séparément, aucun composant n'est obligatoire :
7+
c'est à vous de décider d'installer ce dont vous avez besoin !
278

289
Components
2910
----------
3011

31-
+----------------------+--------------------------------------------+
32-
| Component | Description |
33-
+======================+============================================+
34-
| collection | Replace array by a strict typed collection |
35-
+----------------------+--------------------------------------------+
36-
| collection-contracts | Contracts for collection |
37-
+----------------------+--------------------------------------------+
38-
| collection-generator | Helps you to generate a Collection |
39-
+----------------------+--------------------------------------------+
12+
+-------------------------------------------------+----------------------------------------------------------+
13+
| Component | Description |
14+
+=================================================+==========================================================+
15+
| `collection <component/collection/index.html>`_ | Modèle objet pour remlacer ``array`` par une liste typée |
16+
+-------------------------------------------------+----------------------------------------------------------+
4017

4118
Development components
4219
----------------------

docs/source/contracts.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Contracts
2+
---------
3+
4+
Quand c'est possible, un composant n'est qu'une implémentation d'interfaces.
5+
6+
Ces interfaces se trouvent dans un repository qui a le même nom que le composant, avec le suffixe ``-contract``.
7+
8+
Vous pouvez créer votre propre implémentation tant que vous respectez tous les contrats.
9+
10+
Composants avec des contrats
11+
----------------------------
12+
13+
+-------------------------------------------------+-------------------------------------------------------------+
14+
| Composant | Contrat |
15+
+=================================================+=============================================================+
16+
| `collection <component/collection/index.html>`_ | `collection-contract <component/collection/contract.html>`_ |
17+
+-------------------------------------------------+-------------------------------------------------------------+
18+
19+
Example d'utilisation
20+
---------------------
21+
22+
Si vous utilisez le composant `collection <component/collection/index.html>`_,
23+
vous pouvez typer un paramètre avec ``StringCollection``.
24+
25+
Cette façon de typer votre paramètre forcera l'appelant à utiliser
26+
une certaine implémentation du contrat ``StringCollectionInterface``, alors que vous n'avez peut-être pas besoin
27+
de cette implémentation très précisément.
28+
29+
Il vaut alors mieux utiliser ``StringCollectionInterface`` comme typage, pour laisser à l'appelant le choix d'utiliser
30+
l'implémentation qu'il veut.
31+
Dans ce cas, vous pouvez également installer la dépendance
32+
`php-pp/collection-contract <https://github.com/php-pp/collection-contract>`_ et pas
33+
`php-pp/collection <https://github.com/php-pp/collection>`_.
34+
35+
.. code-block:: php
36+
:emphasize-lines: 4
37+
38+
<?php
39+
// Vous forcez l'utilisation de StringCollection
40+
function foo(StringCollection $strings): void
41+
{
42+
}
43+
44+
// Vous laissez le choix à l'appelant d'utiliser l'implémentation qu'il veut
45+
function bar(StringCollectionInterface $strings): void
46+
{
47+
}

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Contents
3434
:hidden:
3535

3636
components
37+
contracts
3738

3839
.. toctree::
3940
:caption: Components

0 commit comments

Comments
 (0)