From 25e8f74b6a562abc46067d0183d7e605b0c39ae3 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Sat, 30 May 2009 11:02:48 -0400 Subject: [PATCH] - Handle "-" in command-line controller names automatically - Allow much more flexibility in setting the path for command line requests --- .../lib/Horde/Controller/Request/Cli.php | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/framework/Controller/lib/Horde/Controller/Request/Cli.php b/framework/Controller/lib/Horde/Controller/Request/Cli.php index a0ec8105c..ea3dd78ee 100644 --- a/framework/Controller/lib/Horde/Controller/Request/Cli.php +++ b/framework/Controller/lib/Horde/Controller/Request/Cli.php @@ -36,15 +36,7 @@ class Horde_Controller_Request_Cli extends Horde_Controller_Request_Base { parent::__construct($options); - $parser = new Horde_Argv_Parser(array( - 'allowUnknownArgs' => true, - 'addHelpOption' => false, - )); - list($this->_argv, $args) = $parser->parseArgs(); - if (!count($args)) { - throw new Horde_Controller_Exception('unknown command: ' . implode(' ', $args)); - } - $this->_path = $args[0]; + $this->setPath(); } public function getUri() @@ -57,6 +49,29 @@ class Horde_Controller_Request_Cli extends Horde_Controller_Request_Base return $this->_path; } + public function setPath($args = null) + { + if (is_string($args)) { + $this->_path = $args; + } else { + if ($args instanceof Horde_Argv_Parser) { + $parser = $args; + } else { + $parser = new Horde_Argv_Parser(array( + 'allowUnknownArgs' => true, + 'addHelpOption' => false, + )); + } + + list($this->_argv, $args) = $parser->parseArgs(); + if (!count($args)) { + throw new Horde_Controller_Exception('unknown command: ' . implode(' ', $args)); + } + $this->_path = $args[0]; + $this->_path = str_replace('-', '_', $this->_path); + } + } + /** * Get all command line parameters. * some wacky loops to make sure that nested values in one -- 2.11.0