forked from dg/ftp-deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generatePhar
92 lines (74 loc) · 2.18 KB
/
generatePhar
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env php
<?php
/////////////////////////
// Phar generator init //
// with CLI arguments //
/////////////////////////
ini_set("phar.readonly", 0);
if (ini_get("phar.readonly") != 0) {
die("Cannot change phar.readonly mode - change it in 'php.ini' file".PHP_EOL);
}
include 'src/Deployment/CommandLine.php';
$cmd = new Deployment\CommandLine(<<<'XX'
Build of custom FTP Deployment
-------------------
Usage:
generatePhar [--file=deployment.phar] [-c | --compress]
Options:
-c | --compress Compress files in generated phar
--file=<name> Name of generated phar file
-h | --help Show help
XX
);
$options = $cmd->parse();
if ($options['--help']) {
echo $cmd->help();
echo PHP_EOL;
return;
}
$pharFile = $options['--file'] ?? __DIR__.'/deployment.phar';
$compress = (bool)$options['--compress'];
// Remove old phar
if (file_exists($pharFile)) { unlink($pharFile); }
/////////////////////////////////////
// Create phar with given name //
// and with or without compression //
/////////////////////////////////////
echo ($compress ? "Compressed file" : "File")." {$pharFile} will be created".PHP_EOL;
$phar = new Phar($pharFile);
$phar->startBuffering(); // Needed for custom STUB
$phar->buildFromIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(__DIR__.'/src', RecursiveDirectoryIterator::SKIP_DOTS)
),
__DIR__
);
$phar->buildFromIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(__DIR__.'/vendor', RecursiveDirectoryIterator::SKIP_DOTS)
),
__DIR__
);
if ($compress) {
$phar->compressFiles(Phar::GZ);
}
// Create basic custom STUB with deployment.php as entry point
$defaultStub = $defaultStub = <<<'EOF'
#!/usr/bin/env php
<?php
/*
* !!! ATTENTION !!!
*
* This is file contains custom modifications of FTP-Deployment
* More about modifications: https://github.com/arxeiss/ftp-deployment
*
* Original can be found here: https://github.com/dg/ftp-deployment
*
*/
Phar::mapPhar();
include 'phar://'.__FILE__.'/src/deployment.php';
__HALT_COMPILER();
EOF;
$phar->setStub($defaultStub);
$phar->stopBuffering();
echo "Creation of {$pharFile} was successfull".PHP_EOL;