forked from fusonic/chive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pharExport.php
executable file
·111 lines (102 loc) · 2.94 KB
/
pharExport.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
<?php
// Create phar archive
$phar = new Phar("chive_" . @$argv[1] . ".phar.php");
// Load locales
$locales = glob("chive/protected/messages/*", GLOB_ONLYDIR);
foreach($locales as &$locale)
{
$locale = basename($locale);
}
// Delete locales we don't need
$yiiLocales = glob("chive/yii/i18n/data/*.php");
foreach($yiiLocales as $locale)
{
$localeName = pathinfo($locale, PATHINFO_FILENAME);
if(!in_array($localeName, $locales))
{
unlink($locale);
}
}
// Remove some yii components we don't need
exec("rm chive/yii/gii -rf");
exec("rm chive/yii/cli -rf");
exec("rm chive/yii/console -rf");
exec("rm chive/yii/db/schema/mssql -rf");
exec("rm chive/yii/db/schema/oci -rf");
exec("rm chive/yii/db/schema/pgsql -rf");
exec("rm chive/yii/db/schema/sqlite -rf");
exec("rm chive/yii/messages/?? -rf");
exec("rm chive/yii/messages/??_?? -rf");
exec("rm chive/yii/test -rf");
exec("rm chive/yii/vendors/htmlpurifier -rf");
exec("rm chive/yii/vendors/TextHighlighter -rf");
exec("rm chive/yii/views/?? -rf");
exec("rm chive/yii/views/??_?? -rf");
exec("rm chive/yii/web/js/source/autocomplete -rf");
exec("rm chive/yii/web/js/source/jui -rf");
exec("rm chive/yii/web/js/source/rating -rf");
exec("rm chive/yii/web/js/source/treeview -rf");
exec("rm chive/yii/web/js/source/yiitab -rf");
exec("rm chive/yii/web/js/source/jquery.js");
exec("rm chive/yii/web/widgets/captcha -rf");
exec("rm chive/yii/zii -rf");
// Add all files
$sourceDir = __DIR__ . "/chive";
$i = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sourceDir), RecursiveIteratorIterator::SELF_FIRST);
foreach($i as $file)
{
$basename = basename($file);
if($basename{0} == ".")
{
continue;
}
$targetPath = substr($file, strlen($sourceDir) + 1);
if(is_dir($file))
{
$phar->addEmptyDir($targetPath);
}
elseif(!substr_compare($file, ".php", -4))
{
// Get content
echo "- Adding PHP " . $file . "\n";
$content = php_strip_whitespace($file);
$content = str_replace("realpath(", "ltrim(", $content);
file_put_contents($file, $content);
$phar->addFile($file, $targetPath);
}
elseif(!substr_compare($file, ".js", -3))
{
echo "- Adding JS " . $file . "\n";
exec("./jsmin <" . $file . " >" . $file . ".min");
unlink($file);
$phar->addFile($file . ".min", $targetPath);
}
/*
elseif(!substr_compare($file, ".css", -4))
{
echo "- Adding CSS " . $file . "\n";
exec("./jsmin <" . $file . " >" . $file . ".min");
unlink($file);
$phar->addFile($file . ".min", $targetPath);
}
*/
elseif(!substr_compare($file, ".xml", -4) && strpos($file, $sourceDir . "/protected/messages/") === 0)
{
echo "- Adding XML " . $file . "\n";
$content = gzcompress(file_get_contents($file), 9);
unlink($file);
file_put_contents($file . ".gz", $content);
$phar->addFile($file . ".gz", $targetPath . ".gz");
}
else
{
echo "- Adding " . $file . "\n";
$phar->addFile($file, $targetPath);
}
}
$stub = <<<LONG
<?php
Phar::webPhar();
__HALT_COMPILER();
LONG;
$phar->setStub($stub);