Slatyoo
Slatyoo

Reputation: 126

services.yaml configuration - autowire without namespace

How can I autowire my classes with the following folder-structure:

src
 -folder1
  --folder1.1
  --folder1.2
 -folder2
 -folder3

PSR-4 allows autoloading root directories in the composer.json like this (e.g.):
"": "src/"

In symfony to autowire all classes in the given folder you approach it in the services.yaml
Default-Configuration:

  App\:
    resource: 'src/*'
    exclude: 'src/{Entity,Migrations,Tests,Kernel.php}'

Where App\ becomes the default namespace (which I can't use as the default namespace).
I want to achieve the same thing in the services.yaml what I did in the composer.json.

Something like this:

  some.id:
    namespace: ''
    resource: 'src/*'
    exclude: 'src/{Entity,Migrations,Tests,Kernel.php}'

Also I dont want to add 50-60 lines of namespace implementation like this:

Namespace1\:
   resource: ...
   exclude: ...
Namespace2\: ...
Namespace3\: ...

Upvotes: 1

Views: 766

Answers (1)

Slatyoo
Slatyoo

Reputation: 126

There was no way to get this folder-structure to work with autowiring without adding a global namespace (like App\), adding every namespace in services.yaml or modifying the base code.

What I did was adding the global namespace App\ in the src folder.

Upvotes: 1

Related Questions