无法从 Symfony 3.4 中的接口 CompilerPassInterface 扩展
Cannot extend from interface CompilerPassInterface in Symfony 3.4
我想通过在 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) ;
}
}
这是添加到主包时的文件 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() );
}
}
当访问我的注册路径时,我得到
Compile Error: Class
MyBundle\DependencyInjection\Compiler\RegisterUserCompilerPass cannot
extend from interface
Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface
class RegisterUserCompilerPass extends CompilerPassInterface
应该是
class RegisterUserCompilerPass implements CompilerPassInterface
见PHP can't extend from interface?
我想通过在 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) ;
}
}
这是添加到主包时的文件 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() );
}
}
当访问我的注册路径时,我得到
Compile Error: Class MyBundle\DependencyInjection\Compiler\RegisterUserCompilerPass cannot extend from interface Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface
class RegisterUserCompilerPass extends CompilerPassInterface
应该是
class RegisterUserCompilerPass implements CompilerPassInterface
见PHP can't extend from interface?