/
build-phar.php
63 lines (50 loc) · 1.72 KB
/
build-phar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* This file builds Alphred as a .phar
*/
// Create a new phar named Alphred.phar
$phar = new Phar( 'build/Alphred.phar',
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME,
'Alphred.phar'
);
// Start buffering. Mandatory to modify stub.
$phar->startBuffering();
// We use 'Main.php' as the, well, main entry point for the library. It can understand if it is used as a
// command line tool or included as a library.
$defaultStub = $phar->createDefaultStub( 'Main.php' );
$phar[ "Main.php" ] = file_get_contents( __DIR__ . "/Main.php" );
// Cycle through these directories and include everything
foreach( [ 'classes', 'scripts', 'commands' ] as $directory ) :
foreach( array_diff( scandir( $directory ), ['.', '..', '.DS_Store' ] ) as $filename ) :
$phar[ "{$directory}/{$filename}" ] = file_get_contents( __DIR__ . "/{$directory}/{$filename}" );
endforeach;
endforeach;
// Add in other files
$other_files = [
// 'apigen.neon',
'build-phar.php',
// 'build.xml',
'Changelog.md',
'code-standards.xml',
'phpdoc.dist.xml',
// 'phpunit.xml.dist', // Taking this out for now
'README.md',
];
// Include the invidual files
foreach ( $other_files as $file ) :
$phar[ $file ] = file_get_contents( __DIR__ . '/' . $file );
endforeach;
// Create a custom stub to add the shebang
// $stub = "#!/usr/bin/php \n" . $defaultStub;
$stub = $defaultStub;
// Add the stub
$phar->setStub( $stub );
$phar->stopBuffering();
// I should use php's chmod() function, but I'm going to cheat here to make it executable
exec( 'chmod +x build/Alphred.phar', $return, $code );
if ( 0 == $code ) {
print "Built Phar\n";
} else {
print "Problem occured building phar.\n";
}
exit( $code );