Reputation: 529
I try to install a custom Symfony bundle in my application. I created the bundle with the following folder structure:
.
├── composer.json
├── composer.lock
└── src
└── Namespace
└── CoreBundle
├── Controller ...
├── CoreBundle.php
├── Entity ...
├── Helper ...
├── Repository ...
├── Resources ...
├── Services ...
└── Tests ...
I successfully installed the bundle by composer install
in the vendor
folder. There it is under vendor/namespace/core-bundle
as a sym-link (I loaded it locally).
After that I added new Namespace\CoreBundle\CoreBundle(),
in the AppKernel.php
and this produces the following error:
(1/1) ClassNotFoundException
Attempted to load class "CoreBundle" from namespace "Namespace\CoreBundle".
Did you forget a "use" statement for another namespace?
in AppKernel.php (line 25)
I tried to copy the folder manually in vendor
folder, if there is any problem with the sym-link, but it produces the same error. I checked out the autoloaded classes by dump(ClassMapGenerator::createMap('/path/to/symfony'));
and I don't found my namespace there. Is my configuration wrong or my folder structure? If you need more code, I'll update my question as fast as possible.
Update: My bundles composer.json
:
{
"name": "namespace/core-bundle",
"license": "proprietary",
"type": "symfony-bundle",
"autoload": {
"psr-4": {
"Namespace\\CoreBundle\\": "src/Namespace/CoreBundle"
}
},
"require": {
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"liip/imagine-bundle": "1.9.*",
"php": ">=5.5.9",
"symfony/symfony": "3.3.*"
},
"require-dev": {
},
"extra": {
"branch-alias": {
"dev-master": "development"
}
}
}
Upvotes: 2
Views: 1114
Reputation: 24298
After every manual update of autoload
section in your composer.json
:
{
"autoload": {
"psr-4": {
"Namespace\\CoreBundle\\": "src/Namespace/CoreBundle"
}
}
}
don't forget to refresh your generated /vendor/autoload.php
via CLI:
composer dump
# shortcut for `composer dump-autoload`
Upvotes: 1
Reputation: 411
I have a feeling that you have run composer install
before adding the autoload in your autoload in the composer.json
. the problem with this, is that install ignores the .json file, and goes straight for the lock file, and the lock stores all the previous dependencies, leaving it in a previously tested state.
What you are looking for is composer update
. It discards .lock file, and generates a new .lock file for future install commands.
Upvotes: 1