title: Symfony: Namespaced bundle not loaded correctly
body: <p>I have a freshly installed (through composer) Symfony app. I've moved things around a bit, and it seems this has caused Symfony's annotation driver for controllers to break down. Most notably, I'm using a namespace.</p>
  
  <p>My <code>app/config/routing.yml</code> is unmodified. I.e.:</p>
  
  <pre><code>app:
      resource: '@Kafoso/TestApp/AppBundle/Controller/'
      type: annotation
  </code></pre>
  
  <p>And <code>app/config/routing_dev.yml</code> points to <code>app/config/routing.yml</code>.</p>
  
  <p>Now, I've moved the <code>AppBundle</code> class to a new namespace (and thus folder location) <code>Kafoso\TestApp\AppBundle</code>.</p>
  
  <p>I have a default controller <code>Kafoso\TestApp\AppBundle\Controller\DefaultController</code> for <code>GET /</code>:</p>
  
  <pre><code>namespace Kafoso\TestApp\AppBundle\Controller;
  
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\HttpFoundation\Request;
  
  class DefaultController extends Controller
  {
      /**
       * @Route("/", name="homepage")
       */
      public function indexAction(Request $request)
      {
          // replace this example code with whatever you need
          return $this-&gt;render('default/index.html.twig', [
              'base_dir' =&gt; realpath($this-&gt;getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR,
          ]);
      }
  }
  </code></pre>
  
  <p>The bundle is indeed added to <code>app/AppKernel.php</code> (<code>new Kafoso\TestApp\AppBundle()</code>).</p>
  
  <p>The error I get:</p>
  
  <blockquote>
    <p>request.CRITICAL: Uncaught PHP Exception Symfony\Component\Config\Exception\FileLoaderLoadException: "Cannot load resource "@Kafoso/TestApp/AppBundle/Controller/". Make sure the "Kafoso" bundle is correctly registered and loaded in the application kernel class. If the bundle is registered, make sure the bundle path "@Kafoso/TestApp/AppBundle/Controller/" is not empty." at (...)/vhosts/testapp/framework/server/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/Loader.php line 73</p>
  </blockquote>
  
  <p>Notice how Symfony thinks my bundle's name is "Kafoso".</p>
  
  <p>The strange thing is, if I put an <code>error_log</code> or <code>var_dump</code> in the <code>DefaultController</code> (outside the class declaration), I see the output. But for some reason Symfony doesn't parse the controller's annotations.</p>
  
  <p>Is it not possible to use namespaces here? Must everything be placed under <code>AppBundle</code> (or a differently chosen name)?</p>
  
  <p>If it's the latter it seems like a rather restrictive and unnecessary enforcement.</p>
  
  <hr>
  
  <p>EDIT</p>
  
  <p><code>app/config/services.yml</code>:</p>
  
  <pre><code># Learn more about services, parameters and containers at
  # https://symfony.com/doc/current/service_container.html
  parameters:
      #parameter_name: value
  
  services:
      # default configuration for services in *this* file
      _defaults:
          # automatically injects dependencies in your services
          autowire: true
          # automatically registers your services as commands, event subscribers, etc.
          autoconfigure: true
          # this means you cannot fetch services directly from the container via $container-&gt;get()
          # if you need to do this, you can override this setting on individual services
          public: false
  
      # makes classes in src/Kafoso/TestApp/AppBundle available to be used as services
      # this creates a service per class whose id is the fully-qualified class name
      Kafoso\TestApp\AppBundle\:
          resource: '../../src/Kafoso/TestApp/AppBundle/*'
          # you can exclude directories or files
          # but if a service is unused, it's removed anyway
          exclude: '../../src/Kafoso/TestApp/AppBundle/{Entity}'
  
      # controllers are imported separately to make sure they're public
      # and have a tag that allows actions to type-hint services
      Kafoso\TestApp\AppBundle\Controller\:
          resource: '../../src/Kafoso/TestApp/AppBundle/Controller'
          public: true
          tags: ['controller.service_arguments']
  
      # add more services, or override services that need manual wiring
      # Kafoso\TestApp\AppBundle\Service\ExampleService:
      #     arguments:
      #         $someArgument: 'some_value'
  </code></pre>
  
  <hr>
  
  <p>EDIT</p>
  
  <p><code>composer.json</code>:</p>
  
  <pre><code>{
      "name": "kafoso/testapp",
      "license": "proprietary",
      "type": "project",
      "authors": [
          {
              "name": "Kafoso",
              "email": ""
          }
      ],
      "autoload": {
          "psr-4": {
              "Kafoso\\TestApp\\": "src/Kafoso/TestApp"
          },
          "classmap": [
              "app/AppKernel.php",
              "app/AppCache.php"
          ]
      },
      "autoload-dev": {
          "psr-4": {
              "Kafoso\\TestApp\\AppBundle\\Tests\\Integration\\": "tests/integration",
              "Kafoso\\TestApp\\AppBundle\\Tests\\Unit\\": "tests/unit"
          },
          "files": [
              "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
          ]
      },
      "require": {
          "php": "7.1.*",
          "doctrine/doctrine-bundle": "^1.6",
          "doctrine/orm": "^2.5",
          "incenteev/composer-parameter-handler": "^2.0",
          "sensio/distribution-bundle": "^5.0.19",
          "sensio/framework-extra-bundle": "^3.0.2",
          "symfony/monolog-bundle": "^3.1.0",
          "symfony/polyfill-apcu": "^1.0",
          "symfony/swiftmailer-bundle": "^2.3.10",
          "symfony/symfony": "3.3.*",
          "twig/twig": "^1.0||^2.0",
          "webmozart/glob": "^4.1"
      },
      "require-dev": {
          "phpunit/phpunit": "^6.2",
          "phpunit/dbunit": "^3.0",
          "sensio/generator-bundle": "^3.0",
          "symfony/phpunit-bridge": "^3.0"
      },
      "scripts": {
          "symfony-scripts": [
              "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
              "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
              "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
              "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
              "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
              "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
          ],
          "post-install-cmd": [
              "@symfony-scripts"
          ],
          "post-update-cmd": [
              "@symfony-scripts"
          ]
      },
      "config": {
          "sort-packages": true
      },
      "extra": {
          "symfony-app-dir": "app",
          "symfony-bin-dir": "bin",
          "symfony-var-dir": "var",
          "symfony-web-dir": "../../www",
          "symfony-tests-dir": "tests",
          "symfony-assets-install": "relative",
          "incenteev-parameters": {
              "file": "app/config/parameters.yml"
          },
          "branch-alias": null
      }
  }
  </code></pre>
  
  <p>The only changes from the vanilla file are:</p>
  
  <ul>
  <li>Test specification of test namespaces, which have no influence on this problem.</li>
  <li>The addition of the package <code>webmozart/glob</code>.</li>
  <li>The change of <code>symfony-web-dir</code>, which is indeed working (<code>www/app.php</code> is run).</li>
  </ul>
  
  <p>The PSR-4 autoload is <code>Kafoso\TestApp</code>, and not <code>Kafoso\TestApp\AppBundle</code>, but this shouldn't be necessary.</p>