微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Symfony\Component\Console\Exception\LogicException during php bin/console server:run

如何解决Symfony\Component\Console\Exception\LogicException during php bin/console server:run

我无法通过命令运行 symfony 本地服务器:PHP bin/console server:run。 我得到错误: [Symfony\Component\Console\Exception\LogicException] 名为“连接”的选项已存在。

composer.json 中的依赖项:

"require": {
        "PHP": "^7.0,<7.4","composer/package-versions-deprecated": "^1.11","doctrine/doctrine-bundle": "^1.6","doctrine/orm": "^2.5","incenteev/composer-parameter-handler": "^2.0","sensio/distribution-bundle": "^5.0.19","sensio/framework-extra-bundle": "^3.0.2","symfony/monolog-bundle": "^3.1.0","symfony/polyfill-apcu": "^1.0","symfony/swiftmailer-bundle": "^2.3.10","symfony/symfony": "3.3.*","twig/twig": "^1.0||^2.0"
    },"require-dev": {
        "doctrine/data-fixtures": "^1.3","doctrine/doctrine-fixtures-bundle": "^2.3","liip/functional-test-bundle": "^1.8","PHPunit/PHPunit": "^6.3","sensio/generator-bundle": "^3.0","symfony/PHPunit-bridge": "^3.0"
    },

参数.yml:

# This file is auto-generated during the composer install
parameters:
    database_host: 127.0.0.1
    database_port: 3306
    database_name: tests
    database_user: root
    database_password: password
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    secret: ThisTokenIsNotSoSecretChangeIt

我认为 parameters.yml 中的这些参数以前可以使用。 我使用 MysqLsqlite 进行测试。

解决方法

我在 Symfony v4.2 项目中遇到了同样的问题,但我的代码库中没有任何更改。

已在此问题中找到https://github.com/doctrine/dbal/issues/4565
它出现在 doctrine/doctrine-bundle 包的某些版本中(在我的例子中是 v1.11)。来自供应商的 RunSqlDoctrineCommand.php 添加了导致错误的第二个选项。

如果您可以更新您的 doctrine/doctrine-bundle 软件包,您可能会没事。就我而言,无法按包进行更新或修复。

在这种情况下我们能做什么?

接下来的内容与其说是一个真正好的解决方案,不如说是一种黑客行为,因此请自行承担风险!

作为来自官方存储库的提交中的 statet:https://github.com/doctrine/DoctrineBundle/commit/86d2469d6be06d55ad7b9e2f076f6942476f2e87(感谢上述问题中的人)
我从该提交中复制了新的 RunSqlDoctrineCommand.php,并将其作为 dist/RunSqlDoctrineCommand.php 保存在我的项目中。

composer.json 中,将 scripts 部分更改如下:

{
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd"
        },"doctrine-bugfix": [
            "cp -f dist/RunSqlDoctrineCommand.php vendor/doctrine/doctrine-bundle/Command/Proxy/RunSqlDoctrineCommand.php"
        ],"post-install-cmd": [
            "@auto-scripts","@doctrine-bugfix"
        ],"post-update-cmd": [
            "@auto-scripts","@doctrine-bugfix"
        ]
    }
}

这只会在每个 composer install/update 上复制并覆盖供应商目录中的原始文件。顺便说一下,这只适用于 unix/linux 系统。

正如所说:不是最好的解决方案,但它可以让您的项目保持良好状态。

,

在这个answer中有一个很好的解释

就我而言

<section>
        <div class="apply-section bg-1">
          <h2>Lorem</h2>
          <div class="apply-section-text">Lorem ipsum dolor sit amet,consetetur sadipscing elitr,sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,sed diam voluptua. At vero eos et accusam et justo</div>
          <div class="apply-link-container"><a class="apply-link" href="#">button</a></div>
        </div>
      </section>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。