summaryrefslogtreecommitdiffstats
path: root/system/core/Input.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-11-06 13:55:48 +0100
committerAndrey Andreev <narf@bofh.bg>2012-11-06 13:55:48 +0100
commit303eef056b7317a1e4f06feb26fdb452a59c3a51 (patch)
tree666e9292b9a908f3dec2799d8ea496c9e17fa692 /system/core/Input.php
parent55a8c6267fad29d8bc3677c084c2c5d00569ec96 (diff)
Added CI_Input::input_stream()
Helps in reading php://input stream data by caching it when accessed for the first time. (supersedes PR #1684)
Diffstat (limited to 'system/core/Input.php')
-rw-r--r--system/core/Input.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/system/core/Input.php b/system/core/Input.php
index c0158df99..adc5f7ac0 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -100,6 +100,16 @@ class CI_Input {
protected $headers = array();
/**
+ * Input stream data
+ *
+ * Parsed from php://input at runtime
+ *
+ * @see CI_Input::input_stream()
+ * @var array
+ */
+ protected $_input_stream = NULL;
+
+ /**
* Class constructor
*
* Determines whether to globally enable the XSS processing
@@ -257,6 +267,37 @@ class CI_Input {
// ------------------------------------------------------------------------
/**
+ * Fetch an item from the php://input stream
+ *
+ * Useful when you need to access PUT, DELETE or PATCH request data.
+ *
+ * @param string $index Index for item to be fetched
+ * @param bool $xss_clean Whether to apply XSS filtering
+ * @return mixed
+ */
+ public function input_stream($index = '', $xss_clean = FALSE)
+ {
+ // The input stream can only be read once, so we'll need to check
+ // if we have already done that first.
+ if (is_array($this->_input_stream))
+ {
+ return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean);
+ }
+
+ // Parse the input stream in our cache var
+ parse_str(file_get_contents('php://input'), $this->_input_stream);
+ if ( ! is_array($this->_input_stream))
+ {
+ $this->_input_stream = array();
+ return NULL;
+ }
+
+ return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
* Set cookie
*
* Accepts an arbitrary number of parameters (up to 7) or an associative