Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DI] Improve psr4-based service discovery (alternative implementation) #23991

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

Merged
merged 1 commit into from
Aug 29, 2017
Merged

[DI] Improve psr4-based service discovery (alternative implementation) #23991

merged 1 commit into from
Aug 29, 2017

Conversation

kbond
Copy link
Member

@kbond kbond commented Aug 25, 2017

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:

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

@nicolas-grekas
Copy link
Member

We should throw an exception when namespace is used and resource isn't.

@kbond
Copy link
Member Author

kbond commented Aug 27, 2017

  1. An exception is now thrown when the namespace attribute is used but not resource
  2. Should I close [DI] Improve PSR4-based service discovery #23986? Are we going with this implementation?
  3. I opened this PR against master but it should be against 3.4 - should I change or can you do that when merging?
  4. If we are going to go with this implementation, I will open a doc PR.

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Aug 28, 2017
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely 👍 with this implem (vs #23986)
If you can rebase+retarget on 3.4, please do. We can do it while merging yes, but if there are merge conflicts, we'll have to ask you to rebase :)

@kbond
Copy link
Member Author

kbond commented Aug 28, 2017

Ok, rebased/retargeted to 3.4 and doc PR opened.

@@ -804,7 +810,7 @@ private function checkDefinition($id, array $definition, $file)
{
if ($throw = $this->isLoadingInstanceof) {
$keywords = self::$instanceofKeywords;
} elseif ($throw = isset($definition['resource'])) {
} elseif (isset($definition['resource']) || isset($definition['namespace'])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't add the isset checl for the namespace here, it adds confusion to me (one would then wonder how a resource can be null while namespace isn't, which contradicts the above check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then the check for namespace without resource would have to come before this conditional... Is that acceptable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, got it, the diff mislead me. Fine as is!

Copy link
Member

@nicolas-grekas nicolas-grekas Aug 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but $throw still needs to be set

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yeah in master it isn't required anymore (#22750) but in 3.4 it is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@nicolas-grekas
Copy link
Member

Thank you @kbond.

@nicolas-grekas nicolas-grekas merged commit 00d7f6f into symfony:3.4 Aug 29, 2017
nicolas-grekas added a commit that referenced this pull request Aug 29, 2017
… 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
This was referenced Oct 18, 2017
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Feb 9, 2018
…luz)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] add docs for new namespace option

| Q             | A
| ------------- | ---
| Doc fix?       | no
| New docs?      | yes
| Applies to?  | 3.4
| Fixed tickets?    | symfony/symfony#23991

Commits
-------

f395dad Reworded and turned the sidebar into a section
16e0cc7 [DI] add docs for new namespace option
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.