Skip to content

Commit

Permalink
Implement modular cli and a config editing module (Request #12923).
Browse files Browse the repository at this point in the history
  • Loading branch information
ralflang committed Jan 23, 2014
1 parent ccafece commit a90e4c0
Show file tree
Hide file tree
Showing 8 changed files with 672 additions and 2 deletions.
29 changes: 28 additions & 1 deletion framework/Core/lib/Horde/Config.php
Expand Up @@ -154,6 +154,33 @@ public function configFile()
return $configFile;
}

/**
* Retrieve the XML default value of a given config item
* @param array $queryPath An array of name parameters
* @throws Horde_Exception On bad query
* @return string|boolean The default value
*/
public function getXmlDefaultValue(array $queryPath)
{
/* This could use some caching */
$path = $GLOBALS['registry']->get('fileroot', $this->_app) . '/config';
$dom = new DOMDocument();
$dom->load($path . '/conf.xml');
$xpath = new DOMXpath($dom);

$queryString = "/";
foreach ($queryPath as $level) {
$queryString .= "/*[@name='$level']";
}
$nodes = $xpath->query($queryString);
/*TODO: Support for conf.d/*.xml */
/*TODO: Support for config specials */
if ($nodes->length!=1) {
throw new Horde_Exception(_("Ambiguous Query String"));
}
return $nodes->item(0)->textContent;
}

/**
* Reads the application's conf.xml file and builds an associative array
* from its XML tree.
Expand Down Expand Up @@ -415,7 +442,7 @@ protected function _generatePHPConfig($section, $prefix, $formvars)
if (is_bool($val)) {
$value = $val ? 'true' : 'false';
} else {
$value = ($val == 'on') ? 'true' : 'false';
$value = in_array($val, array('on', 'true')) ? 'true' : 'false';
}
break;

Expand Down
2 changes: 2 additions & 0 deletions framework/Core/package.xml
Expand Up @@ -39,6 +39,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [rla] Add method to get conf.xml defaults when conf.php is present for (Request #12923).
* [mms] Store registry cache on the local filesystem.
* [mms] Refactor alarm code to prevent the need from accessing the themes cache on every server access.
* [mms] Prevent avalanche effect from occurring when re-creating cached JS files.
Expand Down Expand Up @@ -3296,6 +3297,7 @@
<date>2014-01-23</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [rla] Add method to get conf.xml defaults when conf.php is present for (Request #12923).
* [mms] Store registry cache on the local filesystem.
* [mms] Refactor alarm code to prevent the need from accessing the themes cache on every server access.
* [mms] Prevent avalanche effect from occurring when re-creating cached JS files.
Expand Down
29 changes: 29 additions & 0 deletions horde/bin/horde-cli
@@ -0,0 +1,29 @@
#!/usr/bin/env php
<?php
/**
* Copyright 2013-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL-2). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl.
*
* @author Ralf Lang <lang@b1-systems.de>
* @category Horde
* @license http://www.horde.org/licenses/lgpl LGPL-2
* @package Horde
*/


if (strpos('@php_dir@', '@php_dir') === 0) {
set_include_path(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'lib' . PATH_SEPARATOR . get_include_path());
}

$baseFile = __DIR__ . '/../lib/Application.php';
if (file_exists($baseFile)) {
require_once $baseFile;
} else {
require_once 'PEAR/Config.php';
require_once PEAR_Config::singleton()
->get('horde_dir', null, 'pear.horde.org') . '/lib/Application.php';
}
Horde_Registry::appInit('horde', array('cli' => true, 'user_admin' => true));
AdminCli::main(array('cli' => $cli));
1 change: 1 addition & 0 deletions horde/docs/CHANGES
Expand Up @@ -2,6 +2,7 @@
v5.2.0-git
----------

[rla] Add modular horde-cli and module for conf.php editing (Request #12923).
[mms] By default, enforce maximum storage size on preferences values.
[mms] Support UglifyJS for compressing javascript.
[mjr] Add improved ActiveSync device administration page.
Expand Down
77 changes: 77 additions & 0 deletions horde/lib/AdminCli.php
@@ -0,0 +1,77 @@
<?php
/**
* The Cli:: class is the entry point for the various cli actions
* provided by horde-cli.
*
* PHP version 5
*
* @category Horde
* @package Horde
* @author Ralf Lang <lang@b1-systems.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Horde
*/

/**
* The AdminCli:: class is the entry point for the various cli actions
* provided by horde-cli.
*
* Copyright 2013-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Horde
* @author Ralf Lang <lang@b1-systems.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Horde
*/
class AdminCli
{

/**
* The main entry point for the application.
*
* @param array $parameters A list of named configuration parameters.
* <pre>
* 'cli' - (array) CLI configuration parameters.
* 'parser' - (array) Parser configuration parameters.
* 'class' - (string) The class name of the parser to use.
* </pre>
*/
static public function main(array $parameters = array())
{
$modular = new Horde_Cli_Modular(
array(
'parser' => array(
'class' => empty($parameters['parser']['class']) ? 'Horde_Argv_Parser' : $parameters['parser']['class'],
'usage' => "[options] [COMMAND]\n"),
'modules' => array(
'directory' => __DIR__ . '/AdminCli',
'exclude' => 'Base'
),
'provider' => array('prefix' => 'AdminCli_Module_')
)
);
$modules = $modular->getModules();
$parser = $modular->createParser();
list($options, $arguments) = $parser->parseArgs();

// get the provider by the first unparsed argument
if (count($arguments) == 0) {
$parser->printHelp();
exit;
}
$moduleName = $arguments[0];
$provider = $modular->getProvider();
try {
$module = $provider->getModule($moduleName);
} catch (Horde_Cli_Modular_Exception $e) {
print "Invalid Module\n";
$parser->printHelp();
exit;
}
$module->run($parameters['cli'], $options, $arguments);
}
}
94 changes: 94 additions & 0 deletions horde/lib/AdminCli/Module/Base.php
@@ -0,0 +1,94 @@
<?php
/**
* AdminCli_Module_Base:: provides core functionality for the
* different modules.
*
* PHP version 5
*
* @category Horde
* @package Horde
* @author Ralf Lang <lang@b1-systems.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Horde
*/

/**
* AdminCli_Module_Base:: provides core functionality for the
* different modules.
*
* Copyright 2013-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Horde
* @author Ralf Lang <lang@b1-systems.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Horde
*/
abstract class AdminCli_Module_Base
{
/**
* Get the usage description for this module.
*
* @return string The description.
*/
public function getUsage()
{
return '';
}

/**
* Get a set of base options that this module adds to the CLI argument
* parser.
*
* @return array The options.
*/
public function getBaseOptions()
{
return array();
}

/**
* Indicate if the module provides an option group.
*
* @return boolean True if an option group should be added.
*/
public function hasOptionGroup()
{
return true;
}

/**
* Return the action arguments supported by this module.
*
* @return array A list of supported action arguments.
*/
public function getActions()
{
return array();
}

/**
* Return the options that should be explained in the context help.
*
* @return array A list of option help texts.
*/
public function getContextOptionHelp()
{
return array();
}

/**
* Return the help text for the specified action.
*
* @param string $action The action.
*
* @return string The help text.
*/
public function getHelp($action)
{
return '';
}
}

0 comments on commit a90e4c0

Please sign in to comment.