\CodeIgniter\API\JSONFormatter::class, 'application/xml' => \CodeIgniter\API\XMLFormatter::class ]; //-------------------------------------------------------------------- /** * A Factory method to return the appropriate formatter for the given mime type. * * @param string $mime * * @return mixed */ 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(); } //-------------------------------------------------------------------- }