From: Chuck Hagenbuch Date: Sat, 24 Jan 2009 20:49:26 +0000 (-0500) Subject: initial command-line request and response classes X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=d0f4253bf4358852e741658fc98174cb103afa04;p=horde.git initial command-line request and response classes --- diff --git a/framework/Controller/lib/Horde/Controller/Request/Cli.php b/framework/Controller/lib/Horde/Controller/Request/Cli.php new file mode 100644 index 000000000..7f46a59cd --- /dev/null +++ b/framework/Controller/lib/Horde/Controller/Request/Cli.php @@ -0,0 +1,81 @@ + + * @author Derek DeVries + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php + * @category Horde + * @package Horde_Controller + * @subpackage Request + */ + +/** + * Represents a command line invocation. + * + * @author Mike Naberezny + * @author Derek DeVries + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php + * @category Horde + * @package Horde_Controller + * @subpackage Request + */ +class Horde_Controller_Request_Cli extends Horde_Controller_Request_Base +{ + /** + * Command line arguments + */ + protected $_argv; + + /** + */ + public function __construct($options = array()) + { + parent::__construct($options); + + $parser = new Horde_Argv_Parser(array('allowUnknownArgs' => true)); + list($this->_argv, $args) = $parser->parseArgs(); + if (count($args) != 1) { + throw new Horde_Controller_Exception("unknown command: " . implode(' ', $args)); + } + $this->_path = $args[0]; + } + + public function getUri() + { + return $this->getPath(); + } + + public function getPath() + { + return $this->_path; + } + + /** + * Get all command line parameters. + * some wacky loops to make sure that nested values in one + * param list don't overwrite other nested values + * + * @return array + */ + public function getParameters() + { + $allParams = array(); + $paramArrays = array($this->_pathParams, $this->_argv); + + foreach ($paramArrays as $params) { + foreach ((array)$params as $key => $value) { + if (!is_array($value) || !isset($allParams[$key])) { + $allParams[$key] = $value; + } else { + $allParams[$key] = array_merge($allParams[$key], $value); + } + } + } + return $allParams; + } + +} diff --git a/framework/Controller/lib/Horde/Controller/Response/Cli.php b/framework/Controller/lib/Horde/Controller/Response/Cli.php new file mode 100644 index 000000000..e638b5916 --- /dev/null +++ b/framework/Controller/lib/Horde/Controller/Response/Cli.php @@ -0,0 +1,26 @@ + + * @author Derek DeVries + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php + * @category Horde + * @package Horde_Controller + * @subpackage Response + */ + +/** + * @author Mike Naberezny + * @author Derek DeVries + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php + * @category Horde + * @package Horde_Controller + * @subpackage Response + */ +class Horde_Controller_Response_Cli extends Horde_Controller_Response_Base +{ +} diff --git a/framework/Controller/package.xml b/framework/Controller/package.xml index b2cc149ad..0e47ffa85 100644 --- a/framework/Controller/package.xml +++ b/framework/Controller/package.xml @@ -41,11 +41,13 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + @@ -80,9 +82,11 @@ http://pear.php.net/dtd/package-2.0.xsd"> + +