2020-08-29 20:50:35 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Config;
|
2016-11-24 00:02:36 -06:00
|
|
|
|
|
|
|
use CodeIgniter\Config\BaseConfig;
|
2020-10-04 00:27:56 +07:00
|
|
|
use CodeIgniter\Format\FormatterInterface;
|
2022-03-19 22:52:14 +07:00
|
|
|
use CodeIgniter\Format\JSONFormatter;
|
|
|
|
use CodeIgniter\Format\XMLFormatter;
|
2016-11-24 00:02:36 -06:00
|
|
|
|
2017-04-02 21:57:04 -05:00
|
|
|
class Format extends BaseConfig
|
2016-11-24 00:02:36 -06:00
|
|
|
{
|
2021-06-04 22:51:52 +08:00
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
* Available Response Formats
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* When you perform content negotiation with the request, these are the
|
|
|
|
* available formats that your application supports. This is currently
|
|
|
|
* only used with the API\ResponseTrait. A valid Formatter must exist
|
|
|
|
* for the specified format.
|
|
|
|
*
|
|
|
|
* These formats are only checked when the data passed to the respond()
|
|
|
|
* method is an array.
|
|
|
|
*
|
|
|
|
* @var string[]
|
|
|
|
*/
|
|
|
|
public $supportedResponseFormats = [
|
|
|
|
'application/json',
|
|
|
|
'application/xml', // machine-readable XML
|
|
|
|
'text/xml', // human-readable XML
|
|
|
|
];
|
2016-11-24 00:02:36 -06:00
|
|
|
|
2021-06-04 22:51:52 +08:00
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
* Formatters
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Lists the class to use to format responses with of a particular type.
|
|
|
|
* For each mime type, list the class that should be used. Formatters
|
|
|
|
* can be retrieved through the getFormatter() method.
|
|
|
|
*
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
|
|
|
public $formatters = [
|
2022-03-19 22:52:14 +07:00
|
|
|
'application/json' => JSONFormatter::class,
|
|
|
|
'application/xml' => XMLFormatter::class,
|
|
|
|
'text/xml' => XMLFormatter::class,
|
2021-06-04 22:51:52 +08:00
|
|
|
];
|
2020-07-29 01:54:07 +08:00
|
|
|
|
2021-06-04 22:51:52 +08:00
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
* Formatters Options
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Additional Options to adjust default formatters behaviour.
|
|
|
|
* For each mime type, list the additional options that should be used.
|
|
|
|
*
|
|
|
|
* @var array<string, int>
|
|
|
|
*/
|
|
|
|
public $formatterOptions = [
|
|
|
|
'application/json' => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES,
|
|
|
|
'application/xml' => 0,
|
|
|
|
'text/xml' => 0,
|
|
|
|
];
|
2020-07-29 01:54:07 +08:00
|
|
|
|
2021-06-04 22:51:52 +08:00
|
|
|
/**
|
|
|
|
* A Factory method to return the appropriate formatter for the given mime type.
|
|
|
|
*
|
|
|
|
* @return FormatterInterface
|
|
|
|
*
|
|
|
|
* @deprecated This is an alias of `\CodeIgniter\Format\Format::getFormatter`. Use that instead.
|
|
|
|
*/
|
|
|
|
public function getFormatter(string $mime)
|
|
|
|
{
|
|
|
|
return Services::format()->getFormatter($mime);
|
|
|
|
}
|
2016-11-24 00:02:36 -06:00
|
|
|
}
|