首页 > 解决方案 > 升级到 Symfony flex (3.4) - 有很多捆绑包时的问题

问题描述

我有一个使用 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']

标签: phpsymfonyroutesupgradesymfony-flex

解决方案


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

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


推荐阅读