Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions service_container.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,24 @@ you can "ask" for a service from the container by type-hinting an argument with
service's class or interface name. Want to :doc:`log </logging>` something? No problem::

// src/Controller/ProductController.php
// ...
namespace App\Controller;

use Psr\Log\LoggerInterface;

/**
* @Route("/products")
*/
public function list(LoggerInterface $logger)
class ProductController
{
$logger->info('Look! I just used a service');
/**
* @Route("/products")
*/
public function list(LoggerInterface $logger)
{
$logger->info('Look! I just used a service');

// ...
// ...
}
}


What other services are available? Find out by running:

.. code-block:: terminal
Expand Down Expand Up @@ -222,7 +226,7 @@ the ``LoggerInterface`` type-hint. Set this on a new ``$logger`` property
and use it later::

// src/Service/MessageGenerator.php
// ...
namespace App\Service;

use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -550,7 +554,7 @@ Choose a Specific Service
The ``MessageGenerator`` service created earlier requires a ``LoggerInterface`` argument::

// src/Service/MessageGenerator.php
// ...
namespace App\Service;

use Psr\Log\LoggerInterface;

Expand Down