8000 [DI][DX] Allow `exclude` to be an array of patterns · Issue #23956 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI][DX] Allow exclude to be an array of patterns #23956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
simshaun opened this issue Aug 22, 2017 · 8 comments
Closed

[DI][DX] Allow exclude to be an array of patterns #23956

simshaun opened this issue Aug 22, 2017 · 8 comments

Comments

@simshaun
Copy link
Contributor
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version x.y.z

It'd be nice if the exclude value could be an array of patterns. I have quite a few classes that I want to exclude from autowiring and a single glob string is getting a bit unwieldy.

Normally, this wouldn't be a problem when all services are private since the DIC removes them if unused, therefore there would be no need to exclude them.

However, in the test environment only, I'm marking all services as public with a compiler pass. (This may be a bad idea.. idk). The reason I'm doing that is that I need to access some services from the container in various functional tests, and I'm getting the warning about accessing private services with ->get(..) to be removed in 4.0.

I thought about tagging those specific services for the compiler pass to recognize and change them to public, but I'm trying to avoid adding DIC config after I was able to delete most of my DIC config since autowiring.

@soullivaneuh
Copy link
Contributor

This is indeed interessting to have something like this:

AppBundle\:
  resource: '../../src/AppBundle/*'
  exclude:
    - '../../src/AppBundle/{Entity,Payload,Repository}'
    - '../../src/AppBundle/Event/*Event.php'

IMHO, it should be a quite easy pick to integrate before the 3.x feature freeze.

@javiereguiluz
Copy link
Member

In my opinion this feature is a must-have. In a relatively small app I had to use this and it doesn't look very readable:

exclude: '../src/({Entity,Repository,Tests}|SomeDir/SomeFileName)'

@apetitpa
Copy link
apetitpa commented Oct 2, 2017

I'd like to work on this feature, is it too late to target 3.4 ?

@xabbuh
Copy link
Member
xabbuh commented Oct 3, 2017

👍 this makes sense to me and should indeed target the 3.4 branch

@chalasr
Copy link
Member
chalasr commented Oct 3, 2017

👍 for 3.4 as well

@fabpot fabpot closed this as completed May 9, 2018
fabpot added a commit that referenced this issue May 9, 2018
…netik)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[DI][DX] Allow exclude to be an array of patterns

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23956
| License       | MIT

This is basically continuing #24428.

In YAML before:
```yaml
AppBundle\:
  resource: '../../src/AppBundle/*'
  exclude: '../../src/AppBundle/{Entity,Payload,Repository}'
```

in YAML after:

```yaml
AppBundle\:
  resource: '../../src/AppBundle/*'
  exclude:
    - '../../src/AppBundle/{Entity,Payload,Repository}'
    - '../../src/AppBundle/Event/*Event.php'
```

In XML before:
```xml
<prototype namespace="App\" resource="../src/*" exclude="../src/{Entity,Migrations,Tests}" />
```

in XML after:

```xml
<prototype namespace="App\" resource="../src/*">
  <exclude>../src/{Entity,Migrations,Tests}</exclude>
  <exclude>../src/Yolo</exclude>
</prototype>
```

In PHP before:
```php
$di->load(Prototype::class.'\\', '../Prototype')
        ->autoconfigure()
        ->exclude('../Prototype/{OtherDir,BadClasses}')
```

In PHP after:
```php
    $di->load(Prototype::class.'\\', '../Prototype')
        ->autoconfigure()
        ->exclude(['../Prototype/OtherDir', '../Prototype/BadClasses'])
```

Everything is backward compatible.
Maybe a decision about handling both attribute exclude and element exclude in XML should be taken.

Commits
-------

3ae3a03 [DI][DX] Allow exclude to be an array of patterns (taking #24428 over)
@BonBonSlick
Copy link

What about xml?

For example, this one will only ignore 2lvl folder by names, unfortunately, it will try to load as a service any deeper folders in addition to this, cant figure out the synatx for exclude array of rexeps

 <prototype namespace="App\"
                   resource="../src/*"
                   exclude="../src/**/*{Traits,ValueObject,Entity,Migrations,Mappings,Serializer,FunctionsExtensions}*"
        /> 

such are not accepted

  exclude="['../src/**/*{Traits,ValueObject,Entity,Migrations,Mappings,Serializer,FunctionsExtensions}*']"
  exclude="{'../src/**/*{Traits,ValueObject,Entity,Migrations,Mappings,Serializer,FunctionsExtensions}*'}"

@ogizanagi
Copy link
Contributor
8687

@BonBonSlick See the PR's description: #27075

@Bilge
Copy link
Contributor
Bilge commented Oct 21, 2021

In my opinion this feature is a must-have. In a relatively small app I had to use this and it doesn't look very readable:

exclude: '../src/({Entity,Repository,Tests}|SomeDir/SomeFileName)'

When was this "glob" syntax ever documented? Since when were parens and pipes ever in any glob implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants
0