From 48c718c4cbe4419411623b709f898d3d9a7d7aef Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 30 Dec 2010 23:40:02 +0000 Subject: Added support for calling controllers, methods and passing parameters via command line, either automatically or specifically with $config['uri_protocol'] = 'CLI'; --- system/core/URI.php | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/system/core/URI.php b/system/core/URI.php index 047e3c9bc..479a225fb 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -68,6 +68,13 @@ class CI_URI { 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'); @@ -104,6 +111,11 @@ class CI_URI { $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); } @@ -144,7 +156,7 @@ class CI_URI { { $uri = $_SERVER['HTTP_X_REWRITE_URL']; } - + // Last ditch effort (for older CGI servers, like IIS 5) elseif (isset($_SERVER['ORIG_PATH_INFO'])) { @@ -171,7 +183,7 @@ class CI_URI { * @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. @@ -215,6 +227,23 @@ class CI_URI { // -------------------------------------------------------------------- + /** + * 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 * @@ -524,7 +553,7 @@ class CI_URI { { $leading = '/'; $trailing = '/'; - + if ($where == 'trailing') { $leading = ''; @@ -533,7 +562,7 @@ class CI_URI { { $trailing = ''; } - + return $leading.$this->$which($n).$trailing; } -- cgit v1.2.3-24-g4f1b