Elements not typically found in package.xml files can be set (or overridden) using methods or a config JSON file. Yes, some of this capability is present in Composer itself, given Composer's ability to install PEAR packages. However, Composer relies on PEAR channels, meaning using Composer's classes for this capability would require developers supporting PEAR and Composer to first publish their packages to their channel and then generate composer.json files afterwards. Using this class, and in particular, the package2composer script that leverages this class, developers are able to use the package.xml file they're using with PEAR's package command to generate a composer.json, which allows a one-stage release workflow to be scripted.
Esempio n. 1
0
 /**
  * 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.');
     }
 }
Esempio n. 2
0
 /**
  * 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;
     }
 }