build_phar.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env php
  2. <?php
  3. define('BASE_DIR', realpath(__DIR__.'/..'));
  4. define('PHAR_FILENAME', 'pheanstalk.phar');
  5. define('PHAR_FULLPATH', BASE_DIR.'/'.PHAR_FILENAME);
  6. // ----------------------------------------
  7. reexecute_if_phar_readonly($argv);
  8. delete_existing_pheanstalk_phar();
  9. build_pheanstalk_phar();
  10. verify_pheanstalk_phar();
  11. exit(0);
  12. // ----------------------------------------
  13. // See: http://www.php.net/manual/en/phar.configuration.php#ini.phar.readonly
  14. function reexecute_if_phar_readonly($argv)
  15. {
  16. if (ini_get('phar.readonly') && !in_array('--ignore-readonly', $argv)) {
  17. $command = sprintf(
  18. 'php -d phar.readonly=0 %s --ignore-readonly',
  19. implode(' ', $argv)
  20. );
  21. echo "Phar configured readonly in php.ini; attempting to re-execute:\n";
  22. echo "$command\n";
  23. passthru($command, $exitStatus);
  24. exit($exitStatus);
  25. }
  26. }
  27. function delete_existing_pheanstalk_phar()
  28. {
  29. if (file_exists(PHAR_FULLPATH)) {
  30. printf("- Deleting existing %s\n", PHAR_FILENAME);
  31. unlink(PHAR_FULLPATH);
  32. }
  33. }
  34. function build_pheanstalk_phar()
  35. {
  36. printf("- Building %s from %s\n", PHAR_FILENAME, BASE_DIR);
  37. $phar = new Phar(PHAR_FULLPATH);
  38. $phar->buildFromDirectory(BASE_DIR);
  39. $phar->setStub(
  40. $phar->createDefaultStub('vendor/autoload.php')
  41. );
  42. }
  43. function verify_pheanstalk_phar()
  44. {
  45. $phar = new Phar(PHAR_FULLPATH);
  46. printf("- %s built with %d files.\n", PHAR_FILENAME, $phar->count());
  47. }