Neos\FluidAdaptor\ViewHelpers\Format\CaseViewHelper::render PHP Method

render() public method

Changes the case of the input string
public render ( string $value = null, string $mode = self::CASE_UPPER ) : string
$value string The input value. If not given, the evaluated child nodes will be used
$mode string The case to apply, must be one of this' CASE_* constants. Defaults to uppercase application
return string the altered string.
    public function render($value = null, $mode = self::CASE_UPPER)
    {
        if ($value === null) {
            $value = $this->renderChildren();
        }
        $originalEncoding = mb_internal_encoding();
        mb_internal_encoding('UTF-8');
        switch ($mode) {
            case self::CASE_LOWER:
                $output = mb_convert_case($value, \MB_CASE_LOWER);
                break;
            case self::CASE_UPPER:
                $output = mb_convert_case($value, \MB_CASE_UPPER);
                break;
            case self::CASE_CAPITAL:
                $output = mb_substr(mb_convert_case($value, \MB_CASE_UPPER), 0, 1) . mb_substr($value, 1);
                break;
            case self::CASE_UNCAPITAL:
                $output = mb_substr(mb_convert_case($value, \MB_CASE_LOWER), 0, 1) . mb_substr($value, 1);
                break;
            case self::CASE_CAPITAL_WORDS:
                $output = mb_convert_case($value, \MB_CASE_TITLE);
                break;
            default:
                mb_internal_encoding($originalEncoding);
                throw new InvalidVariableException('The case mode "' . $mode . '" supplied to Fluid\'s format.case ViewHelper is not supported.', 1358349150);
        }
        mb_internal_encoding($originalEncoding);
        return $output;
    }

Usage Example

 /**
  * @test
  * @dataProvider conversionTestingDataProvider
  */
 public function viewHelperConvertsCorrectly($input, $mode, $expected)
 {
     $this->assertSame($expected, $this->viewHelper->render($input, $mode), sprintf('The conversion with mode "%s" did not perform as expected.', $mode));
 }
CaseViewHelper