I created a simple custom Symfony bundle (in version 5.0). It's after I ran composer require
located in vendor/ntrx/ntrx-user-bundle
, but I'm not able to load it normally. The folder structure there is like this:
Controller/
Service/
composer.json
NtrxUserBundle.php
Readme.md
The composer.json
contains the following:
{
"name": "ntrx/ntrx-user-bundle",
"description": "",
"license": "proprietary",
"type": "symfony-bundle",
"require": {
"php": "^7.2.5",
[...]
},
"autoload": {
"psr-4": { "Ntrx\\UserBundle\\": "" }
}
}
And the NtrxUserBundle.php
contains the following code:
<?php
namespace Ntrx\UserBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class NtrxUserBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container): void {
parent::build($container);
}
}
When I ran for example php bin/console
I get the following error:
Symfony\Component\ErrorHandler\Error\ClassNotFoundError^ {#31
#message: """
Attempted to load class "NtrxUserBundle" from namespace "Ntrx\UserBundle".\n
Did you forget a "use" statement for another namespace?
"""
#code: 0
#file: "./src/Kernel.php"
#line: 23
trace: {
./src/Kernel.php:23 {
App\Kernel->registerBundles(): iterable^
› if ($envs[$this->environment] ?? $envs['all'] ?? false) {
› yield new $class();
› }
}
./vendor/symfony/http-kernel/Kernel.php:369 { …}
./vendor/symfony/http-kernel/Kernel.php:123 { …}
./vendor/symfony/framework-bundle/Console/Application.php:169 { …}
./vendor/symfony/framework-bundle/Console/Application.php:75 { …}
./vendor/symfony/console/Application.php:140 { …}
./bin/console:42 { …}
}
}
I tried to change the names of the bundle or to change the autoloader, but it seems that the class isn't there at all. I also tried to break an other third-party bundle (make a typo in the class name) and I get an corresponding error there but not the error above (The file was found but the class was not in it, the class name or namespace probably has a typo.
). Also composer dump-autoload
doesn't change anything.
The only similar error I found in the web is Symfony enable custom bundle ClassNotFoundException and I think that there's everything correkt in my code. Any suggestions?