Format.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Config;
  3. use CodeIgniter\Config\BaseConfig;
  4. use CodeIgniter\Format\FormatterInterface;
  5. use CodeIgniter\Format\JSONFormatter;
  6. use CodeIgniter\Format\XMLFormatter;
  7. class Format extends BaseConfig
  8. {
  9. /**
  10. * --------------------------------------------------------------------------
  11. * Available Response Formats
  12. * --------------------------------------------------------------------------
  13. *
  14. * When you perform content negotiation with the request, these are the
  15. * available formats that your application supports. This is currently
  16. * only used with the API\ResponseTrait. A valid Formatter must exist
  17. * for the specified format.
  18. *
  19. * These formats are only checked when the data passed to the respond()
  20. * method is an array.
  21. *
  22. * @var list<string>
  23. */
  24. public array $supportedResponseFormats = [
  25. 'application/json',
  26. 'application/xml', // machine-readable XML
  27. 'text/xml', // human-readable XML
  28. ];
  29. /**
  30. * --------------------------------------------------------------------------
  31. * Formatters
  32. * --------------------------------------------------------------------------
  33. *
  34. * Lists the class to use to format responses with of a particular type.
  35. * For each mime type, list the class that should be used. Formatters
  36. * can be retrieved through the getFormatter() method.
  37. *
  38. * @var array<string, string>
  39. */
  40. public array $formatters = [
  41. 'application/json' => JSONFormatter::class,
  42. 'application/xml' => XMLFormatter::class,
  43. 'text/xml' => XMLFormatter::class,
  44. ];
  45. /**
  46. * --------------------------------------------------------------------------
  47. * Formatters Options
  48. * --------------------------------------------------------------------------
  49. *
  50. * Additional Options to adjust default formatters behaviour.
  51. * For each mime type, list the additional options that should be used.
  52. *
  53. * @var array<string, int>
  54. */
  55. public array $formatterOptions = [
  56. 'application/json' => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES,
  57. 'application/xml' => 0,
  58. 'text/xml' => 0,
  59. ];
  60. /**
  61. * A Factory method to return the appropriate formatter for the given mime type.
  62. *
  63. * @return FormatterInterface
  64. *
  65. * @deprecated This is an alias of `\CodeIgniter\Format\Format::getFormatter`. Use that instead.
  66. */
  67. public function getFormatter(string $mime)
  68. {
  69. return Services::format()->getFormatter($mime);
  70. }
  71. }