Neos\Flow\I18n\FormatResolver::getFormatter PHP Method

getFormatter() protected method

The type provided has to be either a name of existing class placed in I18n\Formatter namespace or a fully qualified class name; in both cases implementing this' package's FormatterInterface. For example, when $formatterName is 'number', the I18n\Formatter\NumberFormatter class has to exist; when $formatterName is 'Acme\Foobar\I18nFormatter\SampleFormatter', this class must exist and implement I18n\Formatter\FormatterInterface. Throws exception if there is no formatter for name given or one could be retrieved but does not satisfy the FormatterInterface.
protected getFormatter ( string $formatterType ) : Neos\Flow\I18n\Formatter\FormatterInterface
$formatterType string Either one of the built-in formatters or fully qualified formatter class name
return Neos\Flow\I18n\Formatter\FormatterInterface The concrete formatter class
    protected function getFormatter($formatterType)
    {
        $foundFormatter = false;
        $formatterType = ltrim($formatterType, '\\');
        if (isset($this->formatters[$formatterType])) {
            $foundFormatter = $this->formatters[$formatterType];
        }
        if ($foundFormatter === false) {
            if ($this->objectManager->isRegistered($formatterType)) {
                $possibleClassName = $formatterType;
            } else {
                $possibleClassName = sprintf('Neos\\Flow\\I18n\\Formatter\\%sFormatter', ucfirst($formatterType));
                if (!$this->objectManager->isRegistered($possibleClassName)) {
                    throw new Exception\UnknownFormatterException('Could not find formatter for "' . $formatterType . '".', 1278057791);
                }
            }
            if (!$this->reflectionService->isClassImplementationOf($possibleClassName, Formatter\FormatterInterface::class)) {
                throw new Exception\InvalidFormatterException(sprintf('The resolved internationalization formatter class name "%s" does not implement "%s" as required.', $possibleClassName, FormatterInterface::class), 1358162557);
            }
            $foundFormatter = $this->objectManager->get($possibleClassName);
        }
        $this->formatters[$formatterType] = $foundFormatter;
        return $foundFormatter;
    }