/** * Updates the composer.json file. * * @param string $package Path to the package.xml file. * @param array $options The set of options for the operation. */ public function generateComposeJson($package, array $options = array()) { require_once __DIR__ . '/../../Conductor/PEARPackageFilev2.php'; require_once __DIR__ . '/../../Conductor/Package2XmlToComposer.php'; $converter = new Package2XmlToComposer($package); $converter->setRepositories(array(array('pear', 'http://pear.horde.org'))); $converter->output_file = dirname($package) . '/composer.json'; $converter->convert(); if (isset($options['logger'])) { $options['logger']->ok('Created composer.json file.'); } }
/** * Main method that starts conversion from the command-line * * */ public static function main() { $params = array('f:' => 'package-file:', 'c:' => 'config:', 'h' => 'help'); $short = join('', array_keys($params)); $opts = getopt($short, $params); if (isset($opts['h']) || isset($opts['help'])) { self::help(); } $config = null; $package_file = null; if (isset($opts['c'])) { $config = $opts['c']; } elseif (isset($opts['config'])) { $config = $opts['config']; } if (isset($opts['f'])) { $package_file = $opts['f']; } elseif (isset($opts['package-file'])) { $package_file = $opts['package-file']; } if ($package_file === null) { $cwd = getcwd(); if (file_exists($cwd . '/package.xml')) { $package_file = $cwd . '/package.xml'; } } if ($config === null && $package_file !== null) { // check same dir as package.xml $config_path = dirname($package_file); if (file_exists($config_path . '/package-composer.json')) { $config = $config_path . '/package-composer.json'; } } $converter = new Package2XmlToComposer($package_file, $config); $ret = $converter->convert(); if ($converter->output_file === null) { echo $ret; } }