8000 [DI] Added _instanceof example by greg0ire · Pull Request #8496 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[DI] Added _instanceof example #8496

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
Oct 13, 2017
Merged

Conversation

greg0ire
Copy link
Contributor
@greg0ire greg0ire commented Oct 9, 2017

@HeahDude seems to be away, and I think this is badly needed in the docs, so let's carry his PR.

Closes #8239

@greg0ire
Copy link
Contributor Author
greg0ire commented Oct 9, 2017

@B-Galati @xabbuh please review


<instanceof id="AppBundle\Domain\LoaderInterface" public="true">
<tag name="app.domain_loader" />
</instanceof>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I fixed a closing tag

<services>
<!-- ... -->

<instanceof id="AppBundle\Domain\LoaderInterface" public="true">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I replaced class by id

use AppBundle\Domain\LoaderInterface;

$container->registerForAutoconfiguration(LoaderInterface::class)
->addTag('app.domain_loader');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And here I rewrote the whole thing, it looked like it was an unfinished copy/paste. I no longer use setInstanceofConditionals, not sure what's best, please tell me.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's ok to use this shortcut but unlike other formats it's missing // ... at the beginning to remind classes should be auto-registered first before being auto configured.

Maybe this function could be better documented with some extra comment, i.e: "This method returns a child definition to define the default configuration of the given class/interface.`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, addressed!

And the final big change is ``_instanceof``. It acts as a default definition
template (see `service-33-default_definition`_), but only for services whose
class matches a defined one.
This can be very useful when many services share some tag that cannot be
Copy link
Member

Choose a reason for hiding this comment

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

If you want to make this a new paragraph, there must be a blank line before it. Otherwise, I would not break lines here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean you would break them at this point of the sentence or you wouldn't break at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the sf docs standards explicitely state lines should be broken when exceeding 72 chars

@xabbuh xabbuh added this to the 3.3 milestone Oct 9, 2017
@HeahDude
Copy link
Contributor

Thanks for finishing this :).

Copy link
Contributor
@B-Galati B-Galati left a comment

Choose a reason for hiding this comment

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

Thank you 👍

@xabbuh
Copy link
Member
xabbuh commented Oct 13, 2017

Thank you @greg0ire.

@xabbuh xabbuh merged commit 691c547 into symfony:3.3 Oct 13, 2017
xabbuh added a commit that referenced this pull request Oct 13, 2017
This PR was merged into the 3.3 branch.

Discussion
----------

[DI] Added _instanceof example

@HeahDude seems to be away, and I think this is badly needed in the docs, so let's carry his PR.

Closes #8239

Commits
-------

691c547 [DI] Added _instanceof example
@greg0ire greg0ire deleted the fix/di-instanceof branch March 20, 2018 14:25

/* This method returns a child definition to define the default
configuration of the given class or interface */
$container->registerForAutoconfiguration(LoaderInterface::class)
Copy link
Member

Choose a reason for hiding this comment

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

this call is not about the _instanceof. It is about registering custom logic for services using autoconfigure.

The new PHP DSL has a syntax to define the _instanceof conditionals. The old syntax does not, because it uses the ContainerBuilder directly and so cannot provide file-scoped features.

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
0