2

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"
    }
  }
}
4
  • 1
    You might want to post your CoreBundles composer.json. Commented Oct 27, 2017 at 9:54
  • I added the composer.json. Commented Oct 27, 2017 at 10:03
  • 1
    Shouldn't it say "Namespace\\CoreBundle\\": "src/" in the autoload psr-4 part? Edit: nvm - was thinking psr-0. Does it work after you manually dump the autoloader using composer dump-autoload -a ? Commented Oct 27, 2017 at 10:37
  • 1
    Thanks! composer dump-autoload -a did the trick! Commented Oct 27, 2017 at 11:34

2 Answers 2

1

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`
Sign up to request clarification or add additional context in comments.

Comments

1

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.

3 Comments

I manually deleted the .lock file and ran composer update but the problem persists. :(
do you have require('path/to/vendor/autoload.php') in your entry script?
Thank you for your help. composer dump-autoload -a did the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.