-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.php
More file actions
44 lines (31 loc) · 942 Bytes
/
compile.php
File metadata and controls
44 lines (31 loc) · 942 Bytes
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
<?php
$appFile = 'bin/smok';
// clean up
if (file_exists($appFile))
{
unlink($appFile);
}
if (file_exists($appFile . '.gz'))
{
unlink($appFile . '.gz');
}
// create phar
$phar = new Phar($appFile.'.phar');
// start buffering. Mandatory to modify stub to add shebang
$phar->startBuffering();
// Create the default stub from main.php entrypoint
$defaultStub = $phar->createDefaultStub('app/main.php');
// Add the rest of the apps files
$include = '/^(?=(.*app|.*vendor|.*config))(.*)$/i';
$phar->buildFromDirectory(__DIR__ , $include);
// Customize the stub to add the shebang
$stub = "#!/usr/bin/env php \n" . $defaultStub;
// Add the stub
$phar->setStub($stub);
$phar->stopBuffering();
// plus - compressing it into gzip
$phar->compressFiles(Phar::GZ);
rename(__DIR__ . '/bin/smok.phar',__DIR__ . '/bin/smok');
# Make the file executable
chmod(__DIR__ . '/bin/smok', 0770);
echo "$appFile successfully created" . PHP_EOL;