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

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

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

{zone-data:revision}
1.0 - 23 July 2009: Initial Draft.
{zone-data}

{zone-data:overview}
Zend_Filter_StringPad is a filter which allows to extend strings to a specific length.
{zone-data}

{zone-data:references}
* [PHP's str_pad|http://php.net/str_pad]
* [Based on the StringLength Proposal - see Zend comments|http://framework.zend.com/wiki/display/ZFPROP/Zend_Filter_StringLength+-+Thomas+Weidner]
{zone-data}

{zone-data:requirements}
* This component *will* correctly handle multi byte strings.
* This component *will* support the same parameters as PHP's own str_pad method.
{zone-data}

{zone-data:dependencies}
Zend_Filter_Interface
Zend_View_Helper_Abstract
{zone-data}

{zone-data:operation}
This filter extends given strings to the wished length. It accepts and other string for extension/padding and default to whitespace if non is given.
It also supports extension from left, right or both sides.
For simplicity this component adds also a view helper which makes use of this filter.
{zone-data}

{zone-data:milestones}
* Milestone 1: \[DONE\] Proposal finished
* Milestone 2: Proposal accepted
* Milestone 3: Working implementation
* Milestone 4: Unit tests
* Milestone 5: Documentation
* Milestone 6: Moved to core
{zone-data}

{zone-data:class-list}
* Zend_Filter_StringPad
* Zend_View_Helper_StringPad
{zone-data}

{zone-data:use-cases}
||UC-01||
Extends a string to 15 chars
{code}
$filter = new Zend_Filter_StringPad(array('length' => 15);
$filter->filter('My string');
// returns 'My string '
{code}
||UC-02||
Extends a string to 15 chars, using another pad char
{code}
$filter = new Zend_Filter_StringPad(array('length' => 15, 'ending' => '.'));
$filter->filter('My string');
// returns 'My string......'
{code}
||UC-03||
Extends a string to 15 chars, using another pad char and another direction
{code}
$filter = new Zend_Filter_StringPad(array('length' => 15, 'ending' => '.', 'type' => Zend_Filter_StringPad::LEFT));
$filter->filter('My string');
// returns '......My string'
{code}
{zone-data}

{zone-data:skeletons}
{code}
class Zend_Filter_StringPad implements Zend_Filter_Interface {
constant LEFT = 'left';
constant BOTH = 'both';
constant RIGHT = 'right';

public function __construct($options);
public function getLength();
public function setLength($length);
public function getEnding();
public function setEnding();
public function getType();
public function setType($type);
}

class Zend_View_Helper_StringPad extends Zend_View_Helper_Abstract {
public function stringPad($options);
}
{code}
{zone-data}

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