Symfony:覆盖第三方服务时出错

Symfony:覆盖第三方服务时出错,symfony,service,parameters,arguments,overriding,Symfony,Service,Parameters,Arguments,Overriding,我正在应用程序中使用第三方包进行通知。这一切都很好,但我想覆盖该捆绑包中服务“NotificationManager”的某些部分,以便将通知与电子邮件结合起来 错误 在完成所有操作后,我收到以下错误消息: Type error: Argument 1 passed to Mgilet\NotificationBundle\Twig\NotificationExtension::__construct() must be an instance of Mgilet\NotificationBund

我正在应用程序中使用第三方包进行通知。这一切都很好,但我想覆盖该捆绑包中服务“NotificationManager”的某些部分,以便将通知与电子邮件结合起来

错误 在完成所有操作后,我收到以下错误消息:

Type error: Argument 1 passed to Mgilet\NotificationBundle\Twig\NotificationExtension::__construct() must be an instance of Mgilet\NotificationBundle\Manager\NotificationManager, instance of NewsBundle\Services\NotificationHelper given, called in /srv/http/sp/app/cache/dev/appDevDebugProjectContainer.php on line 4011
我所做的 我遵循Symfony文档并添加了一个编译器类:

    <?php
namespace NewsBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use NewsBundle\Services\NotificationHelper;

class OverrideCompilerPass implements CompilerPassInterface {

  public function process(ContainerBuilder $container)
      {
          $defNewService = $container->getDefinition('mgilet.notification');
          $defNewService->setClass('NewsBundle\Services\NotificationHelper');

      }

}
  ?>
更新

我编辑了services.yml,因此现在只剩下twig_扩展作为服务,因为当我调试mgilet.notification-service时,它已经分配给我的自定义服务类,所以我认为它是一样的

所以现在我的文件中只有这个:

    notification.twig_extension:
      class: NewsBundle\Twig\NotificationExtension
      arguments: ['@mgilet.notification', '@security.token_storage', '@twig']
      public: false
      tags:
          - { name: twig.extension }
调试容器时,它甚至不会显示为服务,但错误消息保持不变:

Type error: Argument 1 passed to Mgilet\NotificationBundle\Twig\NotificationExtension::__construct() must be an instance of Mgilet\NotificationBundle\Manager\NotificationManager, instance of NewsBundle\Services\NotificationHelper given, called in /srv/http/sp/app/cache/dev/appDevDebugProjectContainer.php on line 4000


我认为NotificationExtension需要调用NotificationManager类。您应该从services.yml发送此类。但你要送你的服务课;通知助手。您应该发送添加一个,它是通知管理器类。因此NotificationHelper位于NotificationBundle中

我认为NotificationExtension需要添加到NotificationManager类。您应该从services.yml发送此类。但你要送你的服务课;通知助手。您应该发送添加一个,它是通知管理器类。因此NotificationHelper位于NotificationBundle中

你清除了所有的缓存吗?是的,但是当清除缓存时,我得到了相同的错误。。[Symfony\Component\Debug\Exception\FatalThrowableError]类型错误:传递给Mgilet\NotificationBundle\Twig\NotificationExtension:的参数1::\uu construct()必须是Mgilet\NotificationBundle\Manager\NotificationManager的实例,NewsBundle\Services\NotificationHelper的实例,在第3 998行的/srv/http/sp/app/cache/de\appDevDebugProjectContaine.php中调用。更新服务参数后是否清除缓存?是的,但错误仍然存在:)@sonja你找到解决方法了吗?你清除了所有的缓存吗?是的,但是当清除缓存时,我得到了相同的错误。。[Symfony\Component\Debug\Exception\FatalThrowableError]类型错误:传递给Mgilet\NotificationBundle\Twig\NotificationExtension:的参数1::\uu construct()必须是Mgilet\NotificationBundle\Manager\NotificationManager的实例,NewsBundle\Services\NotificationHelper的实例,在第3 998行的/srv/http/sp/app/cache/de\appDevDebugProjectContaine.php中调用。更新服务参数后是否清除缓存?是的,但错误仍然存在:)@sonja你找到解决方案了吗?对不起,我不太明白你想说什么:/如果你的意思是,我试图发送错误的参数,我已经更改了该参数(请参阅我更新的问题)但仍然是同一个错误..你确实发送了NotificationHelper类,但你应该从services.yml发送NotificationManager类。是的,这就是我的意思,我编辑了它,但你的意思是我也应该在构造函数中调用NotificationManager吗?对不起,我不太明白你想说什么:/如果你的意思是,我试图发送错误的参数,我已经更改了该参数(请参阅更新的问题),但仍然是相同的错误..您确实发送了NotificationHelper类,但您应该从services.yml发送NotificationManager类。是的,这就是我的意思,我编辑了它,但您的意思是我也应该在构造函数中调用NotificationManager吗?
<?php

namespace NewsBundle\Twig;

use Mgilet\NotificationBundle\Twig\NotificationExtension as BaseExtension;
use NewsBundle\Services\NotificationHelper;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Twig_Extension;

class NotificationExtension extends BaseExtension
/**
 * Twig extension to display notifications
 **/
{
    protected $notificationHelper;
    protected $storage;
    protected $twig;

    /**
     * NotificationExtension constructor.
     * @param NotificationHelper $notificationHelper
     * @param TokenStorage $storage
     * @param \Twig_Environment $twig
     */
    public function __construct(NotificationHelper $notificationHelper, TokenStorage $storage, \Twig_Environment $twig)
    {
        $this->notificationHelper = $notificationHelper;
        $this->storage = $storage;
        $this->twig = $twig;
    }
... stuff happening
}
     notification_helper:
      class: NewsBundle\Services\NotificationHelper
      arguments: ['@doctrine.orm.entity_manager', AppBundle\Entity\Notification]

  notification.twig_extension:
          class: NewsBundle\Twig\NotificationExtension
          arguments: ['@notification_helper', '@security.token_storage', '@twig']
          public: false
          tags:
              - { name: twig.extension }
    notification.twig_extension:
      class: NewsBundle\Twig\NotificationExtension
      arguments: ['@mgilet.notification', '@security.token_storage', '@twig']
      public: false
      tags:
          - { name: twig.extension }
Type error: Argument 1 passed to Mgilet\NotificationBundle\Twig\NotificationExtension::__construct() must be an instance of Mgilet\NotificationBundle\Manager\NotificationManager, instance of NewsBundle\Services\NotificationHelper given, called in /srv/http/sp/app/cache/dev/appDevDebugProjectContainer.php on line 4000