In a project with Symfony 4, I import a self-made bundle with composer
"require-dev": {
"symfony/dotenv": "^4.0",
"symfony/profiler-pack": "^1.0",
"myusername/my-bundle": "dev-master"
},
"repositories" : [{
"type" : "vcs",
"url" : "git@github.com:myusername/my-bundle.git"
}],
The bundle is correctly installed but I got the following error:
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "MyBundle" from namespace "My\Bundle\MyBundle".
The bundle is loaded in the Kernel from the bundles.php file
My\Bundle\MyBundle\MyBundle::class => ['dev' => true, 'test' => true]
Here you are the composer.json of my bundle:
{
"name" : "myusername/my-bundle",
"type" : "symfony-bundle",
"autoload" : {
"psr-4" : {
"myusername\\MyBundle\\" : ""
}
}
}
And finally the main file of the bundle is MyBundle.php
<?php
namespace My\Bundle\MyBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use My\Bundle\MyBundle\DependencyInjection\MyExtension;
class MyBundle extends Bundle
{
public function getContainerExtension()
{
return new MyExtension();
}
}
I'm aware that the problem is caused by the autoloader but I can't figure out how to fix it. I tried the composer dump-autoload command and I have consulted the following similar questions but without luck:
- Symfony autoload not working for a custom Bundle
- Composer Not Generating Autoloads For Library
- PHP Composer autoload PSR-4 Class not found
Thank you!