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