{
$parser = self::_prepareParser($parameters);
$config = self::_prepareConfig($parser);
- $modules = self::_prepareModules();
+ if (isset($parameters['dependencies'])
+ && $parameters['dependencies'] instanceOf Components_Dependencies) {
+ $dependencies = $parameters['dependencies'];
+ } else {
+ $dependencies = new Components_Dependencies_Injector(
+ $config
+ );
+ }
+ $modules = self::_prepareModules($dependencies);
$config->handleModules($modules);
try {
self::_validateArguments($config);
return $config;
}
- static private function _prepareModules()
+ static private function _prepareModules(Components_Dependencies $dependencies)
{
- $modules = new Components_Modules();
+ $modules = new Components_Modules($dependencies);
$modules->addModulesFromDirectory(dirname(__FILE__) . '/Components/Module');
return $modules;
}
--- /dev/null
+<?php
+/**
+ * The Components_Dependencies:: interface is a central broker for
+ * providing the dependencies to the different application parts.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Components
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Components
+ */
+
+/**
+ * The Components_Dependencies:: interface is a central broker for
+ * providing the dependencies to the different application parts.
+ *
+ * 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 Components
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Components
+ */
+interface Components_Dependencies
+{
+ /**
+ * Returns the installer for a package.
+ *
+ * @return Components_Runner_Installer The installer.
+ */
+ public function getRunnerInstaller();
+}
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * The Components_Dependencies_Injector:: class provides the
+ * Components dependencies based on the Horde injector.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Components
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Components
+ */
+
+/**
+ * The Components_Dependencies_Injector:: class provides the
+ * Components dependencies based on the Horde injector.
+ *
+ * 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 Components
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Components
+ */
+class Components_Dependencies_Injector
+extends Horde_Injector
+implements Components_Dependencies
+{
+ /**
+ * Constructor.
+ *
+ * @param Components_Config $config The configuration.
+ */
+ public function __construct(Components_Config $config)
+ {
+ parent::__construct(new Horde_Injector_TopLevel());
+ $this->setInstance('Components_Config', $config);
+ }
+
+ /**
+ * Returns the installer for a package.
+ *
+ * @return Components_Runner_Installer The installer.
+ */
+ public function getRunnerInstaller()
+ {
+ return $this->getInstance('Components_Runner_Installer');
+ }
+}
\ No newline at end of file
*/
interface Components_Module
{
+ /**
+ * Return the title for the option group representing this module.
+ *
+ * @return string The group title.
+ */
public function getOptionGroupTitle();
+ /**
+ * Return the description for the option group representing this module.
+ *
+ * @return string The group description.
+ */
public function getOptionGroupDescription();
+ /**
+ * Return the options for this module.
+ *
+ * @return array The group options.
+ */
public function getOptionGroupOptions();
+ /**
+ * Determine if this module should act. Run all required actions if it has
+ * been instructed to do so.
+ *
+ * @return NULL
+ */
public function handle(Components_Config $config);
-
- public function run(Components_Config $config);
}
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * Components_Module_Base:: provides core functionality for the
+ * different modules.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Components
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Components
+ */
+
+/**
+ * Components_Module_Base:: provides core functionality for the
+ * different modules.
+ *
+ * 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 Components
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Components
+ */
+abstract class Components_Module_Base
+implements Components_Module
+{
+ /**
+ * The dependency provider.
+ *
+ * @var Components_Dependencies
+ */
+ protected $_dependencies;
+
+ /**
+ * Constructor.
+ *
+ * @param Components_Dependencies $dependencies The dependency provider.
+ */
+ public function __construct(Components_Dependencies $dependencies)
+ {
+ $this->_dependencies = $dependencies;
+ }
+}
\ No newline at end of file
* @link http://pear.horde.org/index.php?package=Components
*/
class Components_Module_Installer
-implements Components_Module
+extends Components_Module_Base
{
- private $_run;
-
+ /**
+ * Return the title for the option group representing this module.
+ *
+ * @return string The group title.
+ */
public function getOptionGroupTitle()
{
return 'Installer';
}
+ /**
+ * Return the description for the option group representing this module.
+ *
+ * @return string The group description.
+ */
public function getOptionGroupDescription()
{
return 'This module installs a Horde element including its dependencies.';
}
+ /**
+ * Return the options for this module.
+ *
+ * @return array The group options.
+ */
public function getOptionGroupOptions()
{
return array(
);
}
+ /**
+ * Determine if this module should act. Run all required actions if it has
+ * been instructed to do so.
+ *
+ * @return NULL
+ */
public function handle(Components_Config $config)
{
$options = $config->getOptions();
if (!empty($options['install'])) {
- $this->run($config);
- }
- }
-
- public function run(Components_Config $config)
- {
- $options = $config->getOptions();
- $pear = new PEAR();
- $pear->setErrorHandling(PEAR_ERROR_DIE);
-
- $pearrc = $options['install'] . DIRECTORY_SEPARATOR . '.pearrc';
- $command_config = new PEAR_Command_Config(new PEAR_Frontend_CLI(), new stdClass);
- $command_config->doConfigCreate(
- 'config-create', array(), array($options['install'], $pearrc)
- );
-
- $pear_config = new PEAR_Config($pearrc);
- $GLOBALS['_PEAR_Config_instance'] = $pear_config;
-
- $channel = new PEAR_Command_Channels(
- new PEAR_Frontend_CLI(),
- $pear_config
- );
- $channel->doDiscover('channel-discover', array(), array('pear.horde.org'));
- $channel->doDiscover('channel-discover', array(), array('pear.phpunit.de'));
-
- $installer = new PEAR_Command_Install(
- new PEAR_Frontend_CLI(),
- $pear_config
- );
-
- $arguments = $config->getArguments();
- $element = basename(realpath($arguments[0]));
- $root_path = dirname(realpath($arguments[0]));
-
- $this->_run = array();
-
- $this->_installHordeDependency(
- $installer,
- $pear_config,
- $root_path,
- $element
- );
- }
-
- /**
- * Install a Horde dependency from the current tree (the framework).
- *
- * @param PEAR_Command_Install $installer Installs the dependency.
- * @param PEAR_Config $pear_config The configuration of the PEAR
- * environment in which the
- * dependency will be installed.
- * @param string $root_path Root path to the Horde framework.
- * @param string $dependency Package name of the dependency.
- */
- private function _installHordeDependency(
- PEAR_Command_Install $installer,
- PEAR_Config $pear_config,
- $root_path,
- $dependency
- ) {
- $package_file = $root_path . DIRECTORY_SEPARATOR
- . $dependency . DIRECTORY_SEPARATOR . 'package.xml';
-
- $parser = new PEAR_PackageFile_Parser_v2();
- $parser->setConfig($pear_config);
- $pkg = $parser->parse(file_get_contents($package_file), $package_file);
-
- $dependencies = $pkg->getDeps();
- foreach ($dependencies as $dependency) {
- if (isset($dependency['channel']) && $dependency['channel'] != 'pear.horde.org') {
- $key = $dependency['channel'] . '/' . $dependency['name'];
- if (in_array($key, $this->_run)) {
- continue;
- }
- $installer->doInstall(
- 'install',
- array(
- 'force' => true,
- 'channel' => $dependency['channel'],
- ),
- array($dependency['name'])
- );
- $this->_run[] = $key;
- } else if (isset($dependency['channel'])) {
- $key = $dependency['channel'] . '/' . $dependency['name'];
- if (in_array($key, $this->_run)) {
- continue;
- }
- $this->_run[] = $key;
- $this->_installHordeDependency(
- $installer,
- $pear_config,
- $root_path,
- $dependency['name']
- );
- }
+ $this->_dependencies->getRunnerInstaller()->run();
}
- if (in_array($package_file, $this->_run)) {
- return;
- }
- $installer->doInstall(
- 'install',
- array('nodeps' => true),
- array($package_file)
- );
- $this->_run[] = $package_file;
}
}
private $_modules;
/**
+ * The dependency provider.
+ *
+ * @var Components_Dependencies
+ */
+ private $_dependencies;
+
+ /**
* Constructor.
+ *
+ * @param Components_Dependencies $dependencies The dependency provider.
*/
- public function __construct()
+ public function __construct(Components_Dependencies $dependencies)
{
+ $this->_dependencies = $dependencies;
$this->_modules = array();
}
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($module_directory)) as $file) {
if ($file->isFile() && preg_match('/.php$/', $file->getFilename())) {
$class = $base . preg_replace("/^(.*)\.php/", '\\1', $file->getFilename());
- $this->_modules[$class] = new $class();
+ if ($class != 'Components_Module_Base') {
+ $this->_modules[$class] = new $class($this->_dependencies);
+ }
}
}
}
--- /dev/null
+<?php
+/**
+ * Components_Runner_Installer:: installs a Horde component including its
+ * dependencies.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Components
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Components
+ */
+
+/**
+ * Components_Runner_Installer:: installs a Horde component including its
+ * dependencies.
+ *
+ * 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 Components
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Components
+ */
+class Components_Runner_Installer
+{
+ private $_run;
+
+ /**
+ * The configuration for the current job.
+ *
+ * @param Components_Config
+ */
+ private $_config;
+
+ /**
+ * Constructor.
+ *
+ * @param Components_Config $config The configuration for the current job.
+ */
+ public function __construct(Components_Config $config)
+ {
+ $this->_config = $config;
+ }
+
+ public function run()
+ {
+ $options = $this->_config->getOptions();
+ $pear = new PEAR();
+ $pear->setErrorHandling(PEAR_ERROR_DIE);
+
+ $pearrc = $options['install'] . DIRECTORY_SEPARATOR . '.pearrc';
+ $command_config = new PEAR_Command_Config(new PEAR_Frontend_CLI(), new stdClass);
+ $command_config->doConfigCreate(
+ 'config-create', array(), array($options['install'], $pearrc)
+ );
+
+ $pear_config = new PEAR_Config($pearrc);
+ $GLOBALS['_PEAR_Config_instance'] = $pear_config;
+
+ $channel = new PEAR_Command_Channels(
+ new PEAR_Frontend_CLI(),
+ $pear_config
+ );
+ $channel->doDiscover('channel-discover', array(), array('pear.horde.org'));
+ $channel->doDiscover('channel-discover', array(), array('pear.phpunit.de'));
+
+ $installer = new PEAR_Command_Install(
+ new PEAR_Frontend_CLI(),
+ $pear_config
+ );
+
+ $arguments = $this->_config->getArguments();
+ $element = basename(realpath($arguments[0]));
+ $root_path = dirname(realpath($arguments[0]));
+
+ $this->_run = array();
+
+ $this->_installHordeDependency(
+ $installer,
+ $pear_config,
+ $root_path,
+ $element
+ );
+ }
+
+ /**
+ * Install a Horde dependency from the current tree (the framework).
+ *
+ * @param PEAR_Command_Install $installer Installs the dependency.
+ * @param PEAR_Config $pear_config The configuration of the PEAR
+ * environment in which the
+ * dependency will be installed.
+ * @param string $root_path Root path to the Horde framework.
+ * @param string $dependency Package name of the dependency.
+ */
+ private function _installHordeDependency(
+ PEAR_Command_Install $installer,
+ PEAR_Config $pear_config,
+ $root_path,
+ $dependency
+ ) {
+ $package_file = $root_path . DIRECTORY_SEPARATOR
+ . $dependency . DIRECTORY_SEPARATOR . 'package.xml';
+ if (!file_exists($package_file)) {
+ $package_file = $root_path . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR
+ . $dependency . DIRECTORY_SEPARATOR . 'package.xml';
+ }
+
+ $parser = new PEAR_PackageFile_Parser_v2();
+ $parser->setConfig($pear_config);
+ $pkg = $parser->parse(file_get_contents($package_file), $package_file);
+
+ $dependencies = $pkg->getDeps();
+ foreach ($dependencies as $dependency) {
+ if (isset($dependency['channel']) && $dependency['channel'] != 'pear.horde.org') {
+ $key = $dependency['channel'] . '/' . $dependency['name'];
+ if (in_array($key, $this->_run)) {
+ continue;
+ }
+ $installer->doInstall(
+ 'install',
+ array(
+ 'force' => true,
+ 'channel' => $dependency['channel'],
+ ),
+ array($dependency['name'])
+ );
+ $this->_run[] = $key;
+ } else if (isset($dependency['channel'])) {
+ $key = $dependency['channel'] . '/' . $dependency['name'];
+ if (in_array($key, $this->_run)) {
+ continue;
+ }
+ $this->_run[] = $key;
+ $this->_installHordeDependency(
+ $installer,
+ $pear_config,
+ $root_path,
+ $dependency['name']
+ );
+ }
+ }
+ if (in_array($package_file, $this->_run)) {
+ return;
+ }
+ $installer->doInstall(
+ 'install',
+ array('nodeps' => true),
+ array($package_file)
+ );
+ $this->_run[] = $package_file;
+ }
+}
<email>jan@horde.org</email>
<active>yes</active>
</lead>
- <date>2010-08-25</date>
- <time>09:00:14</time>
+ <date>2010-09-06</date>
+ <time>09:33:23</time>
<version>
<release>0.0.1</release>
<api>0.0.1</api>
</dir> <!-- /data -->
<dir name="lib">
<dir name="Components">
- <dir name="Config">
- <file name="Cli.php" role="php" />
- </dir> <!-- /lib/Components/Config -->
- <dir name="Module">
- <file name="CiSetup.php" role="php" />
- <file name="DevPackage.php" role="php" />
- <file name="Installer.php" role="php" />
- <file name="PearPackageXml.php" role="php" />
- </dir> <!-- /lib/Components/Module -->
- <file name="Config.php" role="php" />
- <file name="Configs.php" role="php" />
- <file name="Constants.php" role="php">
- <replace from="@data_dir@" to="data_dir" type="pear-config"/>
- </file>
- <file name="Exception.php" role="php" />
- <file name="Module.php" role="php" />
- <file name="Modules.php" role="php" />
- </dir> <!-- /lib/Components -->
- <file name="Components.php" role="php" />
+ <dir name="Config">
+ <file name="Cli.php" role="php" />
+ </dir> <!-- /lib/Components/Config -->
+ <dir name="Dependencies">
+ <file name="Injector.php" role="php" />
+ </dir> <!-- /lib/Components/Dependencies -->
+ <dir name="Module">
+ <file name="Base.php" role="php" />
+ <file name="CiSetup.php" role="php" />
+ <file name="DevPackage.php" role="php" />
+ <file name="Installer.php" role="php" />
+ <file name="PearPackageXml.php" role="php" />
+ </dir> <!-- /lib/Components/Module -->
+ <dir name="Runner">
+ <file name="Installer.php" role="php" />
+ </dir> <!-- /lib/Components/Runner -->
+ <file name="Config.php" role="php" />
+ <file name="Configs.php" role="php" />
+ <file name="Constants.php" role="php">
+ <replace from="@data_dir@" to="data_dir" type="pear-config"/>
+ </file>
+ <file name="Dependencies.php" role="php" />
+ <file name="Exception.php" role="php" />
+ <file name="Module.php" role="php" />
+ <file name="Modules.php" role="php" />
+ </dir> <!-- /lib/Components -->
+ <file name="Components.php" role="php" />
</dir> <!-- /lib -->
<dir name="script">
<file name="horde-components.php" role="script" />
</dir> <!-- /script -->
<dir name="test">
<dir name="Components">
- <dir name="fixture">
- <dir name="simple">
- <dir name="lib">
- <file name="New.php" role="test" />
- <file name="Second.php" role="test" />
- </dir> <!-- /test/Components/fixture/simple/lib -->
- </dir> <!-- /test/Components/fixture/simple -->
- </dir> <!-- /test/Components/fixture -->
- <dir name="Integration">
- <file name="ComponentsTest.php" role="test" />
- </dir> <!-- /test/Components/Integration -->
- <dir name="Stub">
- <file name="Parser.php" role="test" />
- </dir> <!-- /test/Components/Stub -->
- <file name="AllTests.php" role="test" />
- <file name="Autoload.php" role="test" />
- <file name="phpunit.xml" role="test" />
- <file name="StoryTestCase.php" role="test" />
- </dir> <!-- /test/Components -->
+ <dir name="fixture">
+ <dir name="channels">
+ <file name="pear.horde.org.channel.xml" role="test" />
+ <file name="pear.php.net.channel.xml" role="test" />
+ <file name="pear.phpunit.de.channel.xml" role="test" />
+ </dir> <!-- /test/Components/fixture/channels -->
+ <dir name="simple">
+ <dir name="lib">
+ <file name="New.php" role="test" />
+ <file name="Second.php" role="test" />
+ </dir> <!-- /test/Components/fixture/simple/lib -->
+ </dir> <!-- /test/Components/fixture/simple -->
+ </dir> <!-- /test/Components/fixture -->
+ <dir name="Integration">
+ <file name="ComponentsTest.php" role="test" />
+ </dir> <!-- /test/Components/Integration -->
+ <dir name="Stub">
+ <file name="Parser.php" role="test" />
+ </dir> <!-- /test/Components/Stub -->
+ <file name="AllTests.php" role="test" />
+ <file name="Autoload.php" role="test" />
+ <file name="phpunit.xml" role="test" />
+ <file name="StoryTestCase.php" role="test" />
+ </dir> <!-- /test/Components -->
</dir> <!-- /test -->
<file name="COPYING" role="doc" />
</dir> <!-- / -->
<install as="Components/Config.php" name="lib/Components/Config.php" />
<install as="Components/Configs.php" name="lib/Components/Configs.php" />
<install as="Components/Constants.php" name="lib/Components/Constants.php" />
+ <install as="Components/Dependencies.php" name="lib/Components/Dependencies.php" />
<install as="Components/Exception.php" name="lib/Components/Exception.php" />
<install as="Components/Module.php" name="lib/Components/Module.php" />
<install as="Components/Modules.php" name="lib/Components/Modules.php" />
<install as="Components/Config/Cli.php" name="lib/Components/Config/Cli.php" />
+ <install as="Components/Dependencies/Injector.php" name="lib/Components/Dependencies/Injector.php" />
+ <install as="Components/Module/Base.php" name="lib/Components/Module/Base.php" />
<install as="Components/Module/CiSetup.php" name="lib/Components/Module/CiSetup.php" />
<install as="Components/Module/DevPackage.php" name="lib/Components/Module/DevPackage.php" />
<install as="Components/Module/Installer.php" name="lib/Components/Module/Installer.php" />
<install as="Components/Module/PearPackageXml.php" name="lib/Components/Module/PearPackageXml.php" />
+ <install as="Components/Runner/Installer.php" name="lib/Components/Runner/Installer.php" />
<install as="horde-components" name="script/horde-components.php" />
<install as="Components/AllTests.php" name="test/Components/AllTests.php" />
<install as="Components/Autoload.php" name="test/Components/Autoload.php" />
<install as="Components/phpunit.xml" name="test/Components/phpunit.xml" />
<install as="Components/StoryTestCase.php" name="test/Components/StoryTestCase.php" />
+ <install as="Components/fixture/channels/pear.horde.org.channel.xml" name="test/Components/fixture/channels/pear.horde.org.channel.xml" />
+ <install as="Components/fixture/channels/pear.php.net.channel.xml" name="test/Components/fixture/channels/pear.php.net.channel.xml" />
+ <install as="Components/fixture/channels/pear.phpunit.de.channel.xml" name="test/Components/fixture/channels/pear.phpunit.de.channel.xml" />
<install as="Components/fixture/simple/lib/New.php" name="test/Components/fixture/simple/lib/New.php" />
<install as="Components/fixture/simple/lib/Second.php" name="test/Components/fixture/simple/lib/Second.php" />
<install as="Components/Integration/ComponentsTest.php" name="test/Components/Integration/ComponentsTest.php" />
<release>alpha</release>
<api>alpha</api>
</stability>
- <date>2010-08-25</date>
+ <date>2010-09-06</date>
<license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
<notes>
* Initial release