Skip to content

Commit bf37537

Browse files
author
Kevin Wood-Friend
committed
Moved GET, POST, PUT, and DELETE parsing to separate methods, allowing them to be overridden as needed
1 parent 407b253 commit bf37537

File tree

1 file changed

+50
-36
lines changed

1 file changed

+50
-36
lines changed

application/libraries/REST_Controller.php

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -156,42 +156,7 @@ public function __construct()
156156
// Some Methods cant have a body
157157
$this->request->body = NULL;
158158

159-
switch ($this->request->method)
160-
{
161-
case 'get':
162-
// Grab proper GET variables
163-
parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $get);
164-
165-
// Merge both the URI segments and GET params
166-
$this->_get_args = array_merge($this->_get_args, $get);
167-
break;
168-
169-
case 'post':
170-
$this->_post_args = $_POST;
171-
172-
$this->request->format and $this->request->body = file_get_contents('php://input');
173-
break;
174-
175-
case 'put':
176-
// It might be a HTTP body
177-
if ($this->request->format)
178-
{
179-
$this->request->body = file_get_contents('php://input');
180-
}
181-
182-
// If no file type is provided, this is probably just arguments
183-
else
184-
{
185-
parse_str(file_get_contents('php://input'), $this->_put_args);
186-
}
187-
188-
break;
189-
190-
case 'delete':
191-
// Set up out DELETE variables (which shouldn't really exist, but sssh!)
192-
parse_str(file_get_contents('php://input'), $this->_delete_args);
193-
break;
194-
}
159+
$this->{'_parse_' . $this->request->method}();
195160

196161
// Now we know all about our request, let's try and parse the body if it exists
197162
if ($this->request->format and $this->request->body)
@@ -768,6 +733,55 @@ protected function _auth_override_check()
768733
return false;
769734
}
770735

736+
/**
737+
* Parse GET
738+
*/
739+
protected function _parse_get()
740+
{
741+
// Grab proper GET variables
742+
parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $get);
743+
744+
// Merge both the URI segments and GET params
745+
$this->_get_args = array_merge($this->_get_args, $get);
746+
}
747+
748+
/**
749+
* Parse POST
750+
*/
751+
protected function _parse_post()
752+
{
753+
$this->_post_args = $_POST;
754+
755+
$this->request->format and $this->request->body = file_get_contents('php://input');
756+
}
757+
758+
/**
759+
* Parse PUT
760+
*/
761+
protected function _parse_put()
762+
{
763+
// It might be a HTTP body
764+
if ($this->request->format)
765+
{
766+
$this->request->body = file_get_contents('php://input');
767+
}
768+
769+
// If no file type is provided, this is probably just arguments
770+
else
771+
{
772+
parse_str(file_get_contents('php://input'), $this->_put_args);
773+
}
774+
}
775+
776+
/**
777+
* Parse DELETE
778+
*/
779+
protected function _parse_delete()
780+
{
781+
// Set up out DELETE variables (which shouldn't really exist, but sssh!)
782+
parse_str(file_get_contents('php://input'), $this->_delete_args);
783+
}
784+
771785
// INPUT FUNCTION --------------------------------------------------------------
772786

773787
/**

0 commit comments

Comments
 (0)