【问题标题】:Cannot extend from interface CompilerPassInterface in Symfony 3.4无法从 Symfony 3.4 中的 CompilerPassInterface 接口扩展
【发布时间】:2018-10-01 01:22:45
【问题描述】:

我想通过在 Symfony 3.4 中使用 compilerPass 来覆盖 FosUserbundle 的控制器(RegistartionController)所以这是我的代码

=== RegisterUserCompilerPass ===

<?php

namespace myBundle;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;


class RegisterUserCompilerPass extends CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        $container
            ->getDefinition('fos_user.registration.controller')
            ->setClass(MyBundle\Controller\ReplaceRegistrationController::class) ; 
    }
}

这是添加到主包类时的文件

<?php

namespace MyBundle;


use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

use MyBundle\DependencyInjection\Compiler\RegisterUserCompilerPass  ; 


// use Crypto\UserBundle\Manager\ReplaceRegistration ; 

class CryptoUserBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
     parent::build($container);
       $container->addCompilerPass(new RegisterUserCompilerPass() );
    }

}

当访问我的注册路径时,我得到了

编译错误:类 MyBundle\DependencyInjection\Compiler\RegisterUserCompilerPass 不能 从接口扩展 Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface

【问题讨论】:

  • 你应该理解你的错误信息,而不仅仅是阅读它们,它会让你的生活更简单:)

标签: php symfony overriding fosuserbundle


【解决方案1】:
class RegisterUserCompilerPass extends CompilerPassInterface

应该是

class RegisterUserCompilerPass implements CompilerPassInterface

PHP can't extend from interface?

【讨论】:

  • 你应该解释为什么,即使答案是基本的。
猜你喜欢
  • 1970-01-01
  • 2019-05-05
  • 1970-01-01
  • 2018-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-20
  • 1970-01-01
相关资源
最近更新 更多