1

I create a bundle like this

<?php

namespace CDC\Basement\Bundle\UtilBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class CDCUtilBundle extends Bundle {}

and add composer.json file on root directory of my bundle folder, and put this in autoload

"psr-4": { "CDC\\Basement\\Bundle\\UtilBundle\\": "src/" },

the main class located in /src folder.

After I run composer dump-autoload command, but I get this error:
Attempted to load class "CDCUtilBundle" from namespace "CDC\Basement\Bundle\UtilBundle". Did you forget a "use" statement for another namespace?

If I understood correctly after command run, the new namespace should be added in autoload_psr4.php and autoload_static.php (vendor/composer/) , also in main composer.json too like other bundles https://prnt.sc/r9rwss.

What did I do wrong ? Maybe I forgot add somewhere configs or I need to run other commands too ?

  • What a file name of your bundle class? – Vladimir Tarkhanov Mar 01 '20 at 09:44
  • also typos are a lovely source of errors. – Jakumi Mar 01 '20 at 09:59
  • I added your code to an existing S5 project and it all worked as expected. "add composer.json file on root directory of my bundle folder" Does this mean you have your bundle packaged as a composer package and you installed it using composer require? I suspect your dump-autoload is not picking up your modified composer.json. – Cerad Mar 01 '20 at 14:39
  • Vladimir Tarkhanov, the file name is **CDCUtilBundle.php** – Bagrat Hakobyan Mar 01 '20 at 15:35
  • @Cerad , no, I don`t use **composer require**, I create bundle files manually. – Bagrat Hakobyan Mar 01 '20 at 15:39
  • Is your compser.json with the CDC psr4 entry in the same directory from which you run "composer dump-autoload"? – Cerad Mar 01 '20 at 16:20
  • @Cerad, no its located in bundle root dir, I run command from project root – Bagrat Hakobyan Mar 01 '20 at 17:13
  • 2
    So how is composer supposed to detect the existence of your bundle's composer.json file? Especially since it's doubtful that you have your bundle listed as a requirement in your project's composer.json? Might be best to consult the composer docs and work your way through the process of adding dependencies. – Cerad Mar 01 '20 at 17:21
  • @Cerad , I use symfony official documentation, but thanks for the advice, maybe composer doc can help a more – Bagrat Hakobyan Mar 02 '20 at 05:28
  • This is not a Symfony issue, it is a composer dependency issue. If you really wanted to, just add your CDC namespace line to your project's composer.json and it should work fine. – Cerad Mar 02 '20 at 16:37

0 Answers0