Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[DependencyInjection] Allow for synthetic services before compilation#19619

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
ro0NL wants to merge0 commits intosymfony:masterfromro0NL:dependency-injection/container-builder-synthetics
Closed

[DependencyInjection] Allow for synthetic services before compilation#19619

ro0NL wants to merge0 commits intosymfony:masterfromro0NL:dependency-injection/container-builder-synthetics

Conversation

@ro0NL
Copy link
Contributor

@ro0NLro0NL commentedAug 15, 2016
edited
Loading

QA
Branch?"master"
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketscomma-separated list of tickets fixed by the PR, if any
LicenseMIT
Doc PRreference to the documentation PR, if any

Separated from#19606

This allows accessing synthetic services fromContainerBuilder::get before compilation, besides they are exposed while extension loading.

It covers 2 usecases;

  • synthetic service + synthetic definition (like before, but getting the service is allowed)
  • synthetic service + non-synthetic definition (new feature =>ServiceAwareDefinition which covers both usecases as well)

}

foreach ($container->getSynthetics()as$id =>$service) {
$tmpContainer->set($id,$service);
Copy link
ContributorAuthor

@ro0NLro0NLAug 15, 2016
edited
Loading

Choose a reason for hiding this comment

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

Concerning BC: all services set viaPrependExtensionInterface::prepend are now available while extension loading. Or any other service available at this point.

The services set while loading are not merged back into the container, this is perhaps considerable.

@GuilhemN
Copy link
Contributor

@ro0NL as#19608 is merged, I guess you can close this one ? :)

@ogizanagi
Copy link
Contributor

ogizanagi commentedAug 16, 2016
edited
Loading

@Ener-Getick : My PR was only removing "dead code". It doesn't un-deprecate getting a service instance from theContainerBuilder.

But I'm not convinced we need something like the newServiceAwareDefinition. We could simply consider any service set usingContainerBuilder::set should be a "building-time only" service and allow to get it, but won't be available after compilation. It feels weird and I'm not convinced by this "feature" neither, but currently services set directly in theContainerBuilder are vanished after compilation anyway.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedAug 16, 2016
edited
Loading

Most important is the logic ofContainerBuider::get +MergeExtensionConfigurationPass::process for now.

ServiceAwareDefinition is somewhat a shortcut forset() +setDefinition(), so this can be left out yes. Consider it a poc :)

edit: @Ener-Getick i can rebase.. :)

@ro0NL
Copy link
ContributorAuthor

@ogizanagi theServiceAwareDefinition allows for having the service+definition at the same time, asset()overwrites definitions for the same id.

So if you have a non-synthetic definition + the ready to use service, you are stuck now. Not sure how common that is, on the other hand#19606 is poc of exactly that.

@ogizanagi
Copy link
Contributor

ogizanagi commentedAug 16, 2016
edited
Loading

@ro0NL : My point is that you probably don't need having a service definition for services designed to be used during the container building time only (but is it even a good idea to depend on any kind of service in this phase ?). :/
I think that's the only thing needed for the use-case of exposing kernel & bundles "metadata".
Otherwise, either you'll get a service definition into the compiled container that will never be used at runtime, either you'll have to set the service twice (during and after the container is compiled).

Thusmy suggestion about exposing abooting_kernel during the container build, which would simply be aKernelInterface decorator throwing an exception for unsafe methods, and will never be available at runtime (use thekernel service then). ^^

EDIT:

So if you have a non-synthetic definition + the ready to use service, you are stuck now. Not sure how common that is

As you said, not sure there are real use cases for this. Why would you need a container to build a service you're able to build yourself and would not be used at runtime ? Eventually you only need a way to share things during compilation time.
I think we're probably going in the wrong direction. TheContainerBuilder should probably not behaves as aContainer. Maybe theContainerBuilder is only missing ashared context somehow (immutable or locked at some point preferably. It's not safe to rely on if things can be put in at different building phases such as in the extension loading).

chalasr, sstok, and yceruto reacted with thumbs up emoji

@ro0NL
Copy link
ContributorAuthor

Could be.. this is just a generic approach that allows for it. If the component really needs it, i dont know. Perhaps nice to have. But yeah, my usecase is definitely kernel+bundles ;-)

Abooting_kernel service will also do 👍

@ogizanagi
Copy link
Contributor

ogizanagi commentedAug 16, 2016
edited
Loading

@ro0NL : regarding the part I've added after editingmy comment above, here is a naive & straightforward implementation of a contextualized container builder, allowing to share some context during the build time, before compilation of the container:master...ogizanagi:contextualized_container

Here, theContext is locked right before callingCompiler::compile, ensuring nothing can mutate it appart from theKernel::getContainerBuilder() method (actually,Kernel::registerContainerConfiguration() andBundleInterface::boot() can too). But we can imagine (if legit) locking the context only after some point (in a dedicated compiler pass), making the context mutable at some point (extensions) but "safe to use" only in compiler passes (which is where people tended to rely wrongly on services before the container was build before theContainerBuilder::get() method was deprecated).

Of course, I don't expect this to be a perfect nor legit implementation, but simply exploring and giving more hints on how to proceed considering your uses cases. :)

@ro0NL
Copy link
ContributorAuthor

@ogizanagi im thinking this thru.. maybe you're right on how we try to solve this and not being the right direction. It feels workaroundish i guess.

The ContainerBuilder should probably not behaves as a Container

  • Makes sense. Period. (before/while compilation that is)
  • How does this reflectContainerBuilder::set? Should it even be allowed then?

I was also heading "context" way, and just had a crazy idea:ContainerBuilder::getContext():Container.

@ogizanagi
Copy link
Contributor

ogizanagi commentedAug 16, 2016
edited
Loading

How does this reflect ContainerBuilder::set? Should it even be allowed then?

Indeed, it should not. I guess it was part of the idea behind theget deprecation, but it still allows to set synthetic services, which are vanished after compilation, and moreover not merged during build phase. So it may not allow callingset at all.

ContainerBuilder::getContext():Container

Yeah...thought about that too, but I'm not fan of giving visibility to the fact we use a container to build a container... 😅 At least the foolish lockableContext implementation hides that fact a little.

@ro0NL
Copy link
ContributorAuthor

I dont mind :) I think we're too much used toone container being the almighty thing. It's a pattern, eventually it's legit 😉

Another, bridge too far, idea; each bundle defines it's own container(s) in the ecosystem. Container as a service 😱

Anyway, maybe focus this PR on deprecatingset() first then? So at least the current behavior is consistent and clear.

ogizanagi reacted with laugh emoji

@ogizanagi
Copy link
Contributor

Anyway, maybe focus this PR on deprecating set() first then? So at least the current behavior is consistent and clear.

IMHO it should be the subject of another PR deprecating the wholeset usage.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@ro0NL@GuilhemN@ogizanagi@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp