*/
class Horde_Qc
{
- static public function main($parameters = array())
+ /**
+ * 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())
{
- $modules = new Horde_Qc_Modules();
- if (!isset($parameters['config'])) {
- $parameters['config'] = array();
- }
- $config = new Horde_Qc_Config($parameters['config']);
- $modules->addModulesFromDirectory(dirname(__FILE__) . '/Qc/Module');
+ $parser = self::_prepareParser($parameters);
+ $config = self::_prepareConfig($parser);
+ $modules = self::_prepareModules();
$config->handleModules($modules);
+ try {
+ self::_validateArguments($config->getArguments());
+ } catch (Horde_Qc_Exception $e) {
+ $parser->parserError($e->getMessage());
+ return;
+ }
+ $options = $config->getOptions();
foreach ($modules as $module) {
- $module->handle($config->getOptions());
+ $module->handle($options);
+ }
+ }
+
+ static private function _prepareParser(array $parameters = array())
+ {
+ if (empty($parameters['cli']['parser']['class'])) {
+ $parser_class = 'Horde_Argv_Parser';
+ } else {
+ $parser_class = $parameters['cli']['parser']['class'];
+ }
+ return new $parser_class(
+ array(
+ 'usage' => '%prog ' . _("[options] PACKAGE_PATH")
+ )
+ );
+ }
+
+ static private function _prepareConfig(Horde_Argv_Parser $parser)
+ {
+ $config = new Horde_Qc_Configs();
+ $config->addConfigurationType(
+ new Horde_Qc_Config_Cli(
+ $parser
+ )
+ );
+ return $config;
+ }
+
+ static private function _prepareModules()
+ {
+ $modules = new Horde_Qc_Modules();
+ $modules->addModulesFromDirectory(dirname(__FILE__) . '/Qc/Module');
+ return $modules;
+ }
+
+ static private function _validateArguments(array $arguments)
+ {
+ if (empty($arguments[0])) {
+ throw new Horde_Qc_Exception('Please specify the path of the PEAR package!');
+ }
+
+ if (!is_dir($arguments[0])) {
+ throw new Horde_Qc_Exception(sprintf('%s specifies no directory!', $arguments[0]));
+ }
+
+ if (!file_exists($arguments[0] . '/package.xml')) {
+ throw new Horde_Qc_Exception(sprintf('There is no package.xml at %s!', $arguments[0]));
}
}
}
\ No newline at end of file
<?php
/**
- * Horde_Qc_Config:: class represents configuration for the Horde quality
- * control tool.
+ * Horde_Qc_Config:: interface represents a configuration type for the Horde
+ * quality control tool.
*
* PHP version 5
*
*/
/**
- * Horde_Qc_Config:: class represents configuration for the Horde quality
- * control tool.
+ * Horde_Qc_Config:: interface represents a configuration type for the Horde
+ * quality control tool.
*
* Copyright 2009-2010 The Horde Project (http://www.horde.org/)
*
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Qc
*/
-class Horde_Qc_Config
+interface Horde_Qc_Config
{
-
- /**
- * The different configuration handlers.
- *
- * @var array
- */
- private $_configs;
-
- /**
- * Constructor.
- *
- * @param array $parameters A list of named configuration parameters.
- * <pre>
- * 'cli' - (array) See Horde_Qc_Config_Cli.
- * </pre>
- */
- public function __construct(
- $parameters = array()
- ) {
- if (!isset($parameters['cli'])) {
- $parameters['cli'] = array();
- }
- $this->_configs = array();
- $this->_configs[] = new Horde_Qc_Config_Cli(
- $parameters['cli']
- );
- }
-
/**
* Provide each configuration handler with the list of supported modules.
*
* @param Horde_Qc_Modules $modules A list of modules.
* @return NULL
*/
- public function handleModules(Horde_Qc_Modules $modules)
- {
- foreach ($this->_configs as $config) {
- $config->handleModules($modules);
- }
- }
+ public function handleModules(Horde_Qc_Modules $modules);
/**
- * Return the options provided by the configuration hadnlers.
+ * Return the options provided by the configuration handlers.
*
* @return array An array of options.
*/
- public function getOptions()
- {
- $options = array();
- foreach ($this->_configs as $config) {
- if (count($config->getOptions()) !== 0) {
- $config_options = array();
- foreach ($config->getOptions() as $name => $option) {
- $config_options[$name] = $option;
- }
- $options = array_merge($options, $config_options);
- }
- }
- return $options;
- }
+ public function getOptions();
+ /**
+ * Return the arguments provided by the configuration handlers.
+ *
+ * @return array An array of arguments.
+ */
+ public function getArguments();
}
\ No newline at end of file
* @link http://pear.horde.org/index.php?package=Qc
*/
class Horde_Qc_Config_Cli
+implements Horde_Qc_Config
{
/**
* The command line argument parser.
*
* @var array
*/
- private $_opts;
+ private $_options;
/**
* Any additional arguments parsed from the command line.
*
* @var array
*/
- private $_args;
+ private $_arguments;
/**
* Constructor.
*
- * @param array $parameters A list of named configuration parameters.
- * <pre>
- * 'parser' - (array) Parser configuration parameters.
- * 'class' - (string) The class name of the parser to use.
- * </pre>
*/
public function __construct(
- $parameters = array()
+ Horde_Argv_Parser $parser
) {
- if (empty($parameters['parser']['class'])) {
- $parser_class = 'Horde_Argv_Parser';
- } else {
- $parser_class = $parameters['parser']['class'];
- }
- $this->_parser = new $parser_class(
- array(
- 'usage' => '%prog ' . _("[options] PACKAGE_PATH")
- )
- );
-
+ $this->_parser = $parser;
}
/**
$this->_addOptionsFromModule($this->_parser, $module);
}
- list($this->_opts, $this->_args) = $this->_parser->parseArgs();
+ list($this->_options, $this->_arguments) = $this->_parser->parseArgs();
}
/**
* Return the options parsed from the command line.
*
- * @return array An array of options.
+ * @return Horde_Argv_Values The option values.
*/
public function getOptions()
{
- return $this->_opts;
+ return $this->_options;
+ }
+
+ /**
+ * Return the arguments parsed from the command line.
+ *
+ * @return array An array of arguments.
+ */
+ public function getArguments()
+ {
+ return $this->_arguments;
}
/**
--- /dev/null
+<?php
+/**
+ * Horde_Qc_Configs:: class represents configuration for the Horde quality
+ * control tool.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Qc
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Qc
+ */
+
+/**
+ * Horde_Qc_Configs:: class represents configuration for the Horde quality
+ * control tool.
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Qc
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Qc
+ */
+class Horde_Qc_Configs
+implements Horde_Qc_Config
+{
+
+ /**
+ * The different configuration handlers.
+ *
+ * @var array
+ */
+ private $_configs;
+
+ /**
+ * Constructor.
+ */
+ public function __construct() {
+ $this->_configs = array();
+ }
+
+ /**
+ * Add a configuration type to the configuration handler.
+ *
+ * @param Horde_Qc_Config $type The configuration type.
+ *
+ * @return NULL
+ */
+ public function addConfigurationType(Horde_Qc_Config $type) {
+ $this->_configs[] = $type;
+ }
+
+ /**
+ * Provide each configuration handler with the list of supported modules.
+ *
+ * @param Horde_Qc_Modules $modules A list of modules.
+ * @return NULL
+ */
+ public function handleModules(Horde_Qc_Modules $modules)
+ {
+ foreach ($this->_configs as $config) {
+ $config->handleModules($modules);
+ }
+ }
+
+ /**
+ * Return the options provided by the configuration handlers.
+ *
+ * @return array An array of options.
+ */
+ public function getOptions()
+ {
+ $options = array();
+ foreach ($this->_configs as $config) {
+ if (count($config->getOptions()) !== 0) {
+ $config_options = array();
+ foreach ($config->getOptions() as $name => $option) {
+ $config_options[$name] = $option;
+ }
+ $options = array_merge($options, $config_options);
+ }
+ }
+ return $options;
+ }
+
+ /**
+ * Return the arguments provided by the configuration handlers.
+ *
+ * @return array An array of arguments.
+ */
+ public function getArguments()
+ {
+ $arguments = array();
+ foreach ($this->_configs as $config) {
+ $config_arguments = $config->getArguments();
+ if (!empty($config_arguments)) {
+ $arguments = array_merge($arguments, $config_arguments);
+ }
+ }
+ return $arguments;
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * This class provides the standard error class for the Qc package.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Qc
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Qc
+ */
+
+/**
+ * This class provides the standard error class for the Qc package.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Qc
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Qc
+ */
+class Horde_Qc_Exception
+extends Exception
+{
+}
<file name="Cli.php" role="php" />
</dir> <!-- /lib/Horde/Qc/Config -->
<file name="Config.php" role="php" />
+ <file name="Configs.php" role="php" />
+ <file name="Exception.php" role="php" />
<dir name="Module">
<file name="PearPackageXml.php" role="php" />
</dir> <!-- /lib/Horde/Qc/Module -->
<install as="Horde/Qc/Autoloader.php" name="lib/Horde/Qc/Autoloader.php" />
<install as="Horde/Qc/Config.php" name="lib/Horde/Qc/Config.php" />
<install as="Horde/Qc/Config/Cli.php" name="lib/Horde/Qc/Config/Cli.php" />
+ <install as="Horde/Qc/Configs.php" name="lib/Horde/Qc/Configs.php" />
+ <install as="Horde/Qc/Exception.php" name="lib/Horde/Qc/Exception.php" />
<install as="Horde/Qc/Module.php" name="lib/Horde/Qc/Module.php" />
<install as="Horde/Qc/Module/PearPackageXml.php" name="lib/Horde/Qc/Module/PearPackageXml.php" />
<install as="Horde/Qc/Modules.php" name="lib/Horde/Qc/Modules.php" />
{
switch($action) {
case 'calling the package with the help option':
- $_SERVER['argv'] = array('hqc', '--help', '--packagexml');
+ $_SERVER['argv'] = array(
+ 'hqc',
+ '--help',
+ '--packagexml',
+ dirname(__FILE__) . '/fixture'
+ );
ob_start();
$parameters = array();
- $parameters['config']['cli']['parser']['class'] = 'Horde_Qc_Stub_Parser';
+ $parameters['cli']['parser']['class'] = 'Horde_Qc_Stub_Parser';
Horde_Qc::main($parameters);
$world['output'] = ob_get_contents();
ob_end_clean();