<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[
<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[
Zend_Filter_Boolean is a additional filter which allows to filter boolean words, also localized once, to a boolean value.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: 9)
Table of Contents
1. Overview
2. References
3. Component Requirements, Constraints, and Acceptance Criteria
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
6 Comments
comments.show.hideApr 28, 2009
Marc Hodgins
<p>This is a great idea.</p>
Jul 14, 2009
Matthew Weier O'Phinney
<ac:macro ac:name="note"><ac:parameter ac:name="title">Zend Framework Approval</ac:parameter><ac:rich-text-body>
<p>This proposal is approved for immediate development in the standard incubator, with the following conditions:</p>
<ul>
<li>Please ensure that l10n is an optional requirement</li>
<li>Please ensure it conforms to PHP's boolean type casting</li>
</ul>
</ac:rich-text-body></ac:macro>
Aug 29, 2009
Eric Coker
<p>I mistakenly missed this proposal when submitting my own for a boolean filter.</p>
<p>Firstly, I suggest renaming to Zend_Filter_Bool for naming consistency with Zend_Filter_Int.</p>
<p>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 <strong>not</strong> conforming to the way that PHP casting works:</p>
<p>The <code>(bool)</code> and <code>(boolean)</code> casts in PHP consider <code>NULL</code> and empty strings to be <br />
<code>FALSE</code>, and any value that is not specifically <code>FALSE</code> to be <code>TRUE</code>. When filtering data from forms or databases, such assumptions are likely to result in logic errors.</p>
<p>A different set of needs is addressed by filtering as opposed to casting to boolean:</p>
<ul>
<li>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 <a href="http://framework.zend.com/manual/en/zend.filter.input.html#zend.filter.input.metacommands.default">Zend_Filter_Input::DEFAULT_VALUE</a> metacommand, or by checking/validating for a <code>NULL</code> value from the results of this filter.</li>
<li>It is helpful to filter for valid boolean literals used by some databases that would not be recognized when casting.</li>
</ul>
<p>The following values should be considered <code>FALSE</code>:</p>
<ul>
<li>the boolean <code>FALSE</code> itself</li>
<li>numeric values that equal 0 such as 0 or 0.0</li>
<li>numeric strings that can be cast to the integer 0 such as "0.0" or "00"</li>
<li>the string "false" (any capitalization allowed)</li>
<li>the string "f" (any capitalization allowed)</li>
<li>the string "no" (any capitalization allowed)</li>
<li>the string "n" (any capitalization allowed)</li>
<li>the string "off" (any capitalization allowed)</li>
</ul>
<p>The following values should be considered <code>TRUE</code>:</p>
<ul>
<li>the boolean <code>TRUE</code> itself</li>
<li>numeric values that equal 1 such as 1 or 1.0</li>
<li>numeric strings that can be cast to the integer 1 such as "1.0" or "01"</li>
<li>the string "true" (any capitalization allowed)</li>
<li>the string "t" (any capitalization allowed)</li>
<li>the string "yes" (any capitalization allowed)</li>
<li>the string "y" (any capitalization allowed)</li>
<li>the string "on" (any capitalization allowed)</li>
</ul>
<p>The filter should output <code>NULL</code> upon attempting to process any value not listed above. </p>
Aug 29, 2009
Thomas Weidner
<p>No for the renaming...</p>
<p>As you can read (<a class="external-link" href="http://framework.zend.com/wiki/display/ZFPROP/Naming+conventions+for+2.0+-+Matthew+Ratzloff">http://framework.zend.com/wiki/display/ZFPROP/Naming+conventions+for+2.0+-+Matthew+Ratzloff</a>) abbreviations are depreciated for components.<br />
Zend_Validate_Int will be renamed to Zend_Validate_Integer as with ZF 2.0.<br />
Therefor we will not add new abbreviations as preparation for 2.0.</p>
<p>I will comment the other suggestions as soon as I begin to work on this component in detail.</p>
Nov 24, 2009
Ben Scholzen
<p>I suppose you are going to use the yes/no strings from Zend_Locale_Data? See for example at the bottom of:</p>
<p><a class="external-link" href="http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Locale/Data/de.xml">http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Locale/Data/de.xml</a></p>
Nov 24, 2009
Thomas Weidner
<p>I don't get the point of your question...</p>
<p>The proposal states:</p>
<blockquote>
<p>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.</p></blockquote>
<p>And the implementation within incubator already has this feature available.</p>