Format.php 2.2 KB

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