Skip to content

Commit ab68996

Browse files
committed
Include vendor in Phar
1 parent 1c631b4 commit ab68996

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

CreatePhar.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,42 @@
1212
$phar->addFile('autoload.php');
1313
$phar->addFile('bin/diffFilter');
1414

15-
$code = realpath(__DIR__ . '/src');
16-
$codeLength = strlen($code);
17-
$directory = new RecursiveDirectoryIterator(
18-
$code,
19-
RecursiveDirectoryIterator::FOLLOW_SYMLINKS
20-
);
21-
$iterator = new RecursiveIteratorIterator(
22-
$directory,
23-
0,
24-
RecursiveIteratorIterator::CATCH_GET_CHILD
25-
);
2615

27-
foreach ($iterator as $file) {
28-
$fullPath = $file->getPathname();
29-
$path = 'src' . substr($fullPath, $codeLength);
16+
$dirs = [
17+
'src',
18+
'vendor',
19+
];
3020

31-
$phar->addFile($path);
21+
foreach($dirs as $dir) {
22+
addDir($dir, $phar);
3223
}
3324

3425
$phar->setStub(
3526
"#!/usr/bin/env php
3627
<?php
37-
require 'src/Runners/generic.php';
28+
require 'phar://$pharName/src/Runners/generic.php';
3829
__HALT_COMPILER();"
3930
);
31+
32+
function addDir($dir, $phar)
33+
{
34+
$code = realpath(__DIR__ . "/$dir/");
35+
$codeLength = strlen($code);
36+
$directory = new RecursiveDirectoryIterator(
37+
$code,
38+
RecursiveDirectoryIterator::FOLLOW_SYMLINKS
39+
);
40+
$iterator = new RecursiveIteratorIterator(
41+
$directory,
42+
0,
43+
RecursiveIteratorIterator::CATCH_GET_CHILD
44+
);
45+
46+
foreach ($iterator as $file) {
47+
$fullPath = $file->getPathname();
48+
$path = $dir . substr($fullPath, $codeLength);
49+
if (is_file($path)) {
50+
$phar->addFile($path);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)