phing build file to create a standalone phar package
[bdrem.git] / bin / makephar.php
1 #!/usr/bin/env php
2 <?php
3 if (ini_get('phar.readonly') == 1) {
4     //re-run this script with phar writing activated
5     passthru(PHP_BINARY . ' -dphar.readonly=0 ' . escapeshellarg($argv[0]));
6     exit();
7 }
8
9 $pharfile = __DIR__ . '/../dist/bdrem-0.1.0.phar';
10 if (file_exists($pharfile)) {
11     unlink($pharfile);
12 }
13 $phar = new Phar($pharfile, 0, 'bdrem.phar');
14 $phar->startBuffering();
15
16 // add all files in the project
17 $phar->buildFromDirectory(
18     realpath(__DIR__ . '/../'),
19     '#'
20     . '^' . preg_quote(realpath(__DIR__ . '/../'), '#')
21     . '/(data/bdrem.config.php.dist|lib/|src/bdrem/|www/|README\.rst)'
22     . '#'
23 );
24
25 //remove shebang from bin/bdrem.php
26 $bin = file_get_contents(__DIR__ . '/../bin/bdrem.php');
27 $phar->addFromString('bin/bdrem.php', substr($bin, strpos($bin, "\n") + 1));
28
29 $phar->setStub(file_get_contents(__DIR__ . '/../src/phar-stub.php'));
30 $phar->stopBuffering();
31 ?>