我想通过使用Symfony 3.4中的compilerPass来覆盖FosUserbundle的控制器(RegistartionController),所以这是我的代码
=== 注册用户编译器密码 ===
<?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) ;
}
}
Run Code Online (Sandbox Code Playgroud)
这是添加时的文件,将其添加到主包类中
<?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() );
}
}
Run Code Online (Sandbox Code Playgroud)
当访问我的注册路径时我得到
编译错误:类 MyBundle\DependencyInjection\Compiler\RegisterUserCompilerPass 无法从接口 Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface 扩展