phar_from_dir.php 980 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /** @file phar_from_dir.php
  3. * @brief Create phar archive from directory
  4. * @ingroup examples
  5. * @author Marcus Boerger
  6. * @date 2003 - 2007
  7. * @version 1.0
  8. *
  9. * Usage: php phar_create_from_dir.php \<archive\> \<directory\> [\<regex\>]
  10. *
  11. * Create phar archive \<archive\> using entries from \<directory\> that
  12. * optionally match \<regex\>.
  13. */
  14. if ($argc < 3)
  15. {
  16. echo <<<EOF
  17. php phar_from_dir.php archive directory [regex]
  18. Packs files in a given directory into a phar archive.
  19. archive name of the archive to create
  20. directory input directory to pack
  21. regex optional expression to match files in directory
  22. EOF;
  23. exit(1);
  24. }
  25. $phar = new Phar($argv[1], 0, 'newphar');
  26. $dir = new RecursiveDirectoryIterator($argv[2]);
  27. $dir = new RecursiveIteratorIterator($dir);
  28. if ($argc > 3)
  29. {
  30. $dir = new RegexIterator($dir, '/'.$argv[3].'/');
  31. }
  32. $phar->begin();
  33. foreach($dir as $file)
  34. {
  35. echo "$file\n";
  36. copy($file, "phar://newphar/$file");
  37. }
  38. $phar->commit();
  39. ?>