Zend Framework: Zend_Filter_Boolean Component Proposal
| Proposed Component Name | Zend_Filter_Boolean |
|---|---|
| Developer Notes | http://framework.zend.com/wiki/display/ZFDEV/Zend_Filter_Boolean |
| Proposers | Thomas Weidner |
| Zend Liaison | TBD |
| Revision | 1.0 - 12 April 2009: Initial Draft. (wiki revision: 8) |
Table of Contents
1. Overview
Zend_Filter_Boolean is a additional filter which allows to filter boolean words, also localized once, to a boolean value.
2. References
3. Component Requirements, Constraints, and Acceptance Criteria
- This component will convert given values to a boolean
- This component will allow the usage of localized yes/no strings
- This component will allow to usage of "yes" or "no"
4. Dependencies on Other Framework Components
- Zend_Exception
- Zend_Filter
- Zend_Locale
5. Theory of Operation
This filter will convert given input to boolean. This will not only cast values to boolean, but also allow to use string representations like "yes" or "no" as also their localized represenation like "Ja" or "Si" and have them returned as boolean to work with them for example within a database.
6. Milestones / Tasks
- Milestone 1: [DONE] Proposal finished
- Milestone 2: [DONE] Proposal accepted
- Milestone 3: [DONE] Working implementation
- Milestone 4: [DONE] Unit tests
- Milestone 5: [DONE] Documentation
- Milestone 6: [DONE] Moved to core
7. Class Index
- Zend_Filter_Boolean
8. Use Cases
| UC-01 |
|---|
working with different types
| UC-02 |
|---|
Localized recognition, note that english is always recognised
| UC-03 |
|---|
Localized recognition by setting the locale afterwards
9. Class Skeletons
| Zend Framework Approval This proposal is approved for immediate development in the standard incubator, with the following conditions:
|
I mistakenly missed this proposal when submitting my own for a boolean filter.
Firstly, I suggest renaming to Zend_Filter_Bool for naming consistency with Zend_Filter_Int.
Below is modified text from the "theory of operation" from my proposal. I think it is important to roll the following functionality into your version, which primarily addresses only localization issues. Additionally, I hope the below will argue the case for not conforming to the way that PHP casting works:
The (bool) and (boolean) casts in PHP consider NULL and empty strings to be
FALSE, and any value that is not specifically FALSE to be TRUE. When filtering data from forms or databases, such assumptions are likely to result in logic errors.
A different set of needs is addressed by filtering as opposed to casting to boolean:
- It is not always appropriate to assume intent regarding empty or unset input. If a default value is desired, it should be defined by setting the Zend_Filter_Input::DEFAULT_VALUE metacommand, or by checking/validating for a NULL value from the results of this filter.
- It is helpful to filter for valid boolean literals used by some databases that would not be recognized when casting.
The following values should be considered FALSE:
- the boolean FALSE itself
- numeric values that equal 0 such as 0 or 0.0
- numeric strings that can be cast to the integer 0 such as "0.0" or "00"
- the string "false" (any capitalization allowed)
- the string "f" (any capitalization allowed)
- the string "no" (any capitalization allowed)
- the string "n" (any capitalization allowed)
- the string "off" (any capitalization allowed)
The following values should be considered TRUE:
- the boolean TRUE itself
- numeric values that equal 1 such as 1 or 1.0
- numeric strings that can be cast to the integer 1 such as "1.0" or "01"
- the string "true" (any capitalization allowed)
- the string "t" (any capitalization allowed)
- the string "yes" (any capitalization allowed)
- the string "y" (any capitalization allowed)
- the string "on" (any capitalization allowed)
The filter should output NULL upon attempting to process any value not listed above.
No for the renaming...
As you can read (http://framework.zend.com/wiki/display/ZFPROP/Naming+conventions+for+2.0+-+Matthew+Ratzloff) abbreviations are depreciated for components.
Zend_Validate_Int will be renamed to Zend_Validate_Integer as with ZF 2.0.
Therefor we will not add new abbreviations as preparation for 2.0.
I will comment the other suggestions as soon as I begin to work on this component in detail.
I suppose you are going to use the yes/no strings from Zend_Locale_Data? See for example at the bottom of:
http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Locale/Data/de.xml
I don't get the point of your question...
The proposal states:
This filter will convert given input to boolean. This will not only cast values to boolean, but also allow to use string representations like "yes" or "no" as also their localized represenation like "Ja" or "Si" and have them returned as boolean to work with them for example within a database.
And the implementation within incubator already has this feature available.
ZF Home Page
Code Browser
Wiki Dashboard
This is a great idea.