11Example: Before/After showcase
22============================================================
33
4- .. note ::
5- | The code involved in this example is part of the test suite of **Yokai Batch**.
6- | You can find the original code in the source repository:
7- `Data <https://github.com/yokai-php/batch-src/tree/0.x/tests/symfony/data/star-wars>`__,
8- `Entities <https://github.com/yokai-php/batch-src/tree/0.x/tests/symfony/src/Entity/StarWars>`__,
9- `Jobs <https://github.com/yokai-php/batch-src/tree/0.x/tests/symfony/src/Job/StarWars>`__,
10- `Tests <https://github.com/yokai-php/batch-src/blob/0.x/tests/symfony/tests/StarWarsJobSet.php>`__
4+ | This documentation will help you understand the difference between a classic code you could write.
5+ | Versus a code that had been written using ``yokai/batch`` library.
6+
117
128What are we trying to do?
139------------------------------------------------------------
1410
15- We have a ``jsonl `` file, containing data that we want to import in our database.
11+ We have a ``jsonl `` file, containing data that we want, and we must import it in our database, via `` doctrine/orm `` .
1612
1713.. code-block :: jsonl
1814
@@ -21,11 +17,14 @@ We have a ``jsonl`` file, containing data that we want to import in our database
2117 {"code":"headphones","attributes":["description","headphone_connectivity","name","picture","power_requirements","price","release_date","sku","snr","thd","weight"],"attribute_as_label":"name","attribute_as_image":"picture","labels":{"en_US":"Headphones","fr_FR":"Casques audio","de_DE":"Kopfh\u00f6rer"}}
2218
2319 .. note ::
24- | todo
20+ | This file is obviously much larger than these 3 lines, you might have thousands lines to process.
21+
2522
2623Before: Without Yokai Batch
2724------------------------------------------------------------
2825
26+ The easiest way to do this is to create the one script you have already written thousands of times:
27+
2928.. literalinclude :: before-after/before.php
3029 :language: php
3130
@@ -35,14 +34,19 @@ Before: Without Yokai Batch
3534 | As your team grow, it will become more important to avoid duplicating things like this.
3635 | Because it is likely that someone will forget one of those little things, code will start acting funny.
3736
37+
3838After: With Yokai Batch
3939------------------------------------------------------------
4040
41+ | Now, using ``yokai/batch``, we will be able to factorize most of this code to show only the business part :
42+
4143.. literalinclude :: before-after/after.php
4244 :language: php
4345
4446.. note ::
45- | todo
47+ | Most of the classes of that snippet are from ``Yokai\Batch`` namespace, you will reuse a lot of those along the way.
48+ | After all, batch processing is almost always the same, the only things that changes are:
4649
47- .. hint ::
48- | todo parler du fait que c'est pas obligé d'avoir un storage, etc...
50+ * the data source you are reading from
51+ * some transformations you are performing on that source
52+ * the data source you are writing to
0 commit comments