TYPO3 API  SVNRelease
PrintfViewHelper.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*                                                                        *
00004  * This script belongs to the FLOW3 package "Fluid".                      *
00005  *                                                                        *
00006  * It is free software; you can redistribute it and/or modify it under    *
00007  * the terms of the GNU Lesser General Public License as published by the *
00008  * Free Software Foundation, either version 3 of the License, or (at your *
00009  * option) any later version.                                             *
00010  *                                                                        *
00011  * This script is distributed in the hope that it will be useful, but     *
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00013  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
00014  * General Public License for more details.                               *
00015  *                                                                        *
00016  * You should have received a copy of the GNU Lesser General Public       *
00017  * License along with the script.                                         *
00018  * If not, see http://www.gnu.org/licenses/lgpl.html                      *
00019  *                                                                        *
00020  * The TYPO3 project - inspiring people to share!                         *
00021  *                                                                        */
00022 
00023 /**
00024  * A view helper for formatting values with printf. Either supply an array for
00025  * the arguments or a single value.
00026  * See http://www.php.net/manual/en/function.sprintf.php
00027  *
00028  * = Examples =
00029  *
00030  * <code title="Scientific notation">
00031  * <f:format.printf arguments="{number: 362525200}">%.3e</f:format.printf>
00032  * </code>
00033  * <output>
00034  * 3.625e+8
00035  * </output>
00036  *
00037  * <code title="Argument swapping">
00038  * <f:format.printf arguments="{0: 3, 1: 'Kasper'}">%2$s is great, TYPO%1$d too. Yes, TYPO%1$d is great and so is %2$s!</f:format.printf>
00039  * </code>
00040  * <output>
00041  * Kasper is great, TYPO3 too. Yes, TYPO3 is great and so is Kasper!
00042  * </output>
00043  *
00044  * <code title="Single argument">
00045  * <f:format.printf arguments="{1: 'TYPO3'}">We love %s</f:format.printf>
00046  * </code>
00047  * <output>
00048  * We love TYPO3
00049  * </output>
00050  *
00051  * <code title="Inline notation">
00052  * {someText -> f:format.printf(arguments: {1: 'TYPO3'})}
00053  * </code>
00054  * <output>
00055  * We love TYPO3
00056  * </output>
00057  *
00058  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
00059  * @api
00060  */
00061 class Tx_Fluid_ViewHelpers_Format_PrintfViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
00062 
00063     /**
00064      * Format the arguments with the given printf format string.
00065      *
00066      * @param array $arguments The arguments for vsprintf
00067      * @return string The formatted value
00068      * @author Christopher Hlubek <hlubek@networkteam.com>
00069      * @author Bastian Waidelich <bastian@typo3.org>
00070      * @api
00071      */
00072     public function render(array $arguments) {
00073         $format = $this->renderChildren();
00074         return vsprintf($format, $arguments);
00075     }
00076 }
00077 ?>