phpsymfonyroutesupgradesymfony-flex

Upgrade to Symfony flex (3.4) - Problems when there are many bundles


I have an application with symfony 3.4, and I am updating it to flex and then going to version 4. The problem is that i have many bundles, and in FLEX they do not work with these ... so I am looking for a way to maintain my bundles ...

This is what i have in my SRC folder (controller, entity and repository are empty):

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

This is the error message it returns to me:

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.  

So this is part of my "services.yaml" file (I know it's not right):

    # 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']

Solution

  • Start by adding H360 to the exclude section under App. Trying to autowire complete bundles will not only result in those App prefix errors but will cause a considerable amount of fun besides. Hopefully your bundles are already working so there will be no need yo autowire them. In fact you might consider just turning autowire off completely until you get your app working.

    You might then have issues with the psr4 section of composer.json. You need to setup autoloading (not autowire) so you classes can be loaded.