-
Notifications
You must be signed in to change notification settings - Fork 18
/
CreatePhar.php
71 lines (55 loc) · 1.36 KB
/
CreatePhar.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
64
65
66
67
68
69
70
71
<?php
chdir(__DIR__);
$pharName = 'diffFilter.phar';
cleanUp($pharName);
$pharFile = getcwd() . '/diffFilter.phar';
if (file_exists($pharFile)) {
unlink($pharFile);
}
$phar = new Phar($pharFile, 0, $pharName);
$phar->addFile('autoload.php');
$phar->addFile('bin/diffFilter');
$dirs = [
'src',
'vendor',
];
foreach($dirs as $dir) {
addDir($dir, $phar);
}
$phar->setStub(
"#!/usr/bin/env php
<?php
Phar::mapPhar('$pharName');
require 'phar://$pharName/src/Runners/generic.php';
__HALT_COMPILER();"
);
function addDir($dir, $phar)
{
$code = realpath(__DIR__ . "/$dir/");
$codeLength = strlen($code);
$directory = new RecursiveDirectoryIterator(
$code,
RecursiveDirectoryIterator::FOLLOW_SYMLINKS
);
$iterator = new RecursiveIteratorIterator(
$directory,
0,
RecursiveIteratorIterator::CATCH_GET_CHILD
);
foreach ($iterator as $file) {
$fullPath = $file->getPathname();
$path = $dir . substr($fullPath, $codeLength);
if (strpos($path, '/test/') !== false) {
continue;
}
if (is_file($path)) {
$phar->addFromString($path, php_strip_whitespace($path));
}
}
}
function cleanUp($pharName)
{
shell_exec("rm -rf vendor");
shell_exec("rm $pharName");
shell_exec("composer install --no-dev -o");
}