\CodeIgniter\Format\JSONFormatter::class, 'application/xml' => \CodeIgniter\Format\XMLFormatter::class, 'text/xml' => \CodeIgniter\Format\XMLFormatter::class, ]; //-------------------------------------------------------------------- /** * A Factory method to return the appropriate formatter for the given mime type. * * @param string $mime * * @return \CodeIgniter\Format\FormatterInterface */ public function getFormatter(string $mime) { if (! array_key_exists($mime, $this->formatters)) { throw new \InvalidArgumentException('No Formatter defined for mime type: ' . $mime); } $class = $this->formatters[$mime]; if (! class_exists($class)) { throw new \BadMethodCallException($class . ' is not a valid Formatter.'); } return new $class(); } //-------------------------------------------------------------------- }