Skip to content

Commit

Permalink
Use #[Autowire] attribute instead of Yaml config
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored and javiereguiluz committed Dec 1, 2023
1 parent 15962e8 commit 9f906e4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
8 changes: 0 additions & 8 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ services:
bind: # defines the scalar arguments once and apply them to any service defined/created in this file
string $locales: '%app_locales%'
string $defaultLocale: '%locale%'
string $emailSender: '%app.notifications.email_sender%'

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
Expand All @@ -27,10 +26,3 @@ services:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'

# when the service definition only contains arguments, you can omit the
# 'arguments' key and define the arguments just below the service class
App\EventSubscriber\CommentNotificationSubscriber:
$sender: '%app.notifications.email_sender%'

Symfony\Component\Security\Http\Logout\LogoutUrlGenerator: '@security.logout_url_generator'
2 changes: 2 additions & 0 deletions src/Command/ListUsersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;

Expand Down Expand Up @@ -47,6 +48,7 @@ final class ListUsersCommand extends Command
{
public function __construct(
private readonly MailerInterface $mailer,
#[Autowire('%app.notifications.email_sender%')]
private readonly string $emailSender,
private readonly UserRepository $users
) {
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Form\UserType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
Expand Down Expand Up @@ -62,6 +63,7 @@ public function changePassword(
#[CurrentUser] User $user,
Request $request,
EntityManagerInterface $entityManager,
#[Autowire('@security.logout_url_generator')]
LogoutUrlGenerator $logoutUrlGenerator,
): Response {
$form = $this->createForm(ChangePasswordType::class, $user);
Expand Down
2 changes: 2 additions & 0 deletions src/EventSubscriber/CommentNotificationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Entity\Post;
use App\Entity\User;
use App\Event\CommentCreatedEvent;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
Expand All @@ -31,6 +32,7 @@ public function __construct(
private readonly MailerInterface $mailer,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly TranslatorInterface $translator,
#[Autowire('%app.notifications.email_sender%')]
private readonly string $sender
) {
}
Expand Down

0 comments on commit 9f906e4

Please sign in to comment.