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