Return FALSE from createComponent<name> to ignore the factory
- redwormik
- Member | 6
Hi there!
I intend to create a pull request, but I want to get some opinions first.
I miss the option to NOT return the component from my createComponentFoo method. For example, I want the component to be available only on certain actions / when the user is logged in / etc. I want the app to 500 when the component is needed (e. g. I forgot add the condition around {control foo}), but I want it to be ignored when it isn't (e. g. malicious user tries to access it and doesn't have the permissions).
Current implementation prevents this, because when you reach your factory method, you get an UnexpectedValueException unless you return/add the component. (I assume this is to get better exception if you forget to return the component.)
I propose to treat FALSE as a special return value, i. e. the factory does not want the component to be created and should therefore be ignored.
The source:
https://github.com/…7b551a1765d9
The alternative (and maybe better design) would be to use an exception, but I like the simplicity of FALSE.
What do you think?
- redwormik
- Member | 6
You can return NULL from createComponent(), but not from createComponentFoo(), unless you override Container's createComponent(). (It throws UnexpectedValueException.)
I get why “special value” is frowned upon and maybe exception is a better approach.
Last edited by redwormik (2014-10-06 11:39)