Skip to content

Commit

Permalink
Development (#748)
Browse files Browse the repository at this point in the history
* removed continue param from response

* removed exception from ci-phpunit

* updated example to account for changes to response

* added ci-unit tests

* added travis file

* updated travis ci file

* added Travis badge
  • Loading branch information
chriskacerguis authored Jan 1, 2017
1 parent 524718b commit 39c7cfb
Show file tree
Hide file tree
Showing 488 changed files with 57,923 additions and 41 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: php
sudo: false
php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
script:
- cd application/tests
- phpunit --coverage-text
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# CodeIgniter Rest Server

[![Gitter chat](https://badges.gitter.im/chriskacerguis/codeigniter-restserver.png)](https://gitter.im/codeigniter-restserver/Lobby)

[![Gitter chat](https://badges.gitter.im/chriskacerguis/codeigniter-restserver.png)](https://gitter.im/codeigniter-restserver/Lobby) [![Build Status](https://travis-ci.org/chriskacerguis/codeigniter-restserver.svg?branch=master)](https://travis-ci.org/chriskacerguis/codeigniter-restserver)
A fully RESTful server implementation for CodeIgniter using one library, one
config file and one controller.

Expand Down
55 changes: 28 additions & 27 deletions application/controllers/api/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,43 @@ public function users_get()
}

// Find and return a single record for a particular user.
else {
$id = (int) $id;

$id = (int) $id;

// Validate the id.
if ($id <= 0)
{
// Invalid id, set the response and exit.
$this->response(NULL, \Restserver\Libraries\REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
}
// Validate the id.
if ($id <= 0)
{
// Invalid id, set the response and exit.
$this->response(NULL, \Restserver\Libraries\REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
}

// Get the user from the array, using the id as key for retrieval.
// Usually a model is to be used for this.
// Get the user from the array, using the id as key for retrieval.
// Usually a model is to be used for this.

$user = NULL;
$user = NULL;

if (!empty($users))
{
foreach ($users as $key => $value)
if (!empty($users))
{
if (isset($value['id']) && $value['id'] === $id)
foreach ($users as $key => $value)
{
$user = $value;
if (isset($value['id']) && $value['id'] === $id)
{
$user = $value;
}
}
}
}

if (!empty($user))
{
$this->set_response($user, \Restserver\Libraries\REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
}
else
{
$this->set_response([
'status' => FALSE,
'message' => 'User could not be found'
], \Restserver\Libraries\REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
if (!empty($user))
{
$this->set_response($user, \Restserver\Libraries\REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
}
else
{
$this->set_response([
'status' => FALSE,
'message' => 'User could not be found'
], \Restserver\Libraries\REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
}
}
}

Expand Down
14 changes: 2 additions & 12 deletions application/libraries/REST_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,9 @@ public function _remap($object_called, $arguments = [])
* @access public
* @param array|NULL $data Data to output to the user
* @param int|NULL $http_code HTTP status code
* @param bool $continue TRUE to flush the response to the client and continue
* running the script; otherwise, exit
*/
public function response($data = NULL, $http_code = NULL, $continue = FALSE)
public function response($data = NULL, $http_code = NULL)
{
ob_start();
// If the HTTP status is not NULL, then cast as an integer
Expand Down Expand Up @@ -828,16 +827,7 @@ public function response($data = NULL, $http_code = NULL, $continue = FALSE)
// Output the data
$this->output->set_output($output);

if ($continue === FALSE)
{
// Display the data and exit execution
$this->output->_display();
exit;
}
else
{
ob_end_flush();
}
ob_end_flush();

// Otherwise dump the output automatically
}
Expand Down
1 change: 1 addition & 0 deletions application/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_ci_phpunit_test/tmp/
Loading

0 comments on commit 39c7cfb

Please sign in to comment.