使用SensioGeneratorBundle生成捆绑软件会产生错误symfony 3.4

时间:2019-11-28 13:21:56

标签: php symfony symfony-3.4

在sensio / generator-bundle,symfony ^ 3.4的情况下,我无法生成新的包,我要做的是:

> symfony new calendar --version=^3.4
> cd calendar
>  composer require sensio/generator-bundle

> php bin/console generate:bundle:
> planning on sharing this bundle: yes
>  Bundle namespace: Nmateo/CalBundle
> Bundle name"NmateoCalBundle": [enter]
> Target Directory"src/": [enter]
> Configuration format"xml": [enter]

> symfony new calendar --version=^3.4
> cd calendar
> composer require sensio/generator-bundle

> php bin/console generate:bundle:
> planning on sharing this bundle: yes
> Bundle namespace: Nmateo/CalBundle
> Bundle name"NmateoCalBundle": [enter]
> Target Directory"src/": [enter]
> Configuration format"xml": [enter]

然后我收到此消息:

  

该命令无法自动配置所有内容。
    您需要手动进行以下更改。
    -编辑composer.json文件并注册捆绑软件     “自动加载”部分中的名称空间:

     

-编辑/home/nmateo/Documents/calendar/src/Kernel.php     并在AppKernel :: registerBundles()方法中添加以下捆绑软件:
    新的Nmateo \ CalBundle \ NmateoCalBundle(),

所以我在自动装带器中注册了它:

   "autoload": {
   "psr-4": {
        "App\\": "src/",
        "Nmateo\\CalBundle\\": "src/Nmateo/CalBundle/"
    }
},
"autoload-dev": {
    "psr-4": {
        "App\\Tests\\": "tests/",
        "Nmateo\\CalBundle\\": "src/Nmateo/CalBundle/"
    }
},

并将新的Nmateo CalBundle NmateoCalBundle添加到Kernel.php中registerBundles的末尾:

    public function registerBundles()
{
    $contents = require $this->getProjectDir().'/config/bundles.php';
    foreach ($contents as $class => $envs) {
        if ($envs[$this->environment] ?? $envs['all'] ?? false) {
            yield new $class();
        }
    }
    new Nmateo\CalBundle\NmateoCalBundle();
}

并执行作曲家转储自动加载:

包含0个类的生成的自动加载文件

然后我启动服务器并收到此错误,我尝试了很多次..: enter image description here

编辑:对不起代码引用中的文本,但是stackoverflow让我头疼,因为它不想发布我的问题,它说:请把您的代码放在代码引用中购买我所有的代码已经在代码引用中了。 >

2 个答案:

答案 0 :(得分:2)

在使用任何捆绑软件之前,请阅读GitHub存储库。该捆绑软件无法与Symfony 4.0配合使用

Symfony 3.4等于LTS Symfony 4.0

Sensiolabs使用* .4th版本作为功能冻结版本。


https://github.com/sensiolabs/SensioGeneratorBundle

“警告:此捆绑软件不支持Symfony4。它也不支持由Symfony Flex创建的新的无捆绑软件目录结构。请改用Maker捆绑软件。”

答案 1 :(得分:0)

Symfony 3.4在生成新捆绑包时存在问题,这是一个已知问题, https://github.com/symfony/symfony-standard/issues/1098 修复更改代码的问题,如下所示

"autoload": {
"psr-4": {
    "": "src/"
}

我们所做的是在作曲家中指定将从/src导入每个新生成的包

要完成该过程,您将需要运行

composer dump-autoload

请确保您拥有文件composer.phar或从此处https://getcomposer.org/download/下载

希望有帮助