/**
  * Inits specific formatter class by format name.
  *
  * @param string $name
  *
  * @return array
  *
  * @throws \RuntimeException
  */
 public function initFormatter($name)
 {
     if (isset($this->dispatchers[strtolower($name)])) {
         $dispatcher = $this->dispatchers[strtolower($name)];
     } elseif (class_exists($name)) {
         $dispatcher = new FormatterDispatcher($name);
     } else {
         throw new \RuntimeException("Unknown formatter: \"{$name}\". " . 'Available formatters are: ' . implode(', ', array_keys($this->dispatchers)));
     }
     $formatter = $dispatcher->createFormatter();
     $formatter->setTranslator($this->translator);
     $this->eventDispatcher->addSubscriber($formatter, -5);
     return $this->formatters[] = $formatter;
 }
예제 #2
0
 /**
  * Adds formatter dispatcher to the manager.
  *
  * @param FormatterDispatcher $dispatcher Formatter dispatcher
  */
 public function addDispatcher(FormatterDispatcher $dispatcher)
 {
     $this->dispatchers[$dispatcher->getName()] = $dispatcher;
 }