Zend Framework: Zend_Filter_StringPad Component Proposal
| Proposed Component Name | Zend_Filter_StringPad |
|---|---|
| Developer Notes | http://framework.zend.com/wiki/display/ZFDEV/Zend_Filter_StringPad |
| Proposers | Thomas Weidner |
| Zend Liaison | TBD |
| Revision | 1.0 - 23 July 2009: Initial Draft. (wiki revision: 6) |
Table of Contents
1. Overview
Zend_Filter_StringPad is a filter which allows to extend strings to a specific length.
2. References
3. Component Requirements, Constraints, and Acceptance Criteria
- This component will correctly handle multi byte strings.
- This component will support the same parameters as PHP's own str_pad method.
4. Dependencies on Other Framework Components
Zend_Filter_Interface
Zend_View_Helper_Abstract
5. Theory of 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.
6. Milestones / Tasks
- 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
7. Class Index
- Zend_Filter_StringPad
- Zend_View_Helper_StringPad
8. Use Cases
| UC-01 |
|---|
Extends a string to 15 chars
| UC-02 |
|---|
Extends a string to 15 chars, using another pad char
| UC-03 |
|---|
Extends a string to 15 chars, using another pad char and another direction
9. Class Skeletons
Labels:
None
9 Comments
comments.show.hideAug 05, 2009
fc
-1
Voted down because this filter is a wrapper of the str_pad() function. This is the same as creating a wrapper of the strtolower() function or any other PHP function. what's the purpose of doing something like that?
Aug 05, 2009
Thomas Weidner
There is an existing Zend_Filter_StringToLower.
For this decission there are 2 reasons:
1.) str_pad and co are not binary aware... they can not handle UTF-8
2.) many ZF components make use of filters. For a user it's simpler and more common to call
than calling
Aug 07, 2009
fc
I don't recall anyone complaining about str_pad not being able to handle encodings properly in the last 10 years or so. If you beleive the str_pad function is buggy, then you should create a proposal or commit a patch to the php project instead. But not create a wrapper for each php function.
The same goes for strtolower, and similar classes added to the framework.
Aug 28, 2009
Thomas Weidner
So Zend_Filter, Zend_Validate, Zend_Date, Zend_Currency, Zend_Memory, Zend_Cache are some of the components which should be erased in your opinion because php has functions which work partitially similar ?
I thought the reason for proposals is simplicity and usability for ZF ?
Jul 28, 2010
Dolf Schimmel (Freeaqingme)
Thomas, could you please give a url where the multibyte limitation in php's native str_pad() function is described?
Jul 30, 2010
Thomas Weidner
See this long opened bug here: http://bugs.php.net/bug.php?id=21317
But this is not the main reason for this proposal... just one of the things which could be done with it.
Jul 30, 2010
Dolf Schimmel (Freeaqingme)
If that is not the main reason for this proposal, what is? One can always call str_pad() through the callback filter after all.
Aug 03, 2010
Shaun Farrell
The CR Team advises that this proposal be approved, and would like to have clarification on option names as they may cause confusion.
Aug 03, 2010
Thomas Weidner
'length' => length of string to pad (integer)
'type' => type of padding to use (constant/integer)
'pad' => string used to pad (string)
'truncate' => if pad string is allowed to be truncated when it extends length (boolean)