Skip to content

Update multiple services example #13265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions components/messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ Concepts
both when a message is originally dispatched and again later when a message
is received from a transport,

**Envelope**
**Envelope**:
Messenger specific concept, it gives full flexibility inside the message bus,
by wrapping the messages into it, allowing to add useful information inside
through *envelope stamps*.

**Envelope Stamps**
**Envelope Stamps**:
Piece of information you need to attach to your message: serializer context
to use for transport, markers identifying a received message or any sort of
metadata your middleware or transport layer may use.
Expand Down
2 changes: 1 addition & 1 deletion components/phpunit_bridge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ your application, you can use your own SUT (System Under Test) solver:
</listeners>

The ``My\Namespace\SutSolver::solve`` can be any PHP callable and receives the
current test classname as its first argument.
current test as its first argument.

Finally, the listener can also display warning messages when the SUT solver does
not find the SUT:
Expand Down
24 changes: 14 additions & 10 deletions service_container.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,15 @@ made. To do that, you create a new class::
namespace App\Updates;

use App\Service\MessageGenerator;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;

class SiteUpdateManager
{
private $messageGenerator;
private $mailer;

public function __construct(MessageGenerator $messageGenerator, \Swift_Mailer $mailer)
public function __construct(MessageGenerator $messageGenerator, MailerInterface $mailer)
{
$this->messageGenerator = $messageGenerator;
$this->mailer = $mailer;
Expand All @@ -311,19 +313,21 @@ made. To do that, you create a new class::
{
$happyMessage = $this->messageGenerator->getHappyMessage();

$message = (new \Swift_Message('Site update just happened!'))
->setFrom('admin@example.com')
->setTo('manager@example.com')
->addPart(
'Someone just updated the site. We told them: '.$happyMessage
);
$email = (new Email())
->from('admin@example.com')
->to('manager@example.com')
->subject('Site update just happened!')
->text('Someone just updated the site. We told them: '.$happyMessage);

return $this->mailer->send($message) > 0;
$this->mailer->send($email);

// ...
}
}

This needs the ``MessageGenerator`` *and* the ``Swift_Mailer`` service. That's no
problem! In fact, this new service is ready to be used. In a controller, for example,
This needs the ``MessageGenerator`` *and* the ``Mailer`` service. That's no
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MailerInterface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk, I'm a little sceptical about this change. We call the Mailer service through the MailerInterface no?

Would't this sound better ?

This needs the MessageGenerator and the Mailer service. That's no
problem, we ask them by type-hinting their class and interface names!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds better indeed

problem, we ask them by type hinting their class and interface names!
Now, this new service is ready to be used. In a controller, for example,
you can type-hint the new ``SiteUpdateManager`` class and use it::

// src/Controller/SiteController.php
Expand Down