common.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. define('LINE_WIDTH', 75);
  11. define('LINE', str_repeat('-', LINE_WIDTH) . "\n");
  12. function bailout($message)
  13. {
  14. echo wordwrap($message, LINE_WIDTH) . " Aborting.\n";
  15. exit(1);
  16. }
  17. function strip_minor_versions($version)
  18. {
  19. preg_match('/^(?P<version>[0-9]\.[0-9]|[0-9]{2,})/', $version, $matches);
  20. return $matches['version'];
  21. }
  22. function centered($text)
  23. {
  24. $padding = (int) ((LINE_WIDTH - strlen($text))/2);
  25. return str_repeat(' ', $padding) . $text;
  26. }
  27. function cd($dir)
  28. {
  29. if (false === chdir($dir)) {
  30. bailout("Could not switch to directory $dir.");
  31. }
  32. }
  33. function run($command)
  34. {
  35. exec($command, $output, $status);
  36. if (0 !== $status) {
  37. $output = implode("\n", $output);
  38. echo "Error while running:\n " . getcwd() . '$ ' . $command . "\nOutput:\n" . LINE . "$output\n" . LINE;
  39. bailout("\"$command\" failed.");
  40. }
  41. }
  42. function get_icu_version_from_genrb($genrb)
  43. {
  44. exec($genrb . ' --version 2>&1', $output, $status);
  45. if (0 !== $status) {
  46. bailout($genrb . ' failed.');
  47. }
  48. if (!preg_match('/ICU version ([\d\.]+)/', implode('', $output), $matches)) {
  49. return null;
  50. }
  51. return $matches[1];
  52. }