Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add support for HTTP PUT and HTTP DELETE data #1684

Closed
wants to merge 14 commits into from

6 participants

@hedcler

$this->input->put();
AND
$this->input->delete();

hedcler and others added some commits
@hedcler hedcler Add Support to PUT and REQUEST data in Input Class
Added support to PUT data us gin $this->input->put() and REQUEST data
using $this->input->request()
5e6fe40
@hedcler hedcler Add support to $_REQUEST data
Added support to access $_REQUEST data us gin $this->input->request()
b505f6b
@hedcler hedcler fix line comment 6ca4c02
@hedcler hedcler Revert "fix line comment"
This reverts commit 6ca4c02.
45e5ee5
@hedcler hedcler Revert "Add support to $_REQUEST data"
This reverts commit b505f6b.
163c7fc
@hedcler hedcler Revert "Add Support to PUT and REQUEST data in Input Class"
This reverts commit 5e6fe40.
0ef3b22
@hedcler hedcler Added support to PUT and REQUEST data
Now you can be used:
$this->input->put() or $this->input->request() to access PUT and
REQUEST data respectively.
3fb2821
@hedcler hedcler Correct comment. a1a4cb3
Hedcler Morais Add access to HTTP PUT data
Now we can be use $this->input->put() on HTTP PUT REQUESTS.
eabcef8
Hedcler Morais Adjust comment 778926e
Hedcler Morais Now support too HTTP DELETE data e44aa4b
@hedcler

Now I verify if HTTP METHOD is PUT or DELETE to access the data.

system/core/Input.php
@@ -173,6 +189,72 @@ public function get($index = NULL, $xss_clean = FALSE)
return $this->_fetch_from_array($_GET, $index, $xss_clean);
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch an item from the HTTP PUT array
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
+
+ public function put($index = NULL, $xss_clean = FALSE) {
+
+ if ( $this->server('REQUEST_METHOD') != 'PUT' ) return FALSE;
@hedcler
hedcler added a note

It's ok now... tks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@winglian

Back-to-back calls to ->put() will fail on subsequent reads because php://input is read-once. You'll need to store the value from php://input during the first read.

@alexbilbie

This should also support PATCH

@joelcox

@hedcler, did you ever get around to the comments stated above?

@narfbg narfbg referenced this pull request from a commit
@narfbg narfbg Added CI_Input::input_stream()
Helps in reading php://input stream data by caching it when accessed for the first time.

(supersedes PR #1684)
303eef0
@narfbg
Owner

See the above commit.

@narfbg narfbg closed this
@hedcler

Thanks @narfbg ! This solves my problem.

@nonchip nonchip referenced this pull request from a commit in nonchip/CodeIgniter
@narfbg narfbg Added CI_Input::input_stream()
Helps in reading php://input stream data by caching it when accessed for the first time.

(supersedes PR #1684)
dbd5af9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 3, 2012
  1. @hedcler

    Add Support to PUT and REQUEST data in Input Class

    hedcler authored
    Added support to PUT data us gin $this->input->put() and REQUEST data
    using $this->input->request()
  2. @hedcler

    Add support to $_REQUEST data

    hedcler authored
    Added support to access $_REQUEST data us gin $this->input->request()
  3. @hedcler

    fix line comment

    hedcler authored
  4. @hedcler

    Revert "fix line comment"

    hedcler authored
    This reverts commit 6ca4c02.
  5. @hedcler

    Revert "Add support to $_REQUEST data"

    hedcler authored
    This reverts commit b505f6b.
  6. @hedcler
  7. @hedcler

    Added support to PUT and REQUEST data

    hedcler authored
    Now you can be used:
    $this->input->put() or $this->input->request() to access PUT and
    REQUEST data respectively.
  8. @hedcler

    Correct comment.

    hedcler authored
Commits on Aug 4, 2012
  1. Add access to HTTP PUT data

    Hedcler Morais authored
    Now we can be use $this->input->put() on HTTP PUT REQUESTS.
  2. Adjust comment

    Hedcler Morais authored
  3. Now support too HTTP DELETE data

    Hedcler Morais authored
Commits on Aug 7, 2012
  1. @hedcler

    Correct Arrays

    hedcler authored
  2. @hedcler
  3. @hedcler
This page is out of date. Refresh to see the latest.
Showing with 91 additions and 0 deletions.
  1. +1 −0  application/controllers/welcome.php
  2. +90 −0 system/core/Input.php
View
1  application/controllers/welcome.php
@@ -46,6 +46,7 @@ public function index()
{
$this->load->view('welcome_message');
}
+
}
/* End of file welcome.php */
View
90 system/core/Input.php
@@ -90,6 +90,22 @@ class CI_Input {
protected $headers = array();
/**
+ * List of all HTTP PUT data
+ *
+ * @var array
+ */
+ protected $http_put_data = array();
+
+ /**
+ * List of all HTTP DELETE data
+ *
+ * @var array
+ */
+ protected $http_delete_data = array();
+
+
+
+ /**
* Constructor
*
* Sets whether to globally enable the XSS processing
@@ -173,6 +189,80 @@ public function get($index = NULL, $xss_clean = FALSE)
return $this->_fetch_from_array($_GET, $index, $xss_clean);
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch an item from the HTTP PUT array
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
+
+ public function put($index = NULL, $xss_clean = FALSE)
+ {
+ // Check if HTTP METHOD is PUT
+ if ( $this->server('REQUEST_METHOD') != 'PUT' )
+ {
+ return FALSE;
+ }
+ // Read PUT variables
+ parse_str( file_get_contents("php://input"), $this->http_put_data );
+ // Check if a field has been provided
+ if ($index === NULL && !empty($this->http_put_data))
+ {
+ $put = array();
+ // Loop through the full put args array and return it
+ foreach (array_keys($this->http_put_data) as $key)
+ {
+ $put[$key] = $this->_fetch_from_array($this->http_put_data, $key, $xss_clean);
+ }
+ return $put;
+ }
+
+ return $this->_fetch_from_array($this->http_put_data, $index, $xss_clean);
+
+ }
+
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch an item from the HTTP DELETE array
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
+
+ public function delete($index = NULL, $xss_clean = FALSE)
+ {
+ // Check if HTTP METHOD is DELETE
+ if ($this->server('REQUEST_METHOD') != 'DELETE')
+ {
+ return FALSE;
+ }
+ // Read DELETE variables
+ parse_str( file_get_contents("php://input"), $this->http_delete_data );
+ // Check if a field has been provided
+ if ($index === NULL && !empty($this->http_delete_data))
+ {
+ $put = array();
+ // Loop through the full delete args array and return it
+ foreach (array_keys($this->http_delete_data) as $key)
+ {
+ $put[$key] = $this->_fetch_from_array($this->http_delete_data, $key, $xss_clean);
+ }
+ return $put;
+ }
+
+ return $this->_fetch_from_array($this->http_delete_data, $index, $xss_clean);
+
+ }
+
+
+
// --------------------------------------------------------------------
/**
Something went wrong with that request. Please try again.