Commits

Phil Sturgeon committed 59a2ffc

Added support for calling controllers, methods and passing parameters via command line, either automatically or specifically with $config['uri_protocol'] = 'CLI';

  • Participants
  • Parent commits f9812f2

Comments (0)

Files changed (1)

File system/core/URI.php

 				return;
 			}
 
+			// Arguments exist, it must be a command line request
+			if ( ! empty($_SERVER['argv']))
+			{
+				$this->uri_string = $this->_parse_cli_args();
+				return;
+			}
+
 			// Is there a PATH_INFO variable?
 			// Note: some servers seem to have trouble with getenv() so we'll test it two ways
 			$path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
 				$this->uri_string = $this->_parse_request_uri($this->_get_request_uri());
 				return;
 			}
+			elseif ($uri == 'CLI')
+			{
+				$this->uri_string = $this->_parse_cli_args();
+				return;
+			}
 
 			$this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri);
 		}
 		{
 			$uri = $_SERVER['HTTP_X_REWRITE_URL'];
 		}
-		
+
 		// Last ditch effort (for older CGI servers, like IIS 5)
 		elseif (isset($_SERVER['ORIG_PATH_INFO']))
 		{
 	 * @param	string
 	 * @return	string
 	 */
-	function _parse_request_uri($uri)
+	private function _parse_request_uri($uri)
 	{
 		// Some server's require URL's like index.php?/whatever If that is the case,
 		// then we need to add that to our parsing.
 	// --------------------------------------------------------------------
 
 	/**
+	 * Parse cli arguments
+	 *
+	 * Take each command line argument and assume it is a URI segment.
+	 *
+	 * @access	private
+	 * @return	string
+	 */
+	private function _parse_cli_args()
+	{
+		$args = array_slice($_SERVER['argv'], 1);
+
+		return $args ? '/' . implode('/', $args) : '';
+	}
+
+	// --------------------------------------------------------------------
+
+	/**
 	 * Filter segments for malicious characters
 	 *
 	 * @access	private
 	{
 		$leading	= '/';
 		$trailing	= '/';
-		
+
 		if ($where == 'trailing')
 		{
 			$leading	= '';
 		{
 			$trailing	= '';
 		}
-		
+
 		return $leading.$this->$which($n).$trailing;
 	}