summaryrefslogtreecommitdiffstats
path: root/system/core/Input.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/core/Input.php')
-rw-r--r--system/core/Input.php81
1 files changed, 28 insertions, 53 deletions
diff --git a/system/core/Input.php b/system/core/Input.php
index f181c27ce..97884d309 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -103,22 +103,16 @@ class CI_Input {
*/
protected $headers = array();
- /**
- * Raw input stream data as received from php://input
- *
- * @see CI_Input::raw_input_stream()
- * @var array
- */
protected $_raw_input_stream = NULL;
/**
- * Input stream data
- *
- * Parsed from raw_input_stream at runtime
- *
- * @see CI_Input::input_stream()
- * @var array
- */
+ * Input stream data
+ *
+ * Parsed from php://input at runtime
+ *
+ * @see CI_Input::input_stream()
+ * @var array
+ */
protected $_input_stream = NULL;
/**
@@ -307,54 +301,35 @@ class CI_Input {
// ------------------------------------------------------------------------
/**
- * Fetch raw data from php://input stream
- *
- * Useful when data is not an array.
- */
- public function raw_input_stream()
+ * 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 = NULL, $xss_clean = NULL)
{
- // Prior to PHP 5.6, the input stream can only be read once,
- // so we'll need to check if we have already done that first.
- if (is_null($this->_raw_input_stream))
+ // Prior to PHP 5.6, 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))
{
- $this->_raw_input_stream = file_get_contents('php://input');
+ parse_str($this->raw_input_stream, $this->_input_stream);
+ is_array($this->_input_stream) OR $this->_input_stream = array();
}
-
- return $this->_raw_input_stream;
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Fetch an item from the 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 = NULL, $xss_clean = NULL)
- {
- parse_str($this->raw_input_stream(), $this->_input_stream);
return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean);
}
-
+
// ------------------------------------------------------------------------
- /**
- * Fetch an item from the input stream
- *
- * Useful when you need to access input that's been send as json'
- *
- * @param string $index Index for item to be fetched
- * @param bool $xss_clean Whether to apply XSS filtering
- * @return mixed
- */
- public function json_input_stream($index = NULL, $xss_clean = NULL)
+ public function __get($name)
{
- $json_input_stream = json_decode($this->raw_input_stream(), true);
- return $this->_fetch_from_array($json_input_stream, $index, $xss_clean);
+ if ($name === 'raw_input_stream')
+ {
+ isset($this->_raw_input_stream) OR $this->_raw_input_stream = file_get_contents('php://input');
+ return $this->_raw_input_stream;
+ }
}
// ------------------------------------------------------------------------