Skip to content

Commit

Permalink
Route method calls to Horde_Argv_Parser and Horde_Cli.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed May 24, 2017
1 parent 7658bc5 commit 4057c6b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
Expand Up @@ -13,4 +13,4 @@ require __DIR__ . '/MyApplication.php';
$app = new MyApplication();
$app->run();

$app->cli->writeln($app->values->int);
$app->writeln($app->values->int);
45 changes: 22 additions & 23 deletions framework/Cli_Application/lib/Horde/Cli/Application.php
Expand Up @@ -21,6 +21,9 @@
/**
* This class implements a complete command line application.
*
* The embedded Horde_Cli and Horde_Argv_Parser objects are proxied, so you can
* call any of their methods on the \Horde\Cli\Application object too.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @copyright 2017 Horde LLC
Expand Down Expand Up @@ -82,6 +85,25 @@ public function __construct(Cli $cli = null, array $parserArgs = array())
$this->_parser = new Parser($parserArgs);
}

/**
* Delegates calls to the embedded Horde_Cli and Horde_Argv_Parser objects.
*
* @param string $method Method name.
* @param array $args Method arguments.
*
* @return mixed Result of method call.
*/
public function __call($method, $args)
{
if (method_exists($this->_cli, $method)) {
return call_user_func_array(array($this->_cli, $method), $args);
}
if (method_exists($this->_parser, $method)) {
return call_user_func_array(array($this->_parser, $method), $args);
}
throw new BadMethodCallException('Undefined method ' . $method);
}

/**
* Getter.
*
Expand Down Expand Up @@ -122,27 +144,4 @@ public function run()
{
list($this->_values, $this->_arguments) = $this->_parser->parseArgs();
}

/**
* Overloaded method to add an argument option.
*
* <code>
* addOption(Horde_Argv_Option $option);
* addOption(string $option[, string $option...][, array $attributes]);
* </code>
* - string $option could be any number of short (-v) or long (--verbose)
* options.
* - $attributes is a hash of option attributes. See
* https://wiki.horde.org/Doc/Dev/HordeArgv for details.
*
* @param Horde_Argv_Option
* @return Horde_Argv_Option
*/
public function addOption()
{
return call_user_func_array(
array($this->_parser, 'addOption'),
func_get_args()
);
}
}

0 comments on commit 4057c6b

Please sign in to comment.