Deprecate CI_Input::is_cli_request() and add common function is_cli() to replace it

Calls to this function are often needed before the Input library is available
diff --git a/system/core/Common.php b/system/core/Common.php
index 56008ef..c008bd5 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -355,6 +355,24 @@
 
 // ------------------------------------------------------------------------
 
+if ( ! function_exists('is_cli'))
+{
+
+	/**
+	 * Is CLI?
+	 *
+	 * Test to see if a request was made from the command line.
+	 *
+	 * @return 	bool
+	 */
+	function is_cli()
+	{
+		return (PHP_SAPI === 'cli' OR defined('STDIN'));
+	}
+}
+
+// ------------------------------------------------------------------------
+
 if ( ! function_exists('show_error'))
 {
 	/**
diff --git a/system/core/Input.php b/system/core/Input.php
index 8c32e45..384e30d 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -708,7 +708,7 @@
 		$_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
 
 		// CSRF Protection check
-		if ($this->_enable_csrf === TRUE && ! $this->is_cli_request())
+		if ($this->_enable_csrf === TRUE && ! is_cli())
 		{
 			$this->security->csrf_verify();
 		}
@@ -901,11 +901,12 @@
 	 *
 	 * Test to see if a request was made from the command line.
 	 *
-	 * @return 	bool
+	 * @deprecated	3.0.0	Use is_cli() instead
+	 * @return      bool
 	 */
 	public function is_cli_request()
 	{
-		return (PHP_SAPI === 'cli' OR defined('STDIN'));
+		return is_cli();
 	}
 
 	// --------------------------------------------------------------------
diff --git a/system/core/URI.php b/system/core/URI.php
index bc086d2..bad9985 100644
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -99,7 +99,7 @@
 		if ($protocol === 'AUTO')
 		{
 			// Is the request coming from the command line?
-			if ($this->_is_cli_request())
+			if (is_cli())
 			{
 				$this->_set_uri_string($this->_parse_argv());
 				return;
@@ -280,23 +280,6 @@
 	// --------------------------------------------------------------------
 
 	/**
-	 * Is CLI Request?
-	 *
-	 * Duplicate of method from the Input class to test to see if
-	 * a request was made from the command line.
-	 *
-	 * @see		CI_Input::is_cli_request()
-	 * @used-by	CI_URI::_fetch_uri_string()
-	 * @return 	bool
-	 */
-	protected function _is_cli_request()
-	{
-		return (PHP_SAPI === 'cli') OR defined('STDIN');
-	}
-
-	// --------------------------------------------------------------------
-
-	/**
 	 * Parse CLI arguments
 	 *
 	 * Take each command line argument and assume it is a URI segment.
diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php
index 659a026..19de979 100644
--- a/system/libraries/Session/Session.php
+++ b/system/libraries/Session/Session.php
@@ -102,10 +102,10 @@
 	 */
 	public function __construct(array $params = array())
 	{
-		$CI =& get_instance();
+		$_config =& get_instance()->config;
 
 		// No sessions under CLI
-		if ($CI->input->is_cli_request())
+		if (is_cli())
 		{
 			return;
 		}
@@ -113,7 +113,7 @@
 		log_message('debug', 'CI_Session Class Initialized');
 
 		// Add possible extra entries to our valid drivers list
-		$drivers = isset($params['sess_valid_drivers']) ? $params['sess_valid_drivers'] : $CI->config->item('sess_valid_drivers');
+		$drivers = isset($params['sess_valid_drivers']) ? $params['sess_valid_drivers'] : $_config->item('sess_valid_drivers');
 		if ( ! empty($drivers))
 		{
 			$drivers = array_map('strtolower', (array) $drivers);
@@ -121,7 +121,7 @@
 		}
 
 		// Get driver to load
-		$driver = isset($params['sess_driver']) ? $params['sess_driver'] : $CI->config->item('sess_driver');
+		$driver = isset($params['sess_driver']) ? $params['sess_driver'] : $_config->item('sess_driver');
 		if ( ! $driver)
 		{
 			log_message('debug', "Session: No driver name is configured, defaulting to 'cookie'.");
diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php
index e5dc29c..b073f23 100644
--- a/tests/mocks/core/common.php
+++ b/tests/mocks/core/common.php
@@ -190,4 +190,13 @@
 	{
 		return TRUE;
 	}
+}
+
+if ( ! function_exists('is_cli'))
+{
+	// In order to test HTTP functionality, we need to lie about this
+	function is_cli()
+	{
+		return FALSE;
+	}
 }
\ No newline at end of file
diff --git a/tests/mocks/core/uri.php b/tests/mocks/core/uri.php
index 94f75df..1107858 100644
--- a/tests/mocks/core/uri.php
+++ b/tests/mocks/core/uri.php
@@ -18,9 +18,4 @@
 
 	}
 
-	protected function _is_cli_request()
-	{
-		return FALSE;
-	}
-
 }
\ No newline at end of file
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 5fc86b1..23fd958 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -396,6 +396,7 @@
       -  Added method ``post_get()`` and changed ``get_post()`` to search in GET data first. Both methods' names now properly match their GET/POST data search priorities.
       -  Changed method ``_fetch_from_array()`` to parse array notation in field name.
       -  Added an option for ``_clean_input_keys()`` to return FALSE instead of terminating the whole script.
+      -  Deprecated the ``is_cli_request()`` method, it is now an alias for the new :php:func:`is_cli()` common function.
 
    -  :doc:`Common functions <general/common_functions>` changes include:
 
@@ -404,6 +405,7 @@
       -  Removed redundant conditional to determine HTTP server protocol in :php:func:`set_status_header()`.
       -  Changed ``_exception_handler()`` to respect php.ini *display_errors* setting.
       -  Added function :php:func:`is_https()` to check if a secure connection is used.
+      -  Added function :php:func:`is_cli()` to replace the ``CI_Input::is_cli_request()`` method.
       -  Added function :php:func:`function_usable()` to check if a function exists and is not disabled by `Suhosin <http://www.hardened-php.net/suhosin/>`.
       -  Removed the third (`$php_error`) from function :php:func:`log_message()`.
 
diff --git a/user_guide_src/source/general/cli.rst b/user_guide_src/source/general/cli.rst
index 4145d5c..4f3b07d 100644
--- a/user_guide_src/source/general/cli.rst
+++ b/user_guide_src/source/general/cli.rst
@@ -23,7 +23,7 @@
 
 -  Run your cron-jobs without needing to use *wget* or *curl*
 -  Make your cron-jobs inaccessible from being loaded in the URL by
-   checking for ``$this->input->is_cli_request()``
+   checking the return value of :func:`is_cli()`.
 -  Make interactive "tasks" that can do things like set permissions,
    prune cache folders, run backups, etc.
 -  Integrate with other applications in other languages. For example, a
diff --git a/user_guide_src/source/general/common_functions.rst b/user_guide_src/source/general/common_functions.rst
index e085ef8..2dfec9c 100644
--- a/user_guide_src/source/general/common_functions.rst
+++ b/user_guide_src/source/general/common_functions.rst
@@ -173,6 +173,19 @@
 Returns TRUE if a secure (HTTPS) connection is used and FALSE
 in any other case (including non-HTTP requests).
 
+is_cli()
+========
+
+.. php:function:: is_cli()
+
+	:returns:	bool
+
+Returns TRUE if the application is run through the command line
+and FALSE if not.
+
+.. note:: This function checks both if the ``PHP_SAPI`` value is 'cli'
+	or if the ``STDIN`` constant is defined.
+
 function_usable()
 =================
 
diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst
index 5dfee8b..8126eba 100644
--- a/user_guide_src/source/helpers/date_helper.rst
+++ b/user_guide_src/source/helpers/date_helper.rst
@@ -80,7 +80,7 @@
 	$time = time();
 	echo standard_date($format, $time);
 
-.. note:: This function is DEPRECATED.Use the native ``date()`` combined with
+.. note:: This function is DEPRECATED. Use the native ``date()`` combined with
 	`DateTime's format constants
 	<http://www.php.net/manual/en/class.datetime.php#datetime.constants.types>`_
 	instead:
diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst
index e8fdd0b..8f9cc1b 100644
--- a/user_guide_src/source/installation/upgrade_300.rst
+++ b/user_guide_src/source/installation/upgrade_300.rst
@@ -457,4 +457,28 @@
 	$this->router->method;
 
 .. note:: Those methods are still available, but you're strongly encouraged to remove their usage
+	sooner rather than later.
+
+Input library method is_cli_request()
+=====================================
+
+Calls to the ``CI_Input::is_cli_request()`` method are necessary at many places
+in the CodeIgniter internals and this is often before the :doc:`Input Library
+<../libraries/input>` is loaded. Because of that, it is being replaced by a common
+function named :php:func:`is_cli()` and this method is now just an alias.
+
+The new function is both available at all times for you to use and shorter to type.
+
+::
+
+	// Old
+	$this->input->is_cli_request();
+
+	// New
+	is_cli();
+
+``CI_Input::is_cli_request()`` is now now deprecated and scheduled for removal in
+CodeIgniter 3.1+.
+
+.. note:: This method is still available, but you're strongly encouraged to remove its usage
 	sooner rather than later.
\ No newline at end of file
diff --git a/user_guide_src/source/libraries/input.rst b/user_guide_src/source/libraries/input.rst
index fb245d7..b58ed2f 100644
--- a/user_guide_src/source/libraries/input.rst
+++ b/user_guide_src/source/libraries/input.rst
@@ -315,6 +315,9 @@
 
 	$this->input->is_cli_request()
 
+.. note:: This method is DEPRECATED and is now just an alias for the
+	:php:func:`is_cli()` function.
+
 $this->input->method()
 ======================