File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,7 +39,21 @@ class Format extends BaseConfig
3939 'application/xml ' => \CodeIgniter \Format \XMLFormatter::class,
4040 'text/xml ' => \CodeIgniter \Format \XMLFormatter::class,
4141 ];
42-
42+
43+ /*
44+ |--------------------------------------------------------------------------
45+ | Formatters Options
46+ |--------------------------------------------------------------------------
47+ |
48+ | Additional Options to adjust default formatters behaviour.
49+ | For each mime type, list the additional options that should be used.
50+ |
51+ */
52+ public $ formatterOptions = [
53+ 'application/json ' => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ,
54+ 'application/xml ' => 0 ,
55+ 'text/xml ' => 0 ,
56+ ];
4357 //--------------------------------------------------------------------
4458
4559 /**
Original file line number Diff line number Diff line change 4040namespace CodeIgniter \Format ;
4141
4242use CodeIgniter \Format \Exceptions \FormatException ;
43+ use Config \Format ;
4344
4445/**
4546 * JSON data formatter
@@ -56,7 +57,10 @@ class JSONFormatter implements FormatterInterface
5657 */
5758 public function format ($ data )
5859 {
59- $ options = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR ;
60+ $ config = new Format ();
61+
62+ $ options = $ config ->formatterOptions ['application/json ' ] ?? JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ;
63+ $ options = $ options | JSON_PARTIAL_OUTPUT_ON_ERROR ;
6064
6165 $ options = ENVIRONMENT === 'production ' ? $ options : $ options | JSON_PRETTY_PRINT ;
6266
Original file line number Diff line number Diff line change 4040namespace CodeIgniter \Format ;
4141
4242use CodeIgniter \Format \Exceptions \FormatException ;
43+ use Config \Format ;
4344
4445/**
4546 * XML data formatter
@@ -56,6 +57,8 @@ class XMLFormatter implements FormatterInterface
5657 */
5758 public function format ($ data )
5859 {
60+ $ config = new Format ();
61+
5962 // SimpleXML is installed but default
6063 // but best to check, and then provide a fallback.
6164 if (! extension_loaded ('simplexml ' ))
@@ -66,7 +69,8 @@ public function format($data)
6669 // @codeCoverageIgnoreEnd
6770 }
6871
69- $ output = new \SimpleXMLElement ('<?xml version="1.0"?><response></response> ' );
72+ $ options = $ config ->formatterOptions ['application/xml ' ] ?? 0 ;
73+ $ output = new \SimpleXMLElement ('<?xml version="1.0"?><response></response> ' , $ options );
7074
7175 $ this ->arrayToXML ((array )$ data , $ output );
7276
You can’t perform that action at this time.
0 commit comments