TYPO3 CMS  TYPO3_7-6
CaseViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
20 
66 {
70  const CASE_LOWER = 'lower';
71 
75  const CASE_UPPER = 'upper';
76 
80  const CASE_CAPITAL = 'capital';
81 
85  const CASE_UNCAPITAL = 'uncapital';
86 
90  const CASE_CAPITAL_WORDS = 'capitalWords';
91 
95  protected static $charsetConverter = null;
96 
105  public function render($value = null, $mode = self::CASE_UPPER)
106  {
107  return static::renderStatic(
108  [
109  'value' => $value,
110  'mode' => $mode,
111  ],
113  $this->renderingContext
114  );
115  }
116 
127  {
128  $value = $arguments['value'];
129  $mode = $arguments['mode'];
130 
131  if ($value === null) {
132  $value = $renderChildrenClosure();
133  }
134 
135  if (is_null(static::$charsetConverter)) {
136  static::$charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
137  }
138  $charsetConverter = static::$charsetConverter;
139 
140  switch ($mode) {
141  case self::CASE_LOWER:
142  $output = $charsetConverter->conv_case('utf-8', $value, 'toLower');
143  break;
144  case self::CASE_UPPER:
145  $output = $charsetConverter->conv_case('utf-8', $value, 'toUpper');
146  break;
147  case self::CASE_CAPITAL:
148  $output = $charsetConverter->utf8_substr($charsetConverter->convCaseFirst('utf-8', $value, 'toUpper'), 0, 1) . $charsetConverter->utf8_substr($value, 1);
149  break;
150  case self::CASE_UNCAPITAL:
151  $output = $charsetConverter->utf8_substr($charsetConverter->convCaseFirst('utf-8', $value, 'toLower'), 0, 1) . $charsetConverter->utf8_substr($value, 1);
152  break;
153  case self::CASE_CAPITAL_WORDS:
154  // @todo: Implement method once there is a proper solution with using the CharsetConverter
155  default:
156  throw new InvalidVariableException('The case mode "' . $mode . '" supplied to Fluid\'s format.case ViewHelper is not supported.', 1358349150);
157  }
158 
159  return $output;
160  }
161 }
render($value=null, $mode=self::CASE_UPPER)
static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)