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

[DI] Deprecate Container::isFrozen and introduce isCompiled#19673

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

Merged
fabpot merged 1 commit intosymfony:masterfromro0NL:di/separate-compilation
Mar 22, 2017
Merged

[DI] Deprecate Container::isFrozen and introduce isCompiled#19673

fabpot merged 1 commit intosymfony:masterfromro0NL:di/separate-compilation
Mar 22, 2017

Conversation

@ro0NL
Copy link
Contributor

@ro0NLro0NL commentedAug 19, 2016
edited
Loading

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

This deprecates the concept of freezing a container, implied byContainer::isFrozen. However, freezing happens due compilation (Container::compile). So having justisCompiled instead seems more intuitive, and plays along well withContainerBuilder.

Before/After;

  • Container::isFrozen
    • Checks if the parameter bag is frozen, but is deprecated in 3.2
    • In 4.0 this methods does not exists and can be replaced withgetParameterBag() instanceof FrozenParameterBagorisCompiled(). Depending on what you want (to clarify; the behavior is different when passing a frozen bag to the constructor)
  • Container::isCompiled
    • Truly checks ifcompile() has ran, and is a new feature
  • ContainerBuilder::merge etc.
    • Now usesisCompiled instead ofisFrozen, ie. we allow for it till compilation regarding the state of the paramater bag

ogizanagi, chalasr, and yceruto reacted with thumbs up emoji
@ro0NL
Copy link
ContributorAuthor

ro0NL commentedAug 19, 2016
edited
Loading

In some ways it was actually compiling (resolving the parameters), as this is also done in a compiler pass. So we can also just go withcompile() +isCompiled() on both sides. And deprecate the concept of freezing, which breaks;

Still allowing to compile a already frozen container builder.

@stof
Copy link
Member

-1 for renaming compile to freeze. This method is not only about freezing. It is about performing all the compilation steps of the container building (everything done in compiler passes for instance).

@ro0NLro0NL changed the title[DI] Deprecate Container::compile[DI] Deprecate Container::isFrozen in favor of isCompiledAug 19, 2016
@ro0NL
Copy link
ContributorAuthor

@stof different approach. WDYT?

@fabpot
Copy link
Member

I don't understand the problem you are trying to fix here. Can you elaborate? Deprecating something should be taken lightly, so we need to have a very good reason to rename something.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedAug 19, 2016
edited
Loading

It's confusing to mix&matchfreeze/is-frozen andcompile/is-compiled.isFrozen is currently enabled due compilation (ie. we practically havecompile/is-frozen). Imo, the parameter bag is frozen; the container compiled.

This exposes a minor code smell inContainerBuilder where it's additionally tracking state (ContainerBuilder::$compiled) where this is actually the same as checking if it's frozen (ie. compiled). I guess the difference was unclear back then, and you get "better be safe then sorry" changes.

* @return bool true if the container parameter bag are frozen, false otherwise
* @return bool
*/
finalpublicfunctionisCompiled()
Copy link
ContributorAuthor

@ro0NLro0NLAug 19, 2016
edited
Loading

Choose a reason for hiding this comment

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

This is now the ought to use method. If youtruly want to check for a frozen parameter bag use
getParameterBag() instanceof FrozenParameterBag instead (hence the deprecation).

Besides, this method now guarantees state ofcompile() as we dont depend on a frozen parameterbag for that anymore (which we can pass to the constructor ;-)).

Now.., i assume the calls toisFrozen inContainerBuilder (or practically anywhere) are intended asisCompilated. Which is my true point :)

Choose a reason for hiding this comment

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

Why making it final? That would be the first method in the class.

@ro0NLro0NL changed the title[DI] Deprecate Container::isFrozen in favor of isCompiled[DI] Deprecate Container::isFrozen and introduce isCompiledAug 19, 2016
if ($this->isFrozen()) {
thrownewBadMethodCallException('Cannot load from an extension on afrozen container.');
if ($this->isCompiled()) {
thrownewBadMethodCallException('Cannot load from an extension on aconpiled container.');
Copy link
Contributor

Choose a reason for hiding this comment

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

compiled

@nicolas-grekas
Copy link
Member

I tend to be sympathetic to deprecating the "frozen" vocabulary on containers. It's been looking strange to me also and the difference is unclear with the "compile" concept.isCompiled looks better.
That may enhance DX, that would be the argument supporting this change.

ogizanagi reacted with thumbs up emoji

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedAug 22, 2016
edited
Loading

Updated thePhpDumper as well.. it makes sense, but can be unpredictable when you have
new Container<Builder>(new FrozenParameterBag())

What do we expect when dumping this uncompiled (ie. we dont call$container->compile())? Currently the behavior is the same when doningnew Container<Builder>(new ParamaterBag())

@ogizanagi
Copy link
Contributor

ogizanagi commentedAug 22, 2016
edited
Loading

@ro0NL : As we do not rely anymore on the$this->parameterBag instanceof FrozenParameterBag, I'd say it doesn't matter anymore... But...you'll probably have to check if the parameterBag is frozen in theContainerBuilder::merge() method before trying to add parameters.

$this->parameterBag->resolve();

$this->parameterBag =newFrozenParameterBag($this->parameterBag->all());
if (!$this->parameterBaginstanceof FrozenParameterBag) {

Choose a reason for hiding this comment

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

This should be removed: changing the object instance of the bag can be seen as a wanted side effect of compiling. Not wrapping a FrozenParameterBag in a FrozenParameterBag looks like an unnecessary optimization to me also.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedAug 23, 2016
edited
Loading

@ogizanagi merging is only allowed before compiling. If you passed aFrozenParameterBag at that point i tend to let it crash (from the paramereter bag side that is).

Not sure what's best for DX here.. crashing or ignoring silently...

@nicolas-grekas any thoughts?

Other then that.. this is ready.

@ro0NL
Copy link
ContributorAuthor

Oh and btw... just to be sure; the YAML+XML dumper really depend on a frozen bag right? Due escaping.

@nicolas-grekas
Copy link
Member

Rebase needed to take#19704 into account.

@allflame
Copy link
Contributor

@ro0NL as far as i can see isCompiled will return false for dumped container whether or not container was compiled beforehand

@nicolas-grekas
Copy link
Member

I really don't know if this has a chance to be accepted by the core team, but let's say yes, I think we should go one step further and try deprecating dumping non-compiled containers.
WDYT?

@ro0NL
Copy link
ContributorAuthor

@allflameisCompiled depends oncompile(). The PHP dumper doesnt compile your container, it''s more or less designed to cover both cases, ie.

  • dump a compiled container(builder)
  • compile a dumped container(builder)

@allflame
Copy link
Contributor

allflame commentedAug 24, 2016
edited
Loading

@ro0NL I'm aware of that fact. Let me explain using your own statements:
SincePhpDumper has nothing to do with the compiled status, it shouldn't change it, right?
What I'm trying to say is that if you take your code, compile the container, you will getisCompiled resolving to true (correct), but if you dump it to the file and then create the container from the dumped file, you will getisCompiled resolving to false (incorrect), which is "strange" since you were dumping compiled container.
@nicolas-grekas tbh I'm not using the whole Symfony ecosystem so I cant think of implication this change can have (potential BC issues), but what I'm pretty sure of is that if you don't compile your container the "original" and "dumped" version won't necessarily be the same.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedAug 24, 2016
edited
Loading

@allflame sorry, you're right#19704 applies toisCompiled as well, i should fix that 👍

About BC, i truly consider this a design flaw andthinkhope the impact is minimal.

@ro0NL
Copy link
ContributorAuthor

Rebased. Still all good :)

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedDec 29, 2016
edited
Loading

I just realized i made a mistake with the latest deprecation:ed5b1d8#diff-f7b23d463cba27ac5e4cb677f2be7623R76

Im talkinguncompiled container here, looking at the class itshould have beennot-frozen container. I really dont mind this tiny semantic. Then again, if we dont do the PR it might be worth updating that instead... sorry :)

$this->parameterBag->resolve();
$this->parameterBag =newFrozenParameterBag($this->parameterBag->all());

$this->compiled =true;

Choose a reason for hiding this comment

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

I'd keep only this line a revert the previous changes in this method, that would prevent any potential BC-related side effect of the change.

ro0NL reacted with thumbs up emoji
*/
publicfunctionisFrozen()
{
@trigger_error(sprintf('The %s() method is deprecated as of 3.3 and will be removed in 4.0. Use the isCompiled() method instead.',__METHOD__),E_USER_DEPRECATED);

Choose a reason for hiding this comment

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

we use "since version 3.3" here usually I think

ro0NL reacted with thumbs up emoji
publicfunctioncompile()
{
if ($this->isCompiled()) {
return;

Choose a reason for hiding this comment

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

let's remove this change, it just opens a potential BC break to me

ro0NL reacted with thumbs up emoji
@nicolas-grekas
Copy link
Member

👍 with suggested changes

@ro0NL
Copy link
ContributorAuthor

Updated, rebased & waiting for travis.

Cant wait for 4.0 guys 👍

@xabbuh
Copy link
Member

@ro0NL Looks like tests fail.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedJan 11, 2017
edited
Loading

Hm.. looks fixture related, maybe something added in the meanwhile. Ill have a look tonight.

Note to self;

  • Symfony\Component\DependencyInjection\Tests\ContainerTest::testIsFrozen
  • Symfony\Component\DependencyInjection\Tests\Dumper\PhpDumperTest::testClosureProxy

@nicolas-grekas
Copy link
Member

ping@ro0NL

@ro0NL
Copy link
ContributorAuthor

Yes.. ill check it tonight. Focussed on#19668 first.. but that's more or less dealt with now.

@ro0NL
Copy link
ContributorAuthor

All good@nicolas-grekas

@fabpot
Copy link
Member

LGMT@ro0NL Can you rebase one last time? Thanks.

@ro0NL
Copy link
ContributorAuthor

@fabpot all good.

@fabpot
Copy link
Member

Thank you@ro0NL.

@fabpotfabpot merged commit6abd312 intosymfony:masterMar 22, 2017
fabpot added a commit that referenced this pull requestMar 22, 2017
…piled (ro0NL)This PR was merged into the 3.3-dev branch.Discussion----------[DI] Deprecate Container::isFrozen and introduce isCompiled| Q | A || --- | --- || Branch? | "master" || Bug fix? | no || New feature? | yes || BC breaks? | no || Deprecations? | yes || Tests pass? | yes || Fixed tickets | comma-separated list of tickets fixed by the PR, if any || License | MIT || Doc PR | reference to the documentation PR, if any |This deprecates the concept of freezing a container, implied by `Container::isFrozen`. However, freezing happens due compilation (`Container::compile`). So having just `isCompiled` instead seems more intuitive, and plays along well with `ContainerBuilder`.Before/After;- `Container::isFrozen`  - Checks if the parameter bag is frozen, but is deprecated in 3.2  - In 4.0 this methods does not exists and can be replaced with `getParameterBag() instanceof FrozenParameterBag` _or_ `isCompiled()`. Depending on what you want (to clarify; the behavior is different when passing a frozen bag to the constructor)- `Container::isCompiled`  - Truly checks if `compile()` has ran, and is a new feature- `ContainerBuilder::merge` etc.  - Now uses `isCompiled` instead of `isFrozen`, ie. we allow for it till compilation regarding the state of the paramater bagCommits-------6abd312 [DI] Deprecate Container::isFrozen and introduce isCompiled
@ro0NLro0NL deleted the di/separate-compilation branchMarch 22, 2017 19:03
if ($this->isFrozen() && (isset($this->definitions[$id]) && !$this->definitions[$id]->isSynthetic())) {
if ($this->isCompiled() && (isset($this->definitions[$id]) && !$this->definitions[$id]->isSynthetic())) {
// setting a synthetic service on a frozen container is alright
thrownewBadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a frozen container is not allowed.',$id));
Copy link
Contributor

Choose a reason for hiding this comment

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

sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id)

basically,s/frozen/compiled, no ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

😭

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed with#22112

@nicolas-grekasnicolas-grekas modified the milestones:3.x,3.3Mar 24, 2017
@fabpotfabpot mentioned this pull requestMay 1, 2017
nicolas-grekas added a commit that referenced this pull requestMay 21, 2017
This PR was squashed before being merged into the 4.0-dev branch (closes#22763).Discussion----------[DI] Remove deprecated isFrozen()| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | yes| Deprecations? | no| Tests pass?   | should be| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->| License       | MIT| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->See#19673Test failure seems unrelated.Commits-------04b39a3 [DI] Remove deprecated isFrozen()
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

+1 more reviewer

@TaluuTaluuTaluu left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

11 participants

@ro0NL@stof@fabpot@nicolas-grekas@ogizanagi@allflame@xabbuh@Taluu@GuilhemN@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp