@@ -765,72 +765,88 @@ public function _remap($object_called, $arguments = [])
765765 */
766766 public function response ($ data = NULL , $ http_code = NULL )
767767 {
768+ //if profiling enabled then print profiling data
769+ $ isProfilingEnabled = $ this ->config ->item ('enable_profiling ' );
770+ if (!$ isProfilingEnabled ){
768771 ob_start ();
769- // If the HTTP status is not NULL, then cast as an integer
770- if ($ http_code !== NULL )
771- {
772- // So as to be safe later on in the process
773- $ http_code = (int ) $ http_code ;
774- }
775-
776- // Set the output as NULL by default
777- $ output = NULL ;
778-
779- // If data is NULL and no HTTP status code provided, then display, error and exit
780- if ($ data === NULL && $ http_code === NULL )
781- {
782- $ http_code = self ::HTTP_NOT_FOUND ;
783- }
784-
785- // If data is not NULL and a HTTP status code provided, then continue
786- elseif ($ data !== NULL )
787- {
788- // If the format method exists, call and return the output in that format
789- if (method_exists ($ this ->format , 'to_ ' . $ this ->response ->format ))
790- {
791- // Set the format header
792- $ this ->output ->set_content_type ($ this ->_supported_formats [$ this ->response ->format ], strtolower ($ this ->config ->item ('charset ' )));
793- $ output = $ this ->format ->factory ($ data )->{'to_ ' . $ this ->response ->format }();
794-
795- // An array must be parsed as a string, so as not to cause an array to string error
796- // Json is the most appropriate form for such a data type
797- if ($ this ->response ->format === 'array ' )
798- {
799- $ output = $ this ->format ->factory ($ output )->{'to_json ' }();
800- }
801- }
802- else
803- {
804- // If an array or object, then parse as a json, so as to be a 'string'
805- if (is_array ($ data ) || is_object ($ data ))
806- {
807- $ data = $ this ->format ->factory ($ data )->{'to_json ' }();
808- }
809-
810- // Format is not supported, so output the raw data as a string
811- $ output = $ data ;
812- }
813- }
814-
815- // If not greater than zero, then set the HTTP status code as 200 by default
816- // Though perhaps 500 should be set instead, for the developer not passing a
817- // correct HTTP status code
818- $ http_code > 0 || $ http_code = self ::HTTP_OK ;
819-
820- $ this ->output ->set_status_header ($ http_code );
821-
822- // JC: Log response code only if rest logging enabled
823- if ($ this ->config ->item ('rest_enable_logging ' ) === TRUE )
824- {
825- $ this ->_log_response_code ($ http_code );
826- }
827-
828- // Output the data
829- $ this ->output ->set_output ($ output );
830-
831- ob_end_flush ();
832-
833- // Otherwise dump the output automatically
772+ // If the HTTP status is not NULL, then cast as an integer
773+ if ($ http_code !== NULL )
774+ {
775+ // So as to be safe later on in the process
776+ $ http_code = (int ) $ http_code ;
777+ }
778+
779+ // Set the output as NULL by default
780+ $ output = NULL ;
781+
782+ // If data is NULL and no HTTP status code provided, then display, error and exit
783+ if ($ data === NULL && $ http_code === NULL )
784+ {
785+ $ http_code = self ::HTTP_NOT_FOUND ;
786+ }
787+
788+ // If data is not NULL and a HTTP status code provided, then continue
789+ elseif ($ data !== NULL )
790+ {
791+ // If the format method exists, call and return the output in that format
792+ if (method_exists ($ this ->format , 'to_ ' . $ this ->response ->format ))
793+ {
794+ // Set the format header
795+ $ this ->output ->set_content_type ($ this ->_supported_formats [$ this ->response ->format ], strtolower ($ this ->config ->item ('charset ' )));
796+ $ output = $ this ->format ->factory ($ data )->{'to_ ' . $ this ->response ->format }();
797+
798+ // An array must be parsed as a string, so as not to cause an array to string error
799+ // Json is the most appropriate form for such a data type
800+ if ($ this ->response ->format === 'array ' )
801+ {
802+ $ output = $ this ->format ->factory ($ output )->{'to_json ' }();
803+ }
804+ }
805+ else
806+ {
807+ // If an array or object, then parse as a json, so as to be a 'string'
808+ if (is_array ($ data ) || is_object ($ data ))
809+ {
810+ $ data = $ this ->format ->factory ($ data )->{'to_json ' }();
811+ }
812+
813+ // Format is not supported, so output the raw data as a string
814+ $ output = $ data ;
815+ }
816+ }
817+
818+ // If not greater than zero, then set the HTTP status code as 200 by default
819+ // Though perhaps 500 should be set instead, for the developer not passing a
820+ // correct HTTP status code
821+ $ http_code > 0 || $ http_code = self ::HTTP_OK ;
822+
823+ $ this ->output ->set_status_header ($ http_code );
824+
825+ // JC: Log response code only if rest logging enabled
826+ if ($ this ->config ->item ('rest_enable_logging ' ) === TRUE )
827+ {
828+ $ this ->_log_response_code ($ http_code );
829+ }
830+
831+ // Output the data
832+ $ this ->output ->set_output ($ output );
833+
834+ if ($ continue === FALSE )
835+ {
836+ // Display the data and exit execution
837+ $ this ->output ->_display ();
838+ exit ;
839+ }
840+ else
841+ {
842+ ob_end_flush ();
843+ }
844+
845+ // Otherwise dump the output automatically
846+ }
847+ else {
848+ echo json_encode ($ data );
849+ }
834850 }
835851
836852 /**
0 commit comments