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

问题描述

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

在每个命令(例如:php app/console list)之后的控制台中,现在我收到此消息:

#!/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)

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

<?php

namespace Tixi\ApiBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

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

这些类的位置与它们的命名空间一起传递。

Folders structure

编辑: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" ]
  },

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

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...