@@ -10,200 +10,200 @@ |
||
10 | 10 | |
11 | 11 | class Installer |
12 | 12 | { |
13 | - private $silent = false; |
|
14 | - private $app_dir = 'application'; |
|
15 | - private $pub_dir = 'public'; |
|
16 | - private $test_dir = 'tests'; |
|
17 | - private $from_composer = false; |
|
18 | - |
|
19 | - public function __construct($argv) |
|
20 | - { |
|
21 | - $this->parse_args($argv); |
|
22 | - } |
|
23 | - |
|
24 | - private function parse_args($argv) |
|
25 | - { |
|
26 | - $argc = count($argv); |
|
27 | - |
|
28 | - if ($argc === 1) { |
|
29 | - return; |
|
30 | - } |
|
31 | - |
|
32 | - for ($i = 1; $i <= $argc; $i++) { |
|
33 | - if (! isset($argv[$i])) { |
|
34 | - break; |
|
35 | - } |
|
36 | - |
|
37 | - switch ($argv[$i]) { |
|
38 | - // php install.php -s |
|
39 | - case '-s': |
|
40 | - $this->silent = true; |
|
41 | - break; |
|
42 | - |
|
43 | - // php install.php -a application |
|
44 | - case '-a': |
|
45 | - if (is_dir($argv[$i+1])) { |
|
46 | - $this->app_dir = $argv[$i+1]; |
|
47 | - } else { |
|
48 | - throw new Exception('No such directory: '.$argv[$i+1]); |
|
49 | - } |
|
50 | - $i++; |
|
51 | - break; |
|
52 | - |
|
53 | - // php install.php -p public |
|
54 | - case '-p': |
|
55 | - if (is_dir($argv[$i+1])) { |
|
56 | - $this->pub_dir = $argv[$i+1]; |
|
57 | - } else { |
|
58 | - throw new Exception('No such directory: '.$argv[$i+1]); |
|
59 | - } |
|
60 | - $i++; |
|
61 | - break; |
|
62 | - |
|
63 | - case '--from-composer': |
|
64 | - $this->from_composer = true; |
|
65 | - $i++; |
|
66 | - break; |
|
67 | - |
|
68 | - default: |
|
69 | - throw new Exception('Unknown argument: '.$argv[$i]); |
|
70 | - } |
|
71 | - } |
|
72 | - } |
|
73 | - |
|
74 | - public function install() |
|
75 | - { |
|
76 | - $this->recursiveCopy( |
|
77 | - dirname(dirname(__FILE__)).'/application/tests', |
|
78 | - $this->app_dir.'/'.$this->test_dir |
|
79 | - ); |
|
80 | - $this->fixPath(); |
|
81 | - if ($this->from_composer) { |
|
82 | - $this->recursiveUnlink($this->app_dir.'/'.$this->test_dir.'/_ci_phpunit_test'); |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Fix paths in Bootstrap.php |
|
88 | - */ |
|
89 | - private function fixPath() |
|
90 | - { |
|
91 | - $file = $this->app_dir.'/'.$this->test_dir.'/Bootstrap.php'; |
|
92 | - $contents = file_get_contents($file); |
|
93 | - |
|
94 | - if (! file_exists('system')) { |
|
95 | - if (file_exists('vendor/codeigniter/framework/system')) { |
|
96 | - $contents = str_replace( |
|
97 | - '$system_path = \'../../system\';', |
|
98 | - '$system_path = \'../../vendor/codeigniter/framework/system\';', |
|
99 | - $contents |
|
100 | - ); |
|
101 | - } else { |
|
102 | - throw new Exception('Can\'t find "system" folder.'); |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - if (! file_exists('index.php')) { |
|
107 | - if (file_exists($this->pub_dir.'/index.php')) { |
|
108 | - // CodeIgniter 3.0.6 and after |
|
109 | - $contents = str_replace( |
|
110 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
111 | - "define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').DIRECTORY_SEPARATOR);", |
|
112 | - $contents |
|
113 | - ); |
|
114 | - // CodeIgniter 3.0.5 and before |
|
115 | - $contents = str_replace( |
|
116 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
117 | - "define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').'/');", |
|
118 | - $contents |
|
119 | - ); |
|
120 | - } elseif (file_exists($this->app_dir.'/public/index.php')) { |
|
121 | - // CodeIgniter 3.0.6 and after |
|
122 | - $contents = str_replace( |
|
123 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
124 | - "define('FCPATH', realpath(dirname(__FILE__).'/../public').DIRECTORY_SEPARATOR);", |
|
125 | - $contents |
|
126 | - ); |
|
127 | - // CodeIgniter 3.0.5 and before |
|
128 | - $contents = str_replace( |
|
129 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
130 | - "define('FCPATH', realpath(dirname(__FILE__).'/../public').'/');", |
|
131 | - $contents |
|
132 | - ); |
|
133 | - if ($this->app_dir !== 'application') { |
|
134 | - $contents = str_replace( |
|
135 | - "\$application_folder = '../../application';", |
|
136 | - "\$application_folder = '../../{$this->app_dir}';", |
|
137 | - $contents |
|
138 | - ); |
|
139 | - } |
|
140 | - } else { |
|
141 | - throw new Exception('Can\'t find "index.php".'); |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - file_put_contents($file, $contents); |
|
146 | - } |
|
147 | - |
|
148 | - public function update() |
|
149 | - { |
|
150 | - $target_dir = $this->app_dir.'/'.$this->test_dir.'/_ci_phpunit_test'; |
|
151 | - $this->recursiveUnlink($target_dir); |
|
152 | - $this->recursiveCopy( |
|
153 | - dirname(dirname(__FILE__)).'/application/tests/_ci_phpunit_test', |
|
154 | - $target_dir |
|
155 | - ); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Recursive Copy |
|
160 | - * |
|
161 | - * @param string $src |
|
162 | - * @param string $dst |
|
163 | - */ |
|
164 | - private function recursiveCopy($src, $dst) |
|
165 | - { |
|
166 | - @mkdir($dst, 0755); |
|
167 | - |
|
168 | - $iterator = new \RecursiveIteratorIterator( |
|
169 | - new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
170 | - \RecursiveIteratorIterator::SELF_FIRST |
|
171 | - ); |
|
172 | - |
|
173 | - foreach ($iterator as $file) { |
|
174 | - if ($file->isDir()) { |
|
175 | - @mkdir($dst.'/'.$iterator->getSubPathName()); |
|
176 | - } else { |
|
177 | - $success = copy($file, $dst.'/'.$iterator->getSubPathName()); |
|
178 | - if ($success) { |
|
179 | - if (! $this->silent) { |
|
180 | - echo 'copied: '.$dst.'/'.$iterator->getSubPathName().PHP_EOL; |
|
181 | - } |
|
182 | - } |
|
183 | - } |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Recursive Unlink |
|
189 | - * |
|
190 | - * @param string $dir |
|
191 | - */ |
|
192 | - private function recursiveUnlink($dir) |
|
193 | - { |
|
194 | - $iterator = new \RecursiveIteratorIterator( |
|
195 | - new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
196 | - \RecursiveIteratorIterator::CHILD_FIRST |
|
197 | - ); |
|
198 | - |
|
199 | - foreach ($iterator as $file) { |
|
200 | - if ($file->isDir()) { |
|
201 | - rmdir($file); |
|
202 | - } else { |
|
203 | - unlink($file); |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - rmdir($dir); |
|
208 | - } |
|
13 | + private $silent = false; |
|
14 | + private $app_dir = 'application'; |
|
15 | + private $pub_dir = 'public'; |
|
16 | + private $test_dir = 'tests'; |
|
17 | + private $from_composer = false; |
|
18 | + |
|
19 | + public function __construct($argv) |
|
20 | + { |
|
21 | + $this->parse_args($argv); |
|
22 | + } |
|
23 | + |
|
24 | + private function parse_args($argv) |
|
25 | + { |
|
26 | + $argc = count($argv); |
|
27 | + |
|
28 | + if ($argc === 1) { |
|
29 | + return; |
|
30 | + } |
|
31 | + |
|
32 | + for ($i = 1; $i <= $argc; $i++) { |
|
33 | + if (! isset($argv[$i])) { |
|
34 | + break; |
|
35 | + } |
|
36 | + |
|
37 | + switch ($argv[$i]) { |
|
38 | + // php install.php -s |
|
39 | + case '-s': |
|
40 | + $this->silent = true; |
|
41 | + break; |
|
42 | + |
|
43 | + // php install.php -a application |
|
44 | + case '-a': |
|
45 | + if (is_dir($argv[$i+1])) { |
|
46 | + $this->app_dir = $argv[$i+1]; |
|
47 | + } else { |
|
48 | + throw new Exception('No such directory: '.$argv[$i+1]); |
|
49 | + } |
|
50 | + $i++; |
|
51 | + break; |
|
52 | + |
|
53 | + // php install.php -p public |
|
54 | + case '-p': |
|
55 | + if (is_dir($argv[$i+1])) { |
|
56 | + $this->pub_dir = $argv[$i+1]; |
|
57 | + } else { |
|
58 | + throw new Exception('No such directory: '.$argv[$i+1]); |
|
59 | + } |
|
60 | + $i++; |
|
61 | + break; |
|
62 | + |
|
63 | + case '--from-composer': |
|
64 | + $this->from_composer = true; |
|
65 | + $i++; |
|
66 | + break; |
|
67 | + |
|
68 | + default: |
|
69 | + throw new Exception('Unknown argument: '.$argv[$i]); |
|
70 | + } |
|
71 | + } |
|
72 | + } |
|
73 | + |
|
74 | + public function install() |
|
75 | + { |
|
76 | + $this->recursiveCopy( |
|
77 | + dirname(dirname(__FILE__)).'/application/tests', |
|
78 | + $this->app_dir.'/'.$this->test_dir |
|
79 | + ); |
|
80 | + $this->fixPath(); |
|
81 | + if ($this->from_composer) { |
|
82 | + $this->recursiveUnlink($this->app_dir.'/'.$this->test_dir.'/_ci_phpunit_test'); |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Fix paths in Bootstrap.php |
|
88 | + */ |
|
89 | + private function fixPath() |
|
90 | + { |
|
91 | + $file = $this->app_dir.'/'.$this->test_dir.'/Bootstrap.php'; |
|
92 | + $contents = file_get_contents($file); |
|
93 | + |
|
94 | + if (! file_exists('system')) { |
|
95 | + if (file_exists('vendor/codeigniter/framework/system')) { |
|
96 | + $contents = str_replace( |
|
97 | + '$system_path = \'../../system\';', |
|
98 | + '$system_path = \'../../vendor/codeigniter/framework/system\';', |
|
99 | + $contents |
|
100 | + ); |
|
101 | + } else { |
|
102 | + throw new Exception('Can\'t find "system" folder.'); |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + if (! file_exists('index.php')) { |
|
107 | + if (file_exists($this->pub_dir.'/index.php')) { |
|
108 | + // CodeIgniter 3.0.6 and after |
|
109 | + $contents = str_replace( |
|
110 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
111 | + "define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').DIRECTORY_SEPARATOR);", |
|
112 | + $contents |
|
113 | + ); |
|
114 | + // CodeIgniter 3.0.5 and before |
|
115 | + $contents = str_replace( |
|
116 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
117 | + "define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').'/');", |
|
118 | + $contents |
|
119 | + ); |
|
120 | + } elseif (file_exists($this->app_dir.'/public/index.php')) { |
|
121 | + // CodeIgniter 3.0.6 and after |
|
122 | + $contents = str_replace( |
|
123 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
124 | + "define('FCPATH', realpath(dirname(__FILE__).'/../public').DIRECTORY_SEPARATOR);", |
|
125 | + $contents |
|
126 | + ); |
|
127 | + // CodeIgniter 3.0.5 and before |
|
128 | + $contents = str_replace( |
|
129 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
130 | + "define('FCPATH', realpath(dirname(__FILE__).'/../public').'/');", |
|
131 | + $contents |
|
132 | + ); |
|
133 | + if ($this->app_dir !== 'application') { |
|
134 | + $contents = str_replace( |
|
135 | + "\$application_folder = '../../application';", |
|
136 | + "\$application_folder = '../../{$this->app_dir}';", |
|
137 | + $contents |
|
138 | + ); |
|
139 | + } |
|
140 | + } else { |
|
141 | + throw new Exception('Can\'t find "index.php".'); |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + file_put_contents($file, $contents); |
|
146 | + } |
|
147 | + |
|
148 | + public function update() |
|
149 | + { |
|
150 | + $target_dir = $this->app_dir.'/'.$this->test_dir.'/_ci_phpunit_test'; |
|
151 | + $this->recursiveUnlink($target_dir); |
|
152 | + $this->recursiveCopy( |
|
153 | + dirname(dirname(__FILE__)).'/application/tests/_ci_phpunit_test', |
|
154 | + $target_dir |
|
155 | + ); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Recursive Copy |
|
160 | + * |
|
161 | + * @param string $src |
|
162 | + * @param string $dst |
|
163 | + */ |
|
164 | + private function recursiveCopy($src, $dst) |
|
165 | + { |
|
166 | + @mkdir($dst, 0755); |
|
167 | + |
|
168 | + $iterator = new \RecursiveIteratorIterator( |
|
169 | + new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
170 | + \RecursiveIteratorIterator::SELF_FIRST |
|
171 | + ); |
|
172 | + |
|
173 | + foreach ($iterator as $file) { |
|
174 | + if ($file->isDir()) { |
|
175 | + @mkdir($dst.'/'.$iterator->getSubPathName()); |
|
176 | + } else { |
|
177 | + $success = copy($file, $dst.'/'.$iterator->getSubPathName()); |
|
178 | + if ($success) { |
|
179 | + if (! $this->silent) { |
|
180 | + echo 'copied: '.$dst.'/'.$iterator->getSubPathName().PHP_EOL; |
|
181 | + } |
|
182 | + } |
|
183 | + } |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Recursive Unlink |
|
189 | + * |
|
190 | + * @param string $dir |
|
191 | + */ |
|
192 | + private function recursiveUnlink($dir) |
|
193 | + { |
|
194 | + $iterator = new \RecursiveIteratorIterator( |
|
195 | + new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
196 | + \RecursiveIteratorIterator::CHILD_FIRST |
|
197 | + ); |
|
198 | + |
|
199 | + foreach ($iterator as $file) { |
|
200 | + if ($file->isDir()) { |
|
201 | + rmdir($file); |
|
202 | + } else { |
|
203 | + unlink($file); |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + rmdir($dir); |
|
208 | + } |
|
209 | 209 | } |