I have the ff class:
namespace App\Component\Notification\RealTimeNotification;
use App\Component\Notification\NotificationInterface;
class EmailNotification implements NotificationInterface
{
private $logNotification;
private $mailer;
private $engine;
// This will appear on From field on Email.
private $mailerFrom;
public function __construct(LogNotification $logNotification, \Swift_Mailer $mailer, \Twig_Environment $twig, string $from)
{
$this->logNotification = $logNotification;
$this->mailer = $mailer;
$this->twig = $twig;
$this->mailerFrom = $mailerFrom;
}
public function send(array $options): void
{
// Resolve options
$this->resolveOptions($options);
$sendTo = $options['sendTo'];
$subject = $options['subject'];
$template = $options['template'];
$data = $options['data'];
$body = $this->createTemplate($template, $data);
$this->sendEmail($sendTo, $subject, $body);
}
protected function sendEmail($sendTo, $subject, $body): void
{
dump($this->mailerFrom);
$message = (new \Swift_Message())
->setSubject($subject)
->setFrom($this->mailerFrom)
->setTo($sendTo)
->setBody($body, 'text/html')
;
$this->mailer->send($message);
}
protected function createTemplate($template, $data): string
{
return $this->twig->render($template, $data);
}
protected function resolveOptions(array $options): void
{
}
protected function createLog(array $email): void
{
$message = 'Email has been sent to: ' . $email;
$this->logNotification->send([
'message' => $message,
]);
}
}
I tried to manually wire all the arguments with the following:
# Notification
app.log_notification:
class: App\Component\Notification\RealTimeNotification\LogNotification
app.email_notification:
class: App\Component\Notification\RealTimeNotification\EmailNotification
decorates: app.log_notification
decoration_inner_name: app.log_notification.inner
arguments:
$logNotification: '@app.log_notification.inner'
$mailer: '@mailer'
$twig: '@twig'
$from: '%mailer_from%'
However, when I run the app it throws the exception:
Cannot autowire service "App\Component\Notification\RealTimeNotification\EmailNotification": argument "$from" of method "__construct()" must have a type-hint or be given a value explicitly
Why is this event happening?
Thanks!