public function createPackageForInstallLocation($package_file, $config_file)
{
$package = $this->_dependencies->getInstance('Components_Pear_Package');
+ $package->setFactory($this);
$package->setEnvironment($this->createInstallLocation($config_file));
$package->setPackageXml($package_file);
return $package;
public function createPackageForDefaultLocation($package_file)
{
$package = $this->_dependencies->getInstance('Components_Pear_Package');
+ $package->setFactory($this);
$package->setEnvironment($this->_dependencies->getInstance('Components_Pear_InstallLocation'));
$package->setPackageXml($package_file);
return $package;
}
+ /**
+ * Return the PEAR Package representation.
+ *
+ * @param string $package_xml_path Path to the package.xml file.
+ * @param Components_Pear_InstallLocation $environment The PEAR environment.
+ *
+ * @return PEAR_PackageFile
+ */
+ public function getPackageFile(
+ $package_xml_path,
+ Components_Pear_InstallLocation $environment
+ )
+ {
+ $pkg = new PEAR_PackageFile($environment->getPearConfig());
+ $package_file = $pkg->fromPackageFile($package_xml_path, PEAR_VALIDATE_NORMAL);
+ if ($package_file instanceOf PEAR_Error) {
+ throw new Components_Exception($package_file->getMessage());
+ }
+ return $package_file;
+ }
+
+ /**
+ * Return a writeable PEAR Package representation.
+ *
+ * @param string $package_xml_path Path to the package.xml file.
+ * @param Components_Pear_InstallLocation $environment The PEAR environment.
+ *
+ * @return PEAR_PackageFileManager2
+ */
+ public function getPackageRwFile(
+ $package_xml_path,
+ Components_Pear_InstallLocation $environment
+ ) {
+ /**
+ * Ensure we setup the PEAR_Config according to the PEAR environment
+ * the user set.
+ */
+ $environment->getPearConfig();
+
+ if (!class_exists('PEAR_PackageFileManager2')) {
+ throw new Components_Exception(
+ 'The Package "PEAR_PackageFileManager2" is missing in the PEAR environment. Please install it so that you can run this action.'
+ );
+ }
+
+ $package_rw_file = PEAR_PackageFileManager2::importOptions(
+ $package_xml_path,
+ array(
+ 'packagedirectory' => dirname($package_xml_path),
+ 'filelistgenerator' => 'file',
+ 'clearcontents' => false,
+ 'clearchangelog' => false,
+ 'simpleoutput' => true,
+ 'ignore' => array('*~', 'conf.php', 'CVS/*'),
+ 'include' => '*',
+ 'dir_roles' =>
+ array(
+ 'doc' => 'doc',
+ 'example' => 'doc',
+ 'js' => 'horde',
+ 'lib' => 'php',
+ 'migration' => 'data',
+ 'script' => 'script',
+ 'test' => 'test',
+ ),
+ )
+ );
+
+ if ($package_rw_file instanceOf PEAR_Error) {
+ throw new Components_Exception($package_file->getMessage());
+ }
+ return $package_rw_file;
+ }
}
\ No newline at end of file
}
}
+ /**
+ * Set the paths to the resource directories.
+ *
+ * @param array $options The application options
+ *
+ * @return NULL
+ */
+ public function setResourceDirectories(array $options)
+ {
+ if (!empty($options['channelxmlpath'])) {
+ $this->setChannelDirectory($options['channelxmlpath']);
+ } else if (!empty($options['sourcepath'])) {
+ $this->setChannelDirectory($options['sourcepath']);
+ }
+ if (!empty($options['sourcepath'])) {
+ $this->setSourceDirectory($options['sourcepath']);
+ }
+ }
+
public function createPearConfig()
{
if (empty($this->_config_file)) {
private $_environment;
/**
+ * The factory for PEAR class instances.
+ *
+ * @param Components_Pear_Factory
+ */
+ private $_factory;
+
+ /**
* The path to the package XML file.
*
* @param string
}
/**
+ * Define the factory that creates our PEAR dependencies.
+ *
+ * @param Components_Pear_Factory
+ *
+ * @return NULL
+ */
+ public function setFactory(Components_Pear_Factory $factory)
+ {
+ $this->_factory = $factory;
+ }
+
+ /**
* Return the PEAR environment for this package.
*
* @return Components_Pear_InstallLocation
{
$this->_checkSetup();
if ($this->_package_file === null) {
- $config = $this->getEnvironment()->getPearConfig();
- $pkg = new PEAR_PackageFile($config);
- $this->_package_file = $pkg->fromPackageFile($this->_package_xml_path, PEAR_VALIDATE_NORMAL);
- if ($this->_package_file instanceOf PEAR_Error) {
- throw new Components_Exception($this->_package_file->getMessage());
- }
+ $this->_package_file = $this->_factory->getPackageFile(
+ $this->_package_xml_path,
+ $this->getEnvironment()
+ );
}
return $this->_package_file;
}
{
$this->_checkSetup();
if ($this->_package_rw_file === null) {
- /**
- * Ensure we setup the PEAR_Config according to the PEAR environment
- * the user set.
- */
- $this->getEnvironment()->getPearConfig();
-
- if (!class_exists('PEAR_PackageFileManager2')) {
- throw new Components_Exception(
- 'The Package "PEAR_PackageFileManager2" is missing in the PEAR environment. Please install it so that you can run this action.'
- );
- }
-
- $this->_package_rw_file = PEAR_PackageFileManager2::importOptions(
+ $this->_package_rw_file = $this->_factory->getPackageRwFile(
$this->_package_xml_path,
- array(
- 'packagedirectory' => dirname($this->_package_xml_path),
- 'filelistgenerator' => 'file',
- 'clearcontents' => false,
- 'clearchangelog' => false,
- 'simpleoutput' => true,
- 'ignore' => array('*~', 'conf.php', 'CVS/*'),
- 'include' => '*',
- 'dir_roles' =>
- array(
- 'doc' => 'doc',
- 'example' => 'doc',
- 'js' => 'horde',
- 'lib' => 'php',
- 'migration' => 'data',
- 'script' => 'script',
- 'test' => 'test',
- ),
- )
+ $this->getEnvironment()
);
-
- if ($this->_package_rw_file instanceOf PEAR_Error) {
- throw new Components_Exception($this->_package_file->getMessage());
- }
}
return $this->_package_rw_file;
}
*/
private function _checkSetup()
{
- if ($this->_environment === null || $this->_package_xml_path === null) {
- throw new Components_Exception('You need to set the environment and the path to the package file first!');
+ if ($this->_environment === null
+ || $this->_package_xml_path === null
+ || $this->_factory === null) {
+ throw new Components_Exception('You need to set the factory, the environment and the path to the package file first!');
}
}
private $_config;
/**
- * The install location.
+ * The factory for PEAR handlers.
*
- * @var Components_Pear_InstallLocation
+ * @var Components_Factory
*/
- private $_location;
+ private $_factory;
/**
* Constructor.
*
- * @param Components_Config $config The configuration for the current job.
- * @param Components_Pear_InstallLocation $location Represents the install
- * location and its
- * corresponding configuration.
+ * @param Components_Config $config The configuration for the current
+ * job.
+ * @param Components_Pear_Factory $factory Generator for all required PEAR
+ * components.
*/
public function __construct(
Components_Config $config,
- Components_Pear_InstallLocation $location
+ Components_Pear_Factory $factory
) {
$this->_config = $config;
- $this->_location = $location;
+ $this->_factory = $factory;
}
public function run()
if (!$location) {
$location = $options['install'];
}
- $this->_location->setLocation($location, '.pearrc');
- $pear_config = $this->_location->getPearConfig();
- if (!empty($options['channelxmlpath'])) {
- $this->_location->setChannelDirectory($options['channelxmlpath']);
- } else if (!empty($options['sourcepath'])) {
- $this->_location->setChannelDirectory($options['sourcepath']);
- }
- if (!empty($options['sourcepath'])) {
- $this->_location->setSourceDirectory($options['sourcepath']);
- }
+ $environment = $this->_factory
+ ->createInstallLocation($location . DIRECTORY_SEPARATOR . '.pearrc');
+ $environment->setResourceDirectories($options);
+ $pear_config = $environment->getPearConfig();
$arguments = $this->_config->getArguments();
$element = basename(realpath($arguments[0]));
$this->_run = array();
$this->_installHordeDependency(
+ $environment,
$root_path,
$element
);
* @param string $root_path Root path to the Horde framework.
* @param string $dependency Package name of the dependency.
*/
- private function _installHordeDependency($root_path, $dependency)
+ private function _installHordeDependency($environment, $root_path, $dependency)
{
$package_file = $root_path . DIRECTORY_SEPARATOR
. $dependency . DIRECTORY_SEPARATOR . 'package.xml';
}
$parser = new PEAR_PackageFile_Parser_v2();
- $parser->setConfig($this->_location->getPearConfig());
+ $parser->setConfig($environment->getPearConfig());
$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') {
- $this->_location->provideChannel($dependency['channel']);
+ $environment->provideChannel($dependency['channel']);
$key = $dependency['channel'] . '/' . $dependency['name'];
if (in_array($key, $this->_run)) {
continue;
}
- $this->_location->addPackageFromPackage(
+ $environment->addPackageFromPackage(
$dependency['channel'], $dependency['name']
);
$this->_run[] = $key;
} else if (isset($dependency['channel'])) {
- $this->_location->provideChannel($dependency['channel']);
+ $environment->provideChannel($dependency['channel']);
$key = $dependency['channel'] . '/' . $dependency['name'];
if (in_array($key, $this->_run)) {
continue;
}
$this->_run[] = $key;
- $this->_installHordeDependency($root_path, $dependency['name']);
+ $this->_installHordeDependency($environment, $root_path, $dependency['name']);
}
}
if (in_array($package_file, $this->_run)) {
return;
}
- $this->_location->provideChannel($pkg->getChannel());
- $this->_location->addPackageFromSource(
+ $environment->provideChannel($pkg->getChannel());
+ $environment->addPackageFromSource(
$package_file
);
$this->_run[] = $package_file;