Skip to content

Commit 1f346de

Browse files
committed
fix: #18 - re-write the phar stub
1 parent 373a9aa commit 1f346de

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

scripts/phar-generator-script.php

100755100644
Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Doctum;
66

7+
// To be able to fetch the version in this script afterwards
8+
require_once __DIR__ . '/../src/Doctum.php';
9+
710
use Phar;
811
use RecursiveDirectoryIterator;
912
use RecursiveIteratorIterator;
@@ -22,13 +25,35 @@
2225
mkdir($buildRoot);
2326
}
2427

28+
$version = \Doctum\Doctum::VERSION;
29+
30+
$pharAlias = 'doctum-' . $version . '.phar';
31+
2532
$phar = new Phar(
2633
$buildRoot . '/doctum.phar',
2734
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME,
28-
'doctum.phar'
35+
$pharAlias
2936
);
3037

31-
$shebang = "#!/usr/bin/env php";
38+
$shebang = '#!/usr/bin/env php';
39+
40+
$date = date('c');
41+
42+
// See: https://github.com/zendtech/ZendOptimizerPlus/issues/115#issuecomment-25612769
43+
// See: https://stackoverflow.com/a/13896692/5155484
44+
$stub = <<<STUB
45+
<?php
46+
/**
47+
* Doctum phar, generated by Doctum the $date
48+
* @see https://github.com/code-lts/doctum#readme
49+
* @version $version
50+
* @license MIT
51+
*/
52+
Phar::interceptFileFuncs();
53+
Phar::mapPhar('$pharAlias');
54+
include 'phar://' . __FILE__ . '/bin/doctum-binary.php';
55+
__HALT_COMPILER();
56+
STUB;
3257

3358
$iterator = new RecursiveDirectoryIterator($srcRoot);
3459
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
@@ -192,7 +217,7 @@ public static function getExcludedFolders(): array
192217

193218
$pharFilesList = new RecursiveIteratorIterator($filter);
194219

195-
$phar->setStub($shebang . PHP_EOL . $phar->createDefaultStub('bin/doctum-binary.php'));
220+
$phar->setStub($shebang . PHP_EOL . $stub);
196221
$phar->setSignatureAlgorithm(Phar::SHA256);
197222
$phar->buildFromIterator($pharFilesList, $srcRoot);
198223

0 commit comments

Comments
 (0)