create_pear_package.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * PEAR package builder
  4. *
  5. * Inspired by Twig's create_pear_package.php.
  6. * @link https://raw.github.com/fabpot/Twig/master/bin/create_pear_package.php
  7. * @author Twig Team
  8. * @license BSD license
  9. */
  10. if (!isset($argv[1]) || $argv[1] === '-h' || $argv[1] === '--help') {
  11. echo 'usage: php ' . $argv[0] . ' <version> <stability>' . PHP_EOL;
  12. echo PHP_EOL;
  13. echo ' version:' . PHP_EOL;
  14. echo ' Version of the package, in the form of major.minor.bug' . PHP_EOL;
  15. echo PHP_EOL;
  16. echo ' stability:' . PHP_EOL;
  17. echo ' One of alpha, beta, stable' . PHP_EOL;
  18. die();
  19. }
  20. if (!isset($argv[2])) {
  21. die('You must provide the stability (alpha, beta, or stable)');
  22. }
  23. $context = array(
  24. 'date' => gmdate('Y-m-d'),
  25. 'time' => gmdate('H:m:00'),
  26. 'version' => $argv[1],
  27. 'api_version' => $argv[1],
  28. 'stability' => $argv[2],
  29. 'api_stability' => $argv[2],
  30. );
  31. $context['files'] = '';
  32. $path = realpath(dirname(__FILE__).'/../library/Requests');
  33. foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
  34. if (preg_match('/\.php$/', $file)) {
  35. $name = str_replace($path . DIRECTORY_SEPARATOR, '', $file);
  36. $name = str_replace(DIRECTORY_SEPARATOR, '/', $name);
  37. $context['files'][] = "\t\t\t\t\t" . '<file install-as="Requests/' . $name . '" name="' . $name . '" role="php" />';
  38. }
  39. }
  40. $context['files'] = implode("\n", $context['files']);
  41. $template = file_get_contents(dirname(__FILE__).'/../package.xml.tpl');
  42. $content = preg_replace_callback('/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/', 'replace_parameters', $template);
  43. file_put_contents(dirname(__FILE__).'/../package.xml', $content);
  44. function replace_parameters($matches) {
  45. global $context;
  46. return isset($context[$matches[1]]) ? $context[$matches[1]] : null;
  47. }