Skip to content

Commit 60ad84a

Browse files
committed
fixed merging conflicts
2 parents 0872a6f + f9520b2 commit 60ad84a

27 files changed

+495
-186
lines changed

README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
A fully RESTful server implementation for CodeIgniter using one library, one
44
config file and one controller.
55

6-
## Sponsored by: Coding Futures
7-
86
## Requirements
97

10-
1. PHP 5.2+
8+
1. PHP 5.2 or greater
119
2. CodeIgniter 2.1.0 to 3.0-dev
1210

1311
_Note: for 1.7.x support download v2.2 from Downloads tab_
@@ -53,7 +51,7 @@ This means your URLs can look like this:
5351
http://example.com/books.json
5452
http://example.com/books?format=json
5553

56-
Alternatively (and recommend) is using the HTTP `Accept` header, which is built for this purpose:
54+
This can be flaky with URI segments, so the recommend approach is using the HTTP `Accept` header:
5755

5856
$ curl -H "Accept: application/json" http://example.com
5957

@@ -148,6 +146,17 @@ By default, the HTTP will be `X-API-KEY`. This can be configured in **config/res
148146

149147
## Change Log
150148

149+
### 2.6.1
150+
151+
* Update CodeIgniter files to 2.1.2
152+
* Log Table support for IPv6 & NULL parameters
153+
* Abstract out the processes of firing a controller method within _remap() to an separate method
154+
* Moved GET, POST, PUT, and DELETE parsing to separate methods, allowing them to be overridden as needed
155+
* Small bugfix for a PHP 5.3 strlen error
156+
* Fixed some PHP 5.4 warnings
157+
* Fix for bug in Format.php's to_html() which failed to detect if $data was really a multidimensional array.
158+
* Fix for empty node on XML output format, for false = 0, true = 1.
159+
151160
### 2.6.0
152161

153162
* Added loads of PHPDoc comments.
@@ -198,7 +207,12 @@ By default, the HTTP will be `X-API-KEY`. This can be configured in **config/res
198207
* key => FALSE can now be used to override the keys_enabled option for a specific method, and level is now optional. If no level is set it will assume the method has a level of 0.
199208
* Fixed issue where calls to ->get('foo') would error is foo was not set. Reported by Paul Barto.
200209

201-
## Donations
210+
## Contributions
211+
212+
This project has been funded and made possible through my clients kindly allowing me to
213+
open-source the functionality as I build it into their projects. I am no longer actively developing
214+
features for this as I no longer require it, but I will continue to maintain pull requests and try to
215+
fix issues as and when they are reported (within a week or two).
202216

203-
If my REST Server has helped you out, or you'd like me to do some custom work on it, [please sponsor me](http://pledgie.com/campaigns/8328)
204-
so I can keep working on this and other CodeIgniter projects for you all.
217+
Pull Requests are the best way to fix bugs or add features. I know loads of you use this, so please
218+
contribute if you have improvements to be made and I'll keep releasing versions over time.

application/config/mimes.php

100755100644
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
$mimes = array( 'hqx' => 'application/mac-binhex40',
1212
'cpt' => 'application/mac-compactpro',
13-
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
13+
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
1414
'bin' => 'application/macbinary',
1515
'dms' => 'application/octet-stream',
1616
'lha' => 'application/octet-stream',
@@ -56,7 +56,7 @@
5656
'midi' => 'audio/midi',
5757
'mpga' => 'audio/mpeg',
5858
'mp2' => 'audio/mpeg',
59-
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3'),
59+
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
6060
'aif' => 'audio/x-aiff',
6161
'aiff' => 'audio/x-aiff',
6262
'aifc' => 'audio/x-aiff',
@@ -65,8 +65,8 @@
6565
'rpm' => 'audio/x-pn-realaudio-plugin',
6666
'ra' => 'audio/x-realaudio',
6767
'rv' => 'video/vnd.rn-realvideo',
68-
'wav' => 'audio/x-wav',
69-
'bmp' => 'image/bmp',
68+
'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
69+
'bmp' => array('image/bmp', 'image/x-windows-bmp'),
7070
'gif' => 'image/gif',
7171
'jpeg' => array('image/jpeg', 'image/pjpeg'),
7272
'jpg' => array('image/jpeg', 'image/pjpeg'),
@@ -93,13 +93,14 @@
9393
'avi' => 'video/x-msvideo',
9494
'movie' => 'video/x-sgi-movie',
9595
'doc' => 'application/msword',
96-
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
97-
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
96+
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),
97+
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'),
9898
'word' => array('application/msword', 'application/octet-stream'),
9999
'xl' => 'application/excel',
100-
'eml' => 'message/rfc822'
100+
'eml' => 'message/rfc822',
101+
'json' => array('application/json', 'text/json')
101102
);
102103

103104

104105
/* End of file mimes.php */
105-
/* Location: ./application/config/mimes.php */
106+
/* Location: ./application/config/mimes.php */

application/config/rest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
<?php defined('BASEPATH') OR exit('No direct script access allowed');
22

3+
/*
4+
|--------------------------------------------------------------------------
5+
| HTTP protocol
6+
|--------------------------------------------------------------------------
7+
|
8+
| Should the service accept only HTTPS requests or not?
9+
|
10+
| Default: FALSE
11+
|
12+
*/
13+
$config['force_https'] = FALSE;
14+
315
/*
416
|--------------------------------------------------------------------------
517
| REST Format
@@ -165,6 +177,17 @@
165177
*/
166178
$config['rest_enable_keys'] = FALSE;
167179

180+
/*
181+
|--------------------------------------------------------------------------
182+
| REST Table Key Column Name
183+
|--------------------------------------------------------------------------
184+
|
185+
| If you are not using the default table schema as shown above, what is the
186+
| name of the db column that holds the api key value?
187+
|
188+
*/
189+
$config['rest_key_column'] = 'key';
190+
168191
/*
169192
|--------------------------------------------------------------------------
170193
| REST Key Length
@@ -221,7 +244,7 @@
221244
`api_key` varchar(40) NOT NULL,
222245
`ip_address` varchar(45) NOT NULL,
223246
`time` int(11) NOT NULL,
224-
`authorized` tinyint(1) NOT NULL,
247+
`authorized` tinyint(1) NOT NULL
225248
PRIMARY KEY (`id`)
226249
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
227250
|

application/libraries/REST_Controller.php

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @author Phil Sturgeon
1212
* @license http://philsturgeon.co.uk/code/dbad-license
1313
* @link https://github.com/philsturgeon/codeigniter-restserver
14-
* @version 2.6.0
14+
* @version 2.6.1
1515
*/
1616
abstract class REST_Controller extends CI_Controller
1717
{
@@ -60,6 +60,13 @@ abstract class REST_Controller extends CI_Controller
6060
*/
6161
protected $rest = NULL;
6262

63+
/**
64+
* Object to store data about the client sending the request
65+
*
66+
* @var object
67+
*/
68+
protected $client = NULL;
69+
6370
/**
6471
* The arguments for the GET request method
6572
*
@@ -145,8 +152,13 @@ public function __construct()
145152
// Lets grab the config and get ready to party
146153
$this->load->config('rest');
147154

148-
// How is this request being made? POST, DELETE, GET, PUT?
155+
// let's learn about the request
149156
$this->request = new stdClass();
157+
158+
// Is it over SSL?
159+
$this->request->ssl = $this->_detect_ssl();
160+
161+
// How is this request being made? POST, DELETE, GET, PUT?
150162
$this->request->method = $this->_detect_method();
151163

152164
// Create argument container, if nonexistent
@@ -250,6 +262,12 @@ public function __construct()
250262
*/
251263
public function _remap($object_called, $arguments)
252264
{
265+
// Should we answer if not over SSL?
266+
if (config_item('force_https') AND !$this->_detect_ssl())
267+
{
268+
$this->response(array('status' => false, 'error' => 'Unsupported protocol'), 403);
269+
}
270+
253271
$pattern = '/^(.*)\.('.implode('|', array_keys($this->_supported_formats)).')$/';
254272
if (preg_match($pattern, $object_called, $matches))
255273
{
@@ -407,6 +425,17 @@ public function response($data = array(), $http_code = null)
407425
exit($output);
408426
}
409427

428+
/*
429+
* Detect SSL use
430+
*
431+
* Detect whether SSL is being used or not
432+
*/
433+
protected function _detect_ssl()
434+
{
435+
return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on"));
436+
}
437+
438+
410439
/*
411440
* Detect input format
412441
*
@@ -569,16 +598,18 @@ protected function _detect_api_key()
569598
// Find the key from server or arguments
570599
if (($key = isset($this->_args[$api_key_variable]) ? $this->_args[$api_key_variable] : $this->input->server($key_name)))
571600
{
572-
if ( ! ($row = $this->rest->db->where('key', $key)->get(config_item('rest_keys_table'))->row()))
601+
if ( ! ($this->client = $this->rest->db->where(config_item('rest_key_column'), $key)->get(config_item('rest_keys_table'))->row()))
573602
{
574603
return FALSE;
575604
}
576605

577-
$this->rest->key = $row->key;
606+
$this->rest->key = $this->client->{config_item('rest_key_column')};
578607

608+
/*
579609
isset($row->user_id) AND $this->rest->user_id = $row->user_id;
580610
isset($row->level) AND $this->rest->level = $row->level;
581611
isset($row->ignore_limits) AND $this->rest->ignore_limits = $row->ignore_limits;
612+
*/
582613

583614
if(!empty($row->is_private_key))
584615
{
@@ -607,7 +638,7 @@ protected function _detect_api_key()
607638
}
608639
}
609640

610-
return TRUE;
641+
return $this->client;
611642
}
612643

613644
// No key has been sent

system/core/CodeIgniter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @var string
3434
*
3535
*/
36-
define('CI_VERSION', '2.1.0');
36+
define('CI_VERSION', '2.1.2');
3737

3838
/**
3939
* CodeIgniter Branch (Core = TRUE, Reactor = FALSE)

0 commit comments

Comments
 (0)