-
Notifications
You must be signed in to change notification settings - Fork 7
/
generate_phar.php
122 lines (95 loc) · 3.59 KB
/
generate_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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
$bitRemoveSource = isset($argv[1]) && $argv[1] == "deletesource" ? true : false;
/**
* CLI params:
* deploypath=xxx
* removesource=xxx
*
* Class PharCreator
*/
class PharCreator
{
public $strDeployPath = "";
// public $strDeployPath = "/Users/sidler/web/kajona_build/kajona";
public $bitRemoveSource = false;
public function generatePhars()
{
$arrCores = scandir("./../");
foreach ($arrCores as $strOneCore) {
if (strpos($strOneCore, "core") === false) {
continue;
}
$arrFiles = scandir("./../".$strOneCore);
foreach ($arrFiles as $strFile) {
if (is_dir(__DIR__."/../".$strOneCore."/".$strFile) && substr($strFile, 0, 7) == 'module_') {
$strModuleName = substr($strFile, 7);
$strPharName = "module_".$strModuleName.".phar";
// if($strModuleName != "system") {
// continue;
// }
$strTargetPath = __DIR__."/../".$strOneCore."/".$strPharName;
if ($this->strDeployPath != "" && is_dir($this->strDeployPath."/".$strOneCore)) {
$strTargetPath = $this->strDeployPath."/".$strOneCore."/".$strPharName;
}
$phar = new Phar(
$strTargetPath,
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME,
$strPharName
);
$phar->buildFromDirectory(__DIR__."/../".$strOneCore."/module_".$strModuleName);
$phar->setStub($phar->createDefaultStub());
// Compression with ZIP or GZ?
//$phar->convertToExecutable(Phar::ZIP);
//$phar->compress(Phar::GZ);
echo 'Generated phar '.$strPharName."\n";
if($this->bitRemoveSource) {
$this->rrmdir(__DIR__."/../".$strOneCore."/module_".$strModuleName);
}
}
}
}
}
public function parseParams($arrParams) {
$arrParsed = array();
foreach($arrParams as $strOneParam) {
$arrOneParam = explode("=", $strOneParam);
if(count($arrOneParam) == 2) {
$arrParsed[$arrOneParam[0]] = $arrOneParam[1];
}
}
if(isset($arrParsed["deploypath"])) {
$this->strDeployPath = $arrParsed["deploypath"];
}
if(isset($arrParsed["removesource"])) {
$this->bitRemoveSource = $arrParsed["removesource"];
}
}
/**
* @param $strDir
*
* @see http://www.php.net/manual/de/function.rmdir.php#98622
*/
private function rrmdir($strDir)
{
if (is_dir($strDir)) {
$arrObjects = scandir($strDir);
foreach ($arrObjects as $objObject) {
if ($objObject != "." && $objObject != "..") {
if (is_dir($strDir."/".$objObject)) {
$this->rrmdir($strDir."/".$objObject);
} else {
$intRetry = 0;
while (!unlink($strDir."/".$objObject) && $intRetry < 8) {
sleep(2);
$intRetry++;
}
}
}
}
rmdir($strDir);
}
}
}
$objCreator = new PharCreator();
$objCreator->parseParams(array_slice($argv, 1));
$objCreator->generatePhars();