make_phar.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. chdir(realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'));
  3. $phar = new Phar('bin/pwhoisd.phar', 0, 'pwhoisd.phar' );
  4. $phar->setSignatureAlgorithm(Phar::SHA1);
  5. $phar->startBuffering();
  6. $rd = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.'));
  7. $files = [];
  8. foreach($rd as $file)
  9. {
  10. if ($file->getFilename() != '..' AND
  11. $file->getFilename() != '.' AND
  12. $file->getFilename() != __FILE__)
  13. {
  14. if (preg_match('|^\.\/src/include|', $file->getPath()))
  15. {
  16. $files[substr($file->getPath().DIRECTORY_SEPARATOR.$file->getFilename(), 2)] =
  17. $file->getPath().DIRECTORY_SEPARATOR.$file->getFilename();
  18. }
  19. }
  20. }
  21. $phar->buildFromIterator(new ArrayIterator($files));
  22. print_r($files);
  23. $phar->setStub( <<<EOB
  24. #!/usr/bin/env php
  25. <?php
  26. /**
  27. * HSDN PHP Whois Server Daemon
  28. *
  29. * The MIT License (MIT)
  30. *
  31. * Copyright (c) 2015 Information Networks Ltd.
  32. *
  33. * Permission is hereby granted, free of charge, to any person obtaining a copy
  34. * of this software and associated documentation files (the "Software"), to deal
  35. * in the Software without restriction, including without limitation the rights
  36. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  37. * copies of the Software, and to permit persons to whom the Software is
  38. * furnished to do so, subject to the following conditions:
  39. *
  40. * The above copyright notice and this permission notice shall be included in all
  41. * copies or substantial portions of the Software.
  42. *
  43. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  44. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  45. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  46. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  47. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  48. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  49. * SOFTWARE.
  50. */
  51. Phar::mapPhar();
  52. (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') and die('This program cannot be run in Windows environment.');
  53. (PHP_SAPI === 'cli') or die('This program running available in CLI mode only.');
  54. define('INCLUDE_PATH', 'phar://pwhoisd.phar/src/include');
  55. require_once INCLUDE_PATH.DIRECTORY_SEPARATOR.'Autoloader.php';
  56. \pWhoisd\Autoloader::register();
  57. \pWhoisd\Application::factory()->run();
  58. __HALT_COMPILER();
  59. ?>
  60. EOB
  61. );
  62. $phar->stopBuffering();
  63. $phar->compressFiles(Phar::GZ);