-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_phar.php
46 lines (36 loc) · 1.19 KB
/
create_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
<?php
/**
* Create pterm.phar
* - REF: https://blog.programster.org/creating-phar-files#:~:text=Simply%20create%20a%20folder%20for,for%20your%20application's%20source%20code.&text=Copy%20all%20of%20your%20PHP,and%20modify%20the%20script%20below).
* - php.ini -> phar.readonly = Off
*/
try
{
//cleanup
$pharFile = 'pterm.phar';
if (file_exists($pharFile)) unlink($pharFile);
if (file_exists($pharFile . '.gz')) unlink($pharFile . '.gz');
//create phar
$phar = new Phar($pharFile);
//start buffering. Mandatory to modify stub to add shebang
$phar -> startBuffering();
//Create the default stub from main.php entrypoint
$defaultStub = $phar -> createDefaultStub('index.php');
//Add the rest of the apps files
$phar -> buildFromDirectory(__DIR__ . '/src');
//Customize the stub to add the shebang
//FIX: $stub = "#!/usr/bin/env php \n" . $defaultStub;
$stub = $defaultStub;
//Add the stub
$phar -> setStub($stub);
$phar -> stopBuffering();
//plus - compressing it into gzip
$phar -> compressFiles(Phar::GZ);
//Make the file executable
chmod(__DIR__ . "/{$pharFile}", 0770);
echo "$pharFile successfully created" . PHP_EOL;
}
catch (Exception $e){
echo $e -> getMessage();
}
exit;