Skip to content

Commit 8ab48d5

Browse files
Ivan Peevskichriskacerguis
authored andcommitted
Allow extending Formatter class
1 parent 548cc41 commit 8ab48d5

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/RestController.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class RestController extends \CI_Controller
232232
/**
233233
* @var Format
234234
*/
235-
private $format;
235+
protected $format;
236236

237237
/**
238238
* @var bool
@@ -636,10 +636,17 @@ public function response($data = null, $http_code = null, $continue = false)
636636
// If data is not NULL and a HTTP status code provided, then continue
637637
elseif ($data !== null) {
638638
// If the format method exists, call and return the output in that format
639-
if (method_exists(Format::class, 'to_'.$this->response->format)) {
639+
$formatter = null;
640+
if ($this->format && method_exists($this->format, 'to_'.$this->response->format)) {
641+
$formatter = $this->format::factory($data);
642+
} else if (method_exists(Format::class, 'to_'.$this->response->format)) {
643+
$formatter = Format::factory($data);
644+
}
645+
646+
if ($formatter !== null) {
640647
// CORB protection
641648
// First, get the output content.
642-
$output = Format::factory($data)->{'to_'.$this->response->format}();
649+
$output = $formatter->{'to_'.$this->response->format}();
643650

644651
// Set the format header
645652
// Then, check if the client asked for a callback, and if the output contains this callback :

0 commit comments

Comments
 (0)