无法在 Symfony 4 自定义包中声明 class 错误

Cannot declare class error in Symfony 4 custom bundle

当我尝试在 Symfony 4 中创建一个新的可重用包时,我不断收到此错误。

Compile Error: Cannot declare class App\ICatcher\Builder\ControlPanel, because the name is already in use
 (1/1) FatalErrorException Compile Error: Cannot declare class App\ICatcher\Builder\ControlPanel, because the name is already in use in ControlPanel.php line 23

ControlPanel.php:

namespace App\ICatcher\Builder;
use Symfony\Component\HttpFoundation\Response;
class ControlPanel extends Response {    
    public function index(){
        return new Response(
            '<html><body>TEST! BUNDLE!!</body></html>'
        );
    }    
}

主包文件:

namespace App\ICatcher\Builder;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class Builder extends Bundle
{
}

作曲家:

"autoload": {
        "psr-4": {
            "App\": "src/",
            "App\ICatcher\Builder\":"src/ICatcher/Builder/src"
        }
    },

捆绑包:

return [
    [...]  
    App\ICatcher\Builder\Builder::class => ['dev' => true,'test' => true],
];

UPD1: 当我将整个 ControlPanel class 注释掉时,刷新页面 - 当我再次取消注释时错误消失并且不会重新出现 - 它 运行s class 并在 Response 中显示文本。然后,如果我 运行 composer update - 它失败并出现相同的错误,如果我在那之后刷新页面 - 它再次失败并出现相同的错误。

您必须从 composer.json 行 "App\ICatcher\Builder\":"src/ICatcher/Builder/src" 中删除,因为在您的情况下,当您通过 composer update 命令转储 vendor/autoload.php 时名称空间是重复的。