-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aeb4053
Fixed CoverageListener usage with custom SUT solver
lyrixx 733aeaf
minor #13251 Fixed CoverageListener usage with custom SUT solver (lyr…
javiereguiluz 00d6407
Merge branch '3.4' into 4.4
javiereguiluz 73e088c
Update messenger.rst
Yohann76 8c8b4c1
minor #13237 Update messenger.rst (Yohann76)
javiereguiluz e55dcad
Update multiple services example
ker0x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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('[email protected]') | ||
->setTo('[email protected]') | ||
->addPart( | ||
'Someone just updated the site. We told them: '.$happyMessage | ||
); | ||
$email = (new Email()) | ||
->from('[email protected]') | ||
->to('[email protected]') | ||
->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 | ||
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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MailerInterface
There was a problem hiding this comment.
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 theMailerInterface
no?Would't this sound better ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds better indeed