Skip to content

Commit 1184bf3

Browse files
BooleanTypeLeroid
authored andcommitted
Underline is too long; using DHL and UPS, it’s more international
1 parent 3740648 commit 1184bf3

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

service_container/factories.rst

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,17 @@ previous examples takes the ``templating`` service as an argument:
303303
};
304304
305305
Usage example
306-
--------------------
306+
-------------
307307

308308
The following example is intended to show how to create and use a factory method in Symfony framework.
309-
Suppose you want to realize the factory method pattern for services, that describe two delivery methods - DPD and SmartPost.
309+
Suppose you want to realize the factory method pattern for services, that describe two delivery methods - DHL and UPS.
310310

311311
Services (subclasses) definition::
312312

313-
// src/Deliveries/DPD.php
313+
// src/Deliveries/DHL.php
314314
namespace App\Deliveries;
315315

316-
class DPD
316+
class DHL
317317
{
318318
public $costLabel;
319319
@@ -322,10 +322,10 @@ Services (subclasses) definition::
322322
}
323323
}
324324
325-
// src/Deliveries/SmartPost.php
325+
// src/Deliveries/UPS.php
326326
namespace App\Deliveries;
327327

328-
class SmartPost
328+
class UPS
329329
{
330330
public $costLabel;
331331
@@ -354,7 +354,7 @@ Factory definition::
354354
355355
As you can see, ``DeliveryFactory`` doesn't specify the exact class of the object that will be created.
356356

357-
Next, use settings similar to those in the sections above. These settings allow you to define a factory method for subclasses without explicitly extending the abstract class (i.e., without ``class DPD extends DeliveryFactory``)!
357+
Next, use settings similar to those in the sections above. These settings allow you to define a factory method for subclasses without explicitly extending the abstract class (i.e., without ``class DHL extends DeliveryFactory``)!
358358

359359
.. configuration-block::
360360

@@ -364,14 +364,14 @@ Next, use settings similar to those in the sections above. These settings allow
364364
services:
365365
# ...
366366
367-
App\Deliveries\DPD:
367+
App\Deliveries\DHL:
368368
factory: ['@App\Factories\DeliveryFactory', create]
369369
arguments:
370-
$deliveryMethod: 'App\Deliveries\DPD'
371-
App\Deliveries\SmartPost:
370+
$deliveryMethod: 'App\Deliveries\DHL'
371+
App\Deliveries\UPS:
372372
factory: ['@App\Factories\DeliveryFactory', create]
373373
arguments:
374-
$deliveryMethod: 'App\Deliveries\SmartPost'
374+
$deliveryMethod: 'App\Deliveries\UPS'
375375
376376
377377
.. code-block:: xml
@@ -386,13 +386,13 @@ Next, use settings similar to those in the sections above. These settings allow
386386
<services>
387387
<!-- ... -->
388388
389-
<service id="App\Deliveries\DPD">
389+
<service id="App\Deliveries\DHL">
390390
<factory service="App\Factories\DeliveryFactory" method="create"/>
391-
<argument key="$deliveryMethod">App\Deliveries\DPD</argument>
391+
<argument key="$deliveryMethod">App\Deliveries\DHL</argument>
392392
</service>
393-
<service id="App\Deliveries\SmartPost">
393+
<service id="App\Deliveries\UPS">
394394
<factory service="App\Factories\DeliveryFactory" method="create"/>
395-
<argument key="$deliveryMethod">App\Deliveries\SmartPost</argument>
395+
<argument key="$deliveryMethod">App\Deliveries\UPS</argument>
396396
</service>
397397
</services>
398398
</container>
@@ -402,20 +402,20 @@ Next, use settings similar to those in the sections above. These settings allow
402402
// config/services.php
403403
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
404404
405-
use App\Deliveries\DPD;
406-
use App\Deliveries\SmartPost;
405+
use App\Deliveries\DHL;
406+
use App\Deliveries\UPS;
407407
use App\Factories\DeliveryFactory;
408408
409409
return function(ContainerConfigurator $configurator) {
410410
$services = $configurator->services();
411411
412-
$services->set(DPD::class)
412+
$services->set(DHL::class)
413413
->factory([ref(DeliveryFactory::class), 'create'])
414-
->arg('$deliveryMethod', 'App\Deliveries\DPD')
414+
->arg('$deliveryMethod', 'App\Deliveries\DHL')
415415
;
416-
$services->set(SmartPost::class)
416+
$services->set(UPS::class)
417417
->factory([ref(DeliveryFactory::class), 'create'])
418-
->arg('$deliveryMethod', 'App\Deliveries\SmartPost')
418+
->arg('$deliveryMethod', 'App\Deliveries\UPS')
419419
;
420420
};
421421
@@ -424,13 +424,13 @@ Now we can use our services as usual (via dependency injection). The only differ
424424
/**
425425
* @Route("/get-deliveries-cost", methods={"GET"})
426426
*/
427-
public function getDeliveriesCost(DPD $dpd, SmartPost $smartPost)
427+
public function getDeliveriesCost(DHL $dhl, UPS $ups)
428428
{
429429
// ...
430430
431-
// $dpd->costLabel is fulfilled in factory method.
432-
$dpdCost = $dpd->costLabel . $dpd->cost();
433-
$smartPostCost = $smartPost->costLabel . $smartPost->cost();
431+
// $dhl->costLabel and $ups->costLabel are fulfilled in factory method.
432+
$dhlCost = $dhl->costLabel . $dhl->cost();
433+
$upsCost = $ups->costLabel . $ups->cost();
434434
435435
// ...
436436
}

0 commit comments

Comments
 (0)