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

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

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

{zone-data:revision}
1.0 - 8 August 2009: Initial Draft.
{zone-data}

{zone-data:overview}
Zend_Filter_StringTruncate is a filter which truncates strings, regardless of their content.
{zone-data}

{zone-data:references}
* [PHP's substr|http://php.net/substr]
* [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* truncate strings at a given length
* This component *will* also handle multibyte strings
{zone-data}

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

{zone-data:operation}
This filter truncates strings to a given length. It's the reverse filter for the [StringPad Filter|http://framework.zend.com/wiki/display/ZFPROP/Zend_Filter_StringPad+-++Thomas+Weidner].
For simplicity this filter also adds 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_StringTruncate
* Zend_View_Helper_StringTruncate
{zone-data}

{zone-data:use-cases}
||UC-01||
Truncate a string at 6 chars
{code}
$filter = new Zend_Filter_StringTruncate(array('length' => 6));
$filter->filter('My string');
// returns 'My str'
{code}
||UC-02||
Truncate a string at 6 chars, using ending chars
{code}
$filter = new Zend_Filter_StringTruncate(array('length' => 6, 'ending' => '..'));
$filter->filter('My string');
// returns 'My s..'
{code}
||UC-03||
Truncate a string at 6 chars, using ending chars and additionally get the truncated content
{code}
$filter = new Zend_Filter_StringTruncate(array('length' => 6, 'ending' => '..'));
$filter->filter('My string');
// returns 'My s..'
$filter->getTruncated();
// returns 'tring'
{code}
||UC-04||
Truncate a string at 6 chars but from the other side
{code}
$filter = new Zend_Filter_StringTruncate(array('length' => 6, 'direction' => Zend_Filter_StringTruncate::LEFT));
$filter->filter('My string');
// returns 'string'
{code}
{zone-data}

{zone-data:skeletons}
{code}
class Zend_Filter_StringTruncate 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 getDirection();
public function setDirection($direction);
public function getTruncated($value = null);
public function filter($value);
}

class Zend_View_Helper_StringTruncate extends Zend_View_Helper_Abstract {
public function stringTruncate($value);
}
{code}
{zone-data}

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