5
use CodeIgniter\Config\BaseConfig;
6
use CodeIgniter\Format\FormatterInterface;
7
use CodeIgniter\Format\JSONFormatter;
8
use CodeIgniter\Format\XMLFormatter;
10
class Format extends BaseConfig
13
* --------------------------------------------------------------------------
14
* Available Response Formats
15
* --------------------------------------------------------------------------
17
* When you perform content negotiation with the request, these are the
18
* available formats that your application supports. This is currently
19
* only used with the API\ResponseTrait. A valid Formatter must exist
20
* for the specified format.
22
* These formats are only checked when the data passed to the respond()
27
public array $supportedResponseFormats = [
29
'application/xml', // machine-readable XML
30
'text/xml', // human-readable XML
34
* --------------------------------------------------------------------------
36
* --------------------------------------------------------------------------
38
* Lists the class to use to format responses with of a particular type.
39
* For each mime type, list the class that should be used. Formatters
40
* can be retrieved through the getFormatter() method.
42
* @var array<string, string>
44
public array $formatters = [
45
'application/json' => JSONFormatter::class,
46
'application/xml' => XMLFormatter::class,
47
'text/xml' => XMLFormatter::class,
51
* --------------------------------------------------------------------------
53
* --------------------------------------------------------------------------
55
* Additional Options to adjust default formatters behaviour.
56
* For each mime type, list the additional options that should be used.
58
* @var array<string, int>
60
public array $formatterOptions = [
61
'application/json' => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES,
62
'application/xml' => 0,
67
* A Factory method to return the appropriate formatter for the given mime type.
69
* @return FormatterInterface
71
* @deprecated This is an alias of `\CodeIgniter\Format\Format::getFormatter`. Use that instead.
73
public function getFormatter(string $mime)
75
return Services::format()->getFormatter($mime);