‪TYPO3CMS  10.4
PaddingViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
22 
61 class ‪PaddingViewHelper extends AbstractViewHelper
62 {
63  use CompileWithContentArgumentAndRenderStatic;
64 
70  protected ‪$escapeChildren = false;
71 
77  public function ‪initializeArguments()
78  {
79  $this->registerArgument('value', 'string', 'string to format');
80  $this->registerArgument('padLength', 'int', '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.', true);
81  $this->registerArgument('padString', 'string', 'The padding string', false, ' ');
82  $this->registerArgument('padType', 'string', 'Append the padding at this site (Possible values: right,left,both. Default: right)', false, 'right');
83  }
84 
93  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
94  {
95  $value = $renderChildrenClosure();
96  $padTypes = [
97  'left' => STR_PAD_LEFT,
98  'right' => STR_PAD_RIGHT,
99  'both' => STR_PAD_BOTH
100  ];
101  $padType = $arguments['padType'];
102  if (!isset($padTypes[$padType])) {
103  $padType = 'right';
104  }
105 
106  return ‪StringUtility::multibyteStringPad((string)$value, $arguments['padLength'], $arguments['padString'], $padTypes[$padType]);
107  }
108 }
‪TYPO3\CMS\Fluid\ViewHelpers\Format\PaddingViewHelper
Definition: PaddingViewHelper.php:62
‪TYPO3\CMS\Fluid\ViewHelpers\Format\PaddingViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: PaddingViewHelper.php:91
‪TYPO3\CMS\Fluid\ViewHelpers\Format
Definition: AbstractEncodingViewHelper.php:16
‪TYPO3\CMS\Fluid\ViewHelpers\Format\PaddingViewHelper\initializeArguments
‪initializeArguments()
Definition: PaddingViewHelper.php:75
‪TYPO3\CMS\Fluid\ViewHelpers\Format\PaddingViewHelper\$escapeChildren
‪bool $escapeChildren
Definition: PaddingViewHelper.php:68
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Utility\StringUtility\multibyteStringPad
‪static string multibyteStringPad(string $string, int $length, string $pad_string=' ', int $pad_type=STR_PAD_RIGHT, string $encoding='UTF-8')
Definition: StringUtility.php:165