[FEATURE] PaddingViewHelper: allow padding-type right/left/both
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Sat, 11 Jun 2011 15:20:32 +0000 (17:20 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sat, 11 Jun 2011 15:20:32 +0000 (17:20 +0200)
Adding 4th parameter of str_pad() to the ViewHelper

Change-Id: I3120e2ae9970c50fc525728168d3828166d09f23
Resolves: #9283

typo3/sysext/fluid/Classes/ViewHelpers/Format/PaddingViewHelper.php

index 9fa1148..7ebd085 100644 (file)
  * TYPO3-=-=-
  * </output>
  *
+ * <code title="Specify padding string and padding type">
+ * <f:format.padding padLength="10" padString="-" padType="both">TYPO3</f:format.padding>
+ * </code>
+ * <output>
+ * --TYPO3---
+ * </output>
+ *
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  * @api
  */
@@ -50,13 +57,25 @@ class Tx_Fluid_ViewHelpers_Format_PaddingViewHelper extends Tx_Fluid_Core_ViewHe
         *
         * @param integer $padLength Length of the resulting string. If the value of pad_length is negative or less than the length of the input string, no padding takes place.
         * @param string $padString The padding string
+        * @param string $padType The padding type ("right", "left" or "both")
         * @return string The formatted value
         * @author Bastian Waidelich <bastian@typo3.org>
         * @api
         */
-       public function render($padLength, $padString = ' ') {
+       public function render($padLength, $padString = ' ', $padType = '') {
                $string = $this->renderChildren();
-               return str_pad($string, $padLength, $padString);
+               switch (strtoupper($padType)) {
+                       case 'LEFT':
+                               $padding = STR_PAD_LEFT;
+                               break;
+                       case 'BOTH':
+                               $padding = STR_PAD_BOTH;
+                               break;
+                       case 'RIGHT':
+                       default:
+                               $padding = STR_PAD_RIGHT;
+               }
+               return str_pad($string, $padLength, $padString, $padding);
        }
 }
 ?>
\ No newline at end of file