【问题标题】:Upgrade to Symfony flex (3.4) - Problems when there are many bundles升级到 Symfony flex (3.4) - 有很多捆绑包时的问题
【发布时间】:2021-08-03 14:47:42
【问题描述】:

我有一个使用 symfony 3.4 的应用程序,我正在将其更新为 flex,然后转到版本 4。 问题是我有很多捆绑包,而在 FLEX 中它们不适用于这些捆绑包……所以我正在寻找一种方法来维护我的捆绑包……

这是我的 SRC 文件夹中的内容(控制器、实体和存储库为空):

> SRC
      > CONTROLLER
      > ENTITY
      > REPOSITORY
      > Kernel.php
      > .htaccess
      > H360 (the place of my bundles)
            > comercialBundle
            > jasperBundle
            > generalBundle
            > ...

这是它返回给我的错误信息:

In FileLoader.php line 168:
                                                                                                                                                                                                                                                                        
  Expected to find class "App\H360\JasperBundle\Controller\DefaultController" in file "C:\inetpub\wwwroot\360forhotels\src/H360\JasperBundle\Controller\DefaultController.php" while importing services from resource "../src/*", but it was not found! Check the name  
  space prefix used with the resource in C:\inetpub\wwwroot\360forhotels\config/services.yaml (which is loaded in resource "C:\inetpub\wwwroot\360forhotels\config/services.yaml").                                                                                     
                                                                                                                                                                                                                                                                        

In FileLoader.php line 157:
                                                                                                                                                                                                                                                                        
  Expected to find class "App\H360\JasperBundle\Controller\DefaultController" in file "C:\inetpub\wwwroot\360forhotels\src/H360\JasperBundle\Controller\DefaultController.php" while importing services from resource "../src/*", but it was not found! Check the name  
  space prefix used with the resource.  

所以这是我的“services.yaml”文件的一部分(我知道这是不对的):

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

【问题讨论】:

  • 首先将 H360 添加到 App 下的排除部分。尝试自动装配完整的捆绑包不仅会导致那些 App 前缀错误,而且还会带来相当多的乐趣。希望您的捆绑包已经在工作,因此不需要您自动装配它们。事实上,您可能会考虑完全关闭自动连线,直到您的应用正常运行。
  • 您可能会遇到 composer.json 的 psr4 部分的问题。你需要设置自动加载(不是自动装配),这样你的类才能被加载。
  • 感谢您的评论!!!看来我已经在解决它了,我完全按照你说的做了......现在我在 yml 文件中遇到了类型 REST 的问题......谢谢@Cerad

标签: php symfony routes upgrade symfony-flex


【解决方案1】:

首先将 H360 添加到 App 下的排除部分。尝试自动装配完整的捆绑包不仅会导致那些 App 前缀错误,而且还会带来相当多的乐趣。希望您的捆绑包已经在工作,因此不需要您自动装配它们。实际上,您可能会考虑完全关闭自动连线,直到您的应用正常运行。

您可能会遇到 composer.json 的 psr4 部分的问题。您需要设置自动加载(不是自动装配),以便加载您的类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2018-10-17
    • 2019-09-14
    • 2023-02-25
    • 2018-06-01
    • 2020-10-01
    • 2019-02-21
    相关资源
    最近更新 更多