-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #23991 [DI] Improve psr4-based service discovery (alternative…
… implementation) (kbond) This PR was merged into the 3.4 branch. Discussion ---------- [DI] Improve psr4-based service discovery (alternative implementation) | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22397 | License | MIT | Doc PR | symfony/symfony-docs#8310 This is an alternative to #23986. It is simpler and doesn't require a second glob in the service id. This adds a `namespace` option. It is optional and if it isn't used, then it falls back to using the service id (current behaviour). As stof mentions in #22397 (comment), it is consistent with the xml loader. With this feature, you can define your services like this: ```yaml services: command_handlers: namespace: App\Domain\ resource: ../../src/Domain/*/CommandHandler tags: [command_handler] event_subscribers: namespace: App\Domain\ resource: ../../src/Domain/*/EventSubscriber tags: [event_subscriber] ``` ping @stof, @nicolas-grekas Commits ------- 00d7f6f [DI] improve psr4-based service discovery with namespace option
- Loading branch information
Showing
9 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...ponent/DependencyInjection/Tests/Fixtures/Prototype/OtherDir/Component1/Dir1/Service1.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\Component1\Dir1; | ||
|
||
class Service1 | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
...ponent/DependencyInjection/Tests/Fixtures/Prototype/OtherDir/Component1/Dir2/Service2.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\Component1\Dir2; | ||
|
||
class Service2 | ||
{ | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...ponent/DependencyInjection/Tests/Fixtures/Prototype/OtherDir/Component1/Dir3/Service3.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\Component1\Dir3; | ||
|
||
class Service3 | ||
{ | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...ponent/DependencyInjection/Tests/Fixtures/Prototype/OtherDir/Component2/Dir1/Service4.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\Component2\Dir1; | ||
|
||
class Service4 | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
...ponent/DependencyInjection/Tests/Fixtures/Prototype/OtherDir/Component2/Dir2/Service5.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\Component2\Dir2; | ||
|
||
class Service5 | ||
{ | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...ymfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_prototype_namespace.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
services: | ||
dir1: | ||
namespace: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\ | ||
resource: ../Prototype/OtherDir/*/Dir1 | ||
tags: [foo] | ||
|
||
dir2: | ||
namespace: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\ | ||
resource: ../Prototype/OtherDir/*/Dir2 | ||
tags: [bar] |
4 changes: 4 additions & 0 deletions
4
...DependencyInjection/Tests/Fixtures/yaml/services_prototype_namespace_without_resource.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
services: | ||
dir1: | ||
namespace: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\ | ||
tags: [foo] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters