19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
63 use CompileWithContentArgumentAndRenderStatic;
77 $this->registerArgument(
'value',
'int',
'The incoming data to convert, or NULL if VH children should be used');
78 $this->registerArgument(
'decimals',
'int',
'The number of digits after the decimal point',
false, 0);
79 $this->registerArgument(
'decimalSeparator',
'string',
'The decimal point character',
false,
'.');
80 $this->registerArgument(
'thousandsSeparator',
'string',
'The character for grouping the thousand digits',
false,
',');
81 $this->registerArgument(
'units',
'string',
'comma separated list of available units, default is LocalizationUtility::translate(\'viewhelper.format.bytes.units\', \'fluid\')');
93 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
95 if ($arguments[
'units'] !==
null) {
96 $units = $arguments[
'units'];
100 $units = GeneralUtility::trimExplode(
',', $units,
true);
102 $value = $renderChildrenClosure();
104 if (is_numeric($value)) {
105 $value = (float)$value;
107 if (!is_int($value) && !is_float($value)) {
110 $bytes = max($value, 0);
111 $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
112 $pow = min($pow, count($units) - 1);
113 $bytes /= pow(2, 10 * $pow);
118 round($bytes, 4 * $arguments[
'decimals']),
119 $arguments[
'decimals'],
120 $arguments[
'decimalSeparator'],
121 $arguments[
'thousandsSeparator']