-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/setted/set/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks
Just asking: why call them "frozen options" instead of the more common "immutable options"? |
How would you handle setting default values? Should it be entirely forbidden to set a default value for frozen options? |
@javiereguiluz there is no specific reason. i call it frozen because, i see @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. |
Can you explain a use case for such a feature? |
@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.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: frozen
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 |
There was a problem hiding this comment.
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
@xabbuh for me: i've options, and default values came from @stof as you saw my typos, my english is not very well 😃. so, may be, someone help for documentation. and for naming, if |
@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 ? |
@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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
So far the code looks reliable to me |
@OskarStark thanks for the review, unnecessary phpdoc removed. |
@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. |
@xabbuh you're right. it's really rarely use case the frozen an option. i'm closing the PR, thanks. |
Thanks @xabbuh for succeeding into pointing out what I failed to explain 👍 |
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 |