php 从 5.6 升级到 7.4 后项目 symfony 2.8 中 AppKernel.php 的问题

Problem with AppKernel.php in project symfony 2.8 after upgrade php from 5.6 to 7.4

最近几天我尝试逐步升级我的项目。我有 Symfony 2.8,composer 2。最近我找到了 rector/rector 升级包,但是当我尝试安装它时出现了冲突。接下来我尝试安装 rector/rector-prefixed。它也给安装带来了很多问题,但经过研究,我已经将我的 php 版本更新到 7.4,并且一切顺利。我已经更新并安装了作曲家,但同时出现了新错误。与应用内核。之前一切都很好,应用程序运行良好。现在我在浏览器中收到消息:Composer 在您的平台中检测到问题:“您的 Composer 依赖项需要 PHP 版本“>= 7.4.0”。“

并且在每个命令之后的控制台中(例如:php app/console 列表)现在我收到这条消息:

#!/usr/bin/env php
PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "TixiCoreDomainBundle" from namespace "Tixi\CoreDomainBundle".
Did you forget a "use" statement for "Tixi\CoreDomainBundle\TixiCoreDomainBundle"? in C:\Users\Developer\PhpstormProjects\sfitixi\app\AppKernel.php:32
Stack trace:
#0 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(427): AppKernel->registerBundles()
#1 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(128): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php(62): Symfony\Component\HttpKernel\Kernel->boot()
#3 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php(117): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Compone in C:\Users\Developer\Phpstor
mProjects\sfitixi\app\AppKernel.php on line 32

Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "TixiCoreDomainBundle" from namespace "Tixi\CoreDomainBundle".
Did you forget a "use" statement for "Tixi\CoreDomainBundle\TixiCoreDomainBundle"? in C:\Users\Developer\PhpstormProjects\sfitixi\app\AppKernel.php:32
Stack trace:
#0 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(427): AppKernel->registerBundles()
#1 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(128): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php(62): Symfony\Component\HttpKernel\Kernel->boot()
#3 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php(117): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Compone in C:\Users\Developer\Phpstor
mProjects\sfitixi\app\AppKernel.php on line 32

这是我在 AppKernel.php 中的内容:

public function registerBundles(): array
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),

            new Tixi\CoreDomainBundle\TixiCoreDomainBundle(),
            new Tixi\ApiBundle\TixiApiBundle(),
            new Tixi\SecurityBundle\TixiSecurityBundle(),
            new Tixi\App\AppBundle\TixiAppBundle(),
            new FOS\RestBundle\FOSRestBundle(),
            new FOS\OAuthServerBundle\FOSOAuthServerBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle(),
            new APY\BreadcrumbTrailBundle\APYBreadcrumbTrailBundle(),
            new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
            new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

我尝试编写 use 语句,但没有任何改变。 我的 composer.json:

{
  "name": "symfony/framework-standard-edition",
  "license": "MIT",
  "type": "project",
  "description": "The \"Symfony Standard Edition\" distribution",
  "autoload": {
    "psr-4": {
      "Tixi\": "src/"
    },
    "classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
  },
  "autoload-dev": {
    "files": [ "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" ]
  },
  "require": {
    "php": "~7.4",
    "ext-json": "*",
    "apy/breadcrumbtrail-bundle": "1.3.*",
    "composer/ca-bundle": "~1.2.7",
    "doctrine/doctrine-bundle": "~1.4",
    "doctrine/doctrine-migrations-bundle": "1.3.*",
    "doctrine/orm": "^2.4.8",
    "egulias/email-validator": "~1.2",
    "friendsofsymfony/oauth-server-bundle": "1.5.*",
    "friendsofsymfony/rest-bundle": "1.7.*",
    "incenteev/composer-parameter-handler": "~2.0",
    "jms/serializer-bundle": "1.5.*",
    "knplabs/knp-snappy-bundle": "1.5.*",
    "mediaburst/clockworksms": "2.0.*",
    "sensio/distribution-bundle": "~4.0",
    "sensio/framework-extra-bundle": "^3.0.2",
    "symfony/monolog-bundle": "^3.0.2",
    "symfony/swiftmailer-bundle": "~2.3,>=2.3.10",
    "symfony/symfony": "2.8.*",
    "twig/extensions": "1.5.*",
    "twig/twig": "^1.0||^2.0"
  },
  "require-dev": {
    "rector/rector-prefixed": "^0.9.31",
    "sensio/generator-bundle": "~3.0",
    "symfony/phpunit-bridge": "~2.7"
  },
  "scripts": {
    "symfony-scripts": [
      "Incenteev\ParameterHandler\ScriptHandler::buildParameters",
      "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
      "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
      "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
      "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
      "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget"
    ],
    "post-install-cmd": [
      "@symfony-scripts"
    ],
    "post-update-cmd": [
      "@symfony-scripts"
    ]
  },
  "config": {
    "bin-dir": "bin",
    "platform": {
      "php": "7.4"
    },
    "sort-packages": true,
    "discard-changes": true
  },
  "extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "symfony-assets-install": "relative",
    "incenteev-parameters": {
      "file": "app/config/parameters.yml"
    },
    "branch-alias": {
      "dev-master": "2.8-dev"
    }
  }
}

有人知道如何解决这个问题吗?

编辑 (11.03.2021)

是的,class 存在。问题是每 4 个 class 的命名空间都以 Tixi 开头。这个 class 是空的,它们扩展了 Symfony 的 Bundle class。他们是这样的:

<?php

namespace Tixi\ApiBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
 * Class TixiApiBundle
 * @package Tixi\ApiBundle
 */
class TixiApiBundle extends Bundle
{
}

并且这个 classes 的位置通过它们的命名空间。

编辑:18.03

更改 composer.json 中的命名空间以进行自动加载后,我遇到了另一个错误,这次是来自 composer.json 的 运行 个脚本。这是错误消息:

> post-install-cmd: @symfony-scripts
> symfony-scripts: Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> symfony-scripts: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> symfony-scripts: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

#!/usr/bin/env php

  [Symfony\Component\Debug\Exception\ContextErrorException]
  Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception

  [RuntimeException]
  An error occurred when executing the ""cache:clear --no-warmup"" command:

  #!/usr/bin/env php

    [Symfony\Component\Debug\Exception\ContextErrorException]
    Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?
  .
Exception trace:
 () at C:\Users\Developer\PhpstormProjects\sfitixi\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Composer\ScriptHandler.php:326
 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::executeCommand() at C:\Users\Developer\PhpstormProjects\sfitixi\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Composer\ScriptHandler.php:138
 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:341
 Composer\EventDispatcher\EventDispatcher->executeEventPhpScript() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:220
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:87
 Composer\EventDispatcher\EventDispatcher->dispatch() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:200
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:102
 Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Installer.php:341
 Composer\Installer->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Command/InstallCommand.php:136
 Composer\Command\InstallCommand->execute() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Command/Command.php:245
 Symfony\Component\Console\Command\Command->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Application.php:835
 Symfony\Component\Console\Application->doRunCommand() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Application.php:185
 Symfony\Component\Console\Application->doRun() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Console/Application.php:310
 Composer\Console\Application->doRun() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Console/Application.php:122
 Composer\Console\Application->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/bin/composer:63
 require() at C:\ProgramData\ComposerSetup\bin\composer.phar:24

自动加载器配置不正确:

  "autoload": {
    "psr-4": {
      "Tixi\": "src/"
    },
    "classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
  },

这告诉自动加载器在 srcTixi 命名空间中搜索所有 classes。据此,class Tixi\CoreDomainBundle\TixiCoreDomainBundle 应位于 src/CoreDomainBundle/TixiCoreDomainBundle.php,但它位于 src/Tixi/CoreDomainBundle/TixiCoreDomainBundle.php

要么将 Tixi 子文件夹中的所有内容向上移动一级,要么调整您的 class 加载程序设置 - 将其更改为 src/Tixi/ 可能会有所帮助