create-pear 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * This file is part of the Predis package.
  5. *
  6. * (c) Daniele Alessandri <suppakilla@gmail.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. // -------------------------------------------------------------------------- //
  12. // In order to be able to execute this script to create a PEAR package of Predis
  13. // both `onion` and `pear` must be available and executable in your $PATH.
  14. // -------------------------------------------------------------------------- //
  15. function executeWithBackup($file, $callback)
  16. {
  17. $exception = null;
  18. $backup = "$file.backup";
  19. copy($file, $backup);
  20. try {
  21. call_user_func($callback, $file);
  22. } catch (Exception $exception) {
  23. // NOOP
  24. }
  25. unlink($file);
  26. rename($backup, $file);
  27. if ($exception) {
  28. throw $exception;
  29. }
  30. }
  31. function buildPackage()
  32. {
  33. passthru('onion build && pear -q package && rm package.xml');
  34. }
  35. executeWithBackup(__DIR__.'/../phpunit.xml.dist', function ($file) {
  36. $cfg = new SimpleXMLElement($file, null, true);
  37. $cfg[0]['bootstrap'] = str_replace('tests/', '', $cfg[0]['bootstrap']);
  38. $cfg->testsuites->testsuite->directory = str_replace('tests/', '', $cfg->testsuites->testsuite->directory);
  39. $cfg->saveXml($file);
  40. buildPackage();
  41. });