@sl1m_dogg

Не загружаются сервисы через [bundle]Extension.php, что делаю не так?

Делал все по симфовским докам. Собственно код:
MailerExtension.php:
<?php

namespace MailerBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class MailerExtension extends Extension
{

    /**
     * Loads a specific configuration.
     *
     * @param array $configs An array of configuration values
     * @param ContainerBuilder $container A ContainerBuilder instance
     *
     * @throws \InvalidArgumentException When provided tag is not defined in this extension
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $container->setDefinition('mailer.emailsender', new Definition('MailerBundle\Sender\EmailSender',[
            new Reference('swiftmailer.mailer'),
            new Reference('swiftmailer.transport'),
            $container->getParameter('mailer_user'),
            $container->getParameter('mailer_password')
        ]));

        $container->setDefinition('mailer.email_controller', new Definition('MailerBundle\Controller\EmailController',[
            new Reference('mailer.emailsender')]));
    }
}


Sender\EmailSender.php:
<?php

namespace MailerBundle\Sender;

use MailerBundle\Entity\Notification;

class EmailSender extends AbstractSender
{
    protected $transport;

    /**
     * EmailSender constructor.
     * @param \Swift_Mailer $mailer
     * @param \Swift_SmtpTransport $smtpTransport
     * @param $name
     * @param $password
     */
    public function __construct(
        \Swift_Mailer $mailer,
        \Swift_SmtpTransport $smtpTransport,
        $name,
        $password
    )
    {
        $transport = $smtpTransport::newInstance('gmail')
            ->setUsername($name)
            ->setPassword($password);

        $this->transport = $mailer::newInstance($transport);
    }


EmailController.php:
<?php

namespace MailerBundle\Controller;

use MailerBundle\Entity\EmailHandler\EmailReceiver;
use MailerBundle\Entity\EmailHandler\EmailSender;
use MailerBundle\Sender\EmailSender as Sender;
use MailerBundle\Entity\Notification;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class EmailController extends Controller
{
    /**
     * @var Sender
     */
    private $sender;

    /**
     * EmailController constructor.
     * @param Sender $sender
     */
    public function __construct(Sender $sender)
    {
        $this->sender = $sender;
    }


При переходе на роут контроллера выдает:
Catchable Fatal Error: Argument 1 passed to MailerBundle\Controller\EmailController::__construct() must be an instance of MailerBundle\Sender\EmailSender, none given, called in C:\xampp1\htdocs\murka.ll\app\cache\dev\classes.php on line 2176 and defined
  • Вопрос задан
  • 239 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы