Akhmed
Akhmed

Reputation: 1219

Symfony 4 autowiring exclude ignores subfolders

Assume following directory structure:

/src
  /DTO
    /Factory
      /Collection

I want to exclude all classes, including classes from subdirectories of /DTO directory

In my services file I do:

services:
  _defaults:
    autowire: true
    autoconfigure: true
    public: false

    App\:
    resource: '../src/*
    exclude:
      - '../src/DTO/*'

This leads to:

Symfony\Component\DependencyInjection\Exception\RuntimeException : Cannot autowire service App\DTO\Factory\Collection\MyCollection

If this service placed in DTO folder directly - then autowiring works.

Can I specify the exclude expression in any way to include subfolders?

Upvotes: 1

Views: 1766

Answers (2)

Akhmed
Akhmed

Reputation: 1219

I found a solution to exclude not only classes placed directly in folder, but also subfolders with two asterisk signs (**).

Here is the example of a valid configuration:

services:
  _defaults:
    autowire: true
    autoconfigure: true
    public: false

    App\:
    resource: '../src/*
    exclude:
      - '../src/DTO/**'

Upvotes: 1

spirit
spirit

Reputation: 3415

To exclude everything from DTO folder use:

    App\:
      resource: '../src/*'
      exclude:
        - '../src/DTO'

i.e. w/o * symbol

Upvotes: 2

Related Questions