8628ed7ca7c0fb1bd0aa8c9076151652c006e25f
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Format / PaddingViewHelper.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 package "Fluid". *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 /**
24 * Formats a string using PHPs str_pad function.
25 * @See http://www.php.net/manual/en/function.str_pad.php
26 *
27 * = Examples =
28 *
29 * <code title="Defaults">
30 * <f:format.padding padLength="10">TYPO3</f:format.padding>
31 * </code>
32 *
33 * Output:
34 * TYPO3 (note the trailing whitespace)
35 *
36 * <code title="Specify padding string">
37 * <f:format.padding padLength="10" padString="-=">TYPO3</f:format.padding>
38 * </code>
39 *
40 * Output:
41 * TYPO3-=-=-
42 *
43 * @version $Id: PaddingViewHelper.php 3169 2009-09-10 12:52:22Z k-fish $
44 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
45 * @scope prototype
46 */
47 class Tx_Fluid_ViewHelpers_Format_PaddingViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
48
49 /**
50 * Format the arguments with the given printf format string.
51 *
52 * @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.
53 * @param string $padString The padding string
54 * @return string The formatted value
55 * @author Bastian Waidelich <bastian@typo3.org>
56 * @api
57 */
58 public function render($padLength, $padString = ' ') {
59 $string = $this->renderChildren();
60 return str_pad($string, $padLength, $padString);
61 }
62 }
63 ?>