-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathyii-phar.php
147 lines (102 loc) · 3.22 KB
/
yii-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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/*
Place this script in the Yii framework folder (yii-x.y.z.rxxx/yii-phar.php) and run it
to package the framework into a single phar file.
In the "index.php" of your application, assuming you placed the packaged framework under
your application's "protected" folder, add the following line at the top:
new Phar(dirname(__FILE__).'/protected/yii-1.1.9.r3527.phar');
This makes the framework available via the phar:// stream-wrapper - when specifying the
path to the Yii framework, set it as "phar://yii".
As of Yii 1.1.9.r3527, CAssetManager does not support packaging the framework this way -
I submitted the following patch, which you will need to apply, or it will not work:
http://code.google.com/p/yii/issues/detail?id=3104
*/
// Configuration:
$dir = dirname(__FILE__);
$path = $dir.'/framework/';
$name = 'yii.phar';
echo $name;
$mode = Phar::GZ;
// Error checks:
if (!class_exists('Phar')) {
die('*** Phar extension is not installed (or not enabled)');
}
if (!Phar::canCompress($mode)) {
die('*** Compression unsupported - please enable the zlib extension');
}
if (!is_dir($path)) {
die('*** Yii Framework not found: '.$path);
}
if (!Phar::canWrite()) {
die('*** Phar is in read-only mode (check phar.readonly in php.ini)');
}
// Iterator:
class FrameworkIterator implements Iterator, Countable {
private $index;
private $files;
private $baselen;
private $size;
private $mask;
private $dirs;
public function __construct($path, $mask = '*') {
$this->index = 0;
$this->files = array();
$this->baselen = strlen($path) + 1;
$this->size = 0;
$this->mask = $mask;
$this->dirs = array();
$this->scan($path);
}
private function scan($path) {
global $phar, $baselen, $total;
foreach (glob($path.'/'.$this->mask) as $file) {
if (is_dir($file)) {
$this->dirs[ $this->getRelative($file) ] = $file;
$this->scan($file);
} else {
$this->size += filesize($file);
$this->files[] = $file;
}
}
}
private function getRelative($path) {
return substr($path, $this->baselen);
}
public function rewind() {
$this->index = 0;
}
public function current() {
return $this->files[$this->index];
}
public function key() {
return $this->getRelative($this->files[$this->index]);
}
public function next() {
$this->index += 1;
}
public function valid() {
return isset($this->files[$this->index]);
}
public function count() {
return count($this->files);
}
public function getSize() {
return $this->size;
}
public function getDirs() {
return $this->dirs;
}
}
// Build and Compress:
echo "Creating archive: $name\n\n";
if (file_exists($name))
unlink($name);
$phar = new Phar($name, 0, 'yii');
$iter = new FrameworkIterator($path);
echo "Building: ".number_format(count($iter)).' files in '.number_format(count($iter->getDirs())).' folders ('.number_format($iter->getSize())." bytes) ...\n\n";
$phar->buildFromIterator($iter);
echo "Compressing files ...\n\n";
//$phar->compressFiles($mode);
//$phar->compress(Phar::BZ2);
$filesize = filesize($name);
echo "Output: ".number_format($filesize)." bytes (".sprintf('%0.2f', $filesize*100 / $iter->getSize())."%)\n\n";