Skip to content

Commit 23b0997

Browse files
grawerplchriskacerguis
authored andcommitted
Update REST_Controller.php (chriskacerguis#924)
Support for namespece
1 parent d03f614 commit 23b0997

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

application/libraries/REST_Controller.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?php
22

3+
namespace Restserver\Libraries;
4+
5+
use Exception;
6+
use stdClass;
7+
38
defined('BASEPATH') OR exit('No direct script access allowed');
49

510
/**
@@ -407,15 +412,15 @@ public function __construct($config = 'rest')
407412
$this->get_local_config($config);
408413

409414
// At present the library is bundled with REST_Controller 2.5+, but will eventually be part of CodeIgniter (no citation)
410-
if(class_exists('Format'))
411-
{
412-
$this->format = new Format();
413-
}
414-
else
415-
{
416-
$this->load->library('Format', NULL, 'libraryFormat');
417-
$this->format = $this->libraryFormat;
418-
}
415+
//if(class_exists('Format'))
416+
//{
417+
// $this->format = new Format();
418+
//}
419+
//else
420+
//{
421+
// $this->load->library('Format', NULL, 'libraryFormat');
422+
// $this->format = $this->libraryFormat;
423+
//}
419424

420425

421426
// Determine supported output formats from configuration
@@ -505,8 +510,9 @@ public function __construct($config = 'rest')
505510
// Now we know all about our request, let's try and parse the body if it exists
506511
if ($this->request->format && $this->request->body)
507512
{
508-
$this->request->body = $this->format->factory($this->request->body, $this->request->format)->to_array();
509-
// Assign payload arguments to proper method container
513+
$this->request->body = Format::factory($this->request->body, $this->request->format)->to_array();
514+
515+
// Assign payload arguments to proper method container
510516
$this->{'_'.$this->request->method.'_args'} = $this->request->body;
511517
}
512518

@@ -840,25 +846,25 @@ public function response($data = NULL, $http_code = NULL, $continue = FALSE)
840846
elseif ($data !== NULL)
841847
{
842848
// If the format method exists, call and return the output in that format
843-
if (method_exists($this->format, 'to_' . $this->response->format))
849+
if (method_exists(Format::class, 'to_' . $this->response->format))
844850
{
845851
// Set the format header
846852
$this->output->set_content_type($this->_supported_formats[$this->response->format], strtolower($this->config->item('charset')));
847-
$output = $this->format->factory($data)->{'to_' . $this->response->format}();
853+
$output = Format::factory($data)->{'to_' . $this->response->format}();
848854

849855
// An array must be parsed as a string, so as not to cause an array to string error
850856
// Json is the most appropriate form for such a data type
851857
if ($this->response->format === 'array')
852858
{
853-
$output = $this->format->factory($output)->{'to_json'}();
859+
$output = Format::factory($output)->{'to_json'}();
854860
}
855861
}
856862
else
857863
{
858864
// If an array or object, then parse as a json, so as to be a 'string'
859865
if (is_array($data) || is_object($data))
860866
{
861-
$data = $this->format->factory($data)->{'to_json'}();
867+
$data = Format::factory($data)->{'to_json'}();
862868
}
863869

864870
// Format is not supported, so output the raw data as a string

0 commit comments

Comments
 (0)