Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[OptionsResolver] added frozen options #17161

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

Closed
wants to merge 7 commits into from
Closed

Conversation

unexge
Copy link

@unexge unexge commented Dec 28, 2015

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

namespace Symfony\Component\OptionsResolver\Exception;

/**
* Exception thrown when a frozen option is setted.
Copy link
Contributor

Choose a reason for hiding this comment

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

/setted/set/

Copy link
Author

Choose a reason for hiding this comment

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

fixed, thanks

@javiereguiluz
Copy link
Member

Just asking: why call them "frozen options" instead of the more common "immutable options"?

@xabbuh
Copy link
Member

xabbuh commented Dec 29, 2015

How would you handle setting default values? Should it be entirely forbidden to set a default value for frozen options?

@unexge
Copy link
Author

unexge commented Dec 29, 2015

@javiereguiluz there is no specific reason. i call it frozen because, i see isFrozen in Symfony couple times.

@xabbuh IMO, only the assigned options can be frozen. i'll make a commit for that, an option can only frozen if the default value is assigned.

@xabbuh
Copy link
Member

xabbuh commented Dec 30, 2015

Can you explain a use case for such a feature?

@stof
Copy link
Member

stof commented Dec 30, 2015

@unexge a frozen DIC container is not immutable. Only some mutations are forbidden

public function setFrozen($optionNames)
{
if ($this->locked) {
throw new AccessException('Options cannot be freeze from a lazy option or normalizer.');
Copy link
Member

Choose a reason for hiding this comment

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

typo: frozen

@stof
Copy link
Member

stof commented Dec 30, 2015

Please also open a PR to the documentation to document this new feature (and reading this doc will also help understanding the goal of this feature)

@@ -658,6 +721,7 @@ public function clear()
* @return array The merged and validated options
*
* @throws UndefinedOptionsException If an option name is undefined
* @throws OptionFrozenException If a frozen option is setted
Copy link
Contributor

Choose a reason for hiding this comment

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

If a frozen option is set

@unexge
Copy link
Author

unexge commented Dec 30, 2015

@xabbuh for me: i've options, and default values came from parameters.yml. and i want to change some of them runtime, but some of them must be stay as the default. i can use the setAllowedValues for setting allowed values only the value came from parameters.yml, but this is a hack, its better to freeze options.

@stof as you saw my typos, my english is not very well 😃. so, may be, someone help for documentation. and for naming, if immutable came more make sense, we can use immutable instead of frozen.

@ogizanagi
Copy link
Contributor

@unexge : Despite the mentioned use-case, I'm currently missing the point of an option you cannot configure 😕 Why even making it an option then ?

@unexge
Copy link
Author

unexge commented Dec 30, 2015

@ogizanagi for all options came from one source. so i mean;

$options = // all options

instead of

$options = // mutable options
$frozenOptions = // frozen options

@@ -367,6 +383,59 @@ public function getDefinedOptions()
}

/**
* Freeze the option with the given name.
*
* @param string|string[] $optionNames One or more option names
Copy link
Contributor

Choose a reason for hiding this comment

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

can this really be a string?

Copy link
Author

Choose a reason for hiding this comment

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

yes, thanks to type casting

@OskarStark
Copy link
Contributor

So far the code looks reliable to me

@unexge
Copy link
Author

unexge commented Jan 8, 2016

@OskarStark thanks for the review, unnecessary phpdoc removed.

@xabbuh
Copy link
Member

xabbuh commented Jan 11, 2016

@unexge I am unsure if options that couldn't be configured at runtime really should be options. For example, when using the options resolver in a form type, I would rather register the form type as a service and inject the "unconfigurable options" in the constructor and I think there are similar approaches for other use cases where you would want to use frozen options.

@unexge
Copy link
Author

unexge commented Jan 11, 2016

@xabbuh you're right. it's really rarely use case the frozen an option. i'm closing the PR, thanks.

@unexge unexge closed this Jan 11, 2016
@ogizanagi
Copy link
Contributor

Thanks @xabbuh for succeeding into pointing out what I failed to explain 👍

@ogizanagi
Copy link
Contributor

BTW the only real use-case I see is an implementation wanting to lock an inherited option by providing its own value, and won't allow to change it.

I.e: Form type B inherits from form type A, set a default value for option foo, and won't allow to change foo back.

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.

9 participants