View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFPROP:Proposal Zone Template}

{zone-data:component-name}
Zend_Filter_Boolean
{zone-data}

{zone-data:proposer-list}
[~thomas]
{zone-data}

{zone-data:liaison}
TBD
{zone-data}

{zone-data:revision}
1.0 - 12 April 2009: Initial Draft.
{zone-data}

{zone-data:overview}
Zend_Filter_Boolean is a additional filter which allows to filter boolean words, also localized once, to a boolean value.
{zone-data}

{zone-data:references}
* [Zend_Filter|http://framework.zend.com/manual/en/zend.filter.html]
* [Zend_Locale|http://framework.zend.com/manual/en/zend.locale.html]
{zone-data}

{zone-data:requirements}
* 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"
{zone-data}

{zone-data:dependencies}
* Zend_Exception
* Zend_Filter
* Zend_Locale
{zone-data}

{zone-data: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.
{zone-data}

{zone-data:milestones}
* 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
{zone-data}

{zone-data:class-list}
* Zend_Filter_Boolean
{zone-data}

{zone-data:use-cases}
||UC-01||
working with different types
{code}
$filter = new Zend_Filter_Boolean();

$filtered = $filter->filter(false); // returns false
$filtered = $filter->filter(true); // returns true

$filtered = $filter->filter(0); // returns false
$filtered = $filter->filter(1); // returns true

$filtered = $filter->filter(-1); // returns false
$filtered = $filter->filter(200); // returns true

$filtered = $filter->filter('yes'); // returns true
$filtered = $filter->filter('no'); // returns false
$filtered = $filter->filter('YES'); // returns true
{code}
||UC-02||
Localized recognition, note that english is always recognised
{code}
$filter = new Zend_Filter_Boolean('de');

$filtered = $filter->filter('Ja'); // returns true
$filtered = $filter->filter('Nein'); // returns false
{code}
||UC-03||
Localized recognition by setting the locale afterwards
{code}
$filter = new Zend_Filter_Boolean();
$filter->setLocale('de');

$filtered = $filter->filter('Ja'); // returns true
$filtered = $filter->filter('Nein'); // returns false
{code}
{zone-data}

{zone-data:skeletons}
{code}
class Zend_Filter_Boolean extends Zend_Filter_Interface {}
{
/**
* @param $locale string|Zend_Locale (Optional) Locale to use
*/
public function __construct($locale = null)

/**
* @param $locale string|Zend_Locale (Optional) Locale to use
* @return Zend_Filter_Boolean
*/
public function setLocale($locale = null)

/**
* @return string
*/
public function getLocale()

/**
* @param $value mixed Value to filter
* @param $locale string|Zend_Locale (Optional) Locale to use
* @return Zend_Filter_Boolean
*/
public function filter($value, $locale = null)

}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>