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

如何解决将 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/ 可能会有所帮助

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

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-