|
1 | 1 | <?php
|
2 | 2 |
|
| 3 | +namespace Restserver\Libraries; |
| 4 | + |
| 5 | +use Exception; |
| 6 | +use stdClass; |
| 7 | + |
3 | 8 | defined('BASEPATH') OR exit('No direct script access allowed');
|
4 | 9 |
|
5 | 10 | /**
|
@@ -407,15 +412,15 @@ public function __construct($config = 'rest')
|
407 | 412 | $this->get_local_config($config);
|
408 | 413 |
|
409 | 414 | // 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 | + //} |
419 | 424 |
|
420 | 425 |
|
421 | 426 | // Determine supported output formats from configuration
|
@@ -505,8 +510,9 @@ public function __construct($config = 'rest')
|
505 | 510 | // Now we know all about our request, let's try and parse the body if it exists
|
506 | 511 | if ($this->request->format && $this->request->body)
|
507 | 512 | {
|
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 |
510 | 516 | $this->{'_'.$this->request->method.'_args'} = $this->request->body;
|
511 | 517 | }
|
512 | 518 |
|
@@ -840,25 +846,25 @@ public function response($data = NULL, $http_code = NULL, $continue = FALSE)
|
840 | 846 | elseif ($data !== NULL)
|
841 | 847 | {
|
842 | 848 | // 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)) |
844 | 850 | {
|
845 | 851 | // Set the format header
|
846 | 852 | $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}(); |
848 | 854 |
|
849 | 855 | // An array must be parsed as a string, so as not to cause an array to string error
|
850 | 856 | // Json is the most appropriate form for such a data type
|
851 | 857 | if ($this->response->format === 'array')
|
852 | 858 | {
|
853 |
| - $output = $this->format->factory($output)->{'to_json'}(); |
| 859 | + $output = Format::factory($output)->{'to_json'}(); |
854 | 860 | }
|
855 | 861 | }
|
856 | 862 | else
|
857 | 863 | {
|
858 | 864 | // If an array or object, then parse as a json, so as to be a 'string'
|
859 | 865 | if (is_array($data) || is_object($data))
|
860 | 866 | {
|
861 |
| - $data = $this->format->factory($data)->{'to_json'}(); |
| 867 | + $data = Format::factory($data)->{'to_json'}(); |
862 | 868 | }
|
863 | 869 |
|
864 | 870 | // Format is not supported, so output the raw data as a string
|
|
0 commit comments