Completed
Pull Request — master (#362)
by Kenji
03:23 queued 01:06
created
lib/Installer.php 2 patches
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -10,214 +10,214 @@
 block discarded – undo
10 10
 
11 11
 class Installer
12 12
 {
13
-    private $silent = false;
14
-    private $app_dir = 'application';  // -a DIRECTORY
15
-    private $pub_dir = 'public';       // -p DIRECTORY
16
-    private $test_dir = null;          // -t DIRECTORY
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 application 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 public directory: '.$argv[$i+1]);
59
-                    }
60
-                    $i++;
61
-                    break;
62
-                // php install.php -t application/tests
63
-                case '-t':
64
-                    if (is_dir($argv[$i+1])) {
65
-                        $this->test_dir = $argv[$i+1];
66
-                    } else {
67
-                        throw new Exception('No such test directory: '.$argv[$i+1]);
68
-                    }
69
-                    $i++;
70
-                    break;
71
-
72
-                case '--from-composer':
73
-                    $this->from_composer = true;
74
-                    $i++;
75
-                    break;
76
-
77
-                default:
78
-                    throw new Exception('Unknown argument: '.$argv[$i]);
79
-            }
80
-        }
81
-        if (is_null($this->test_dir)) {
82
-            $test_dir = $this->app_dir.'/tests';
83
-        }
84
-    }
85
-
86
-    public function install()
87
-    {
88
-        $this->recursiveCopy(
89
-            dirname(dirname(__FILE__)).'/application/tests',
90
-            $this->test_dir
91
-        );
92
-        $this->fixPath();
93
-        if ($this->from_composer) {
94
-            $this->recursiveUnlink($this->app_dir.'/'.$this->test_dir.'/_ci_phpunit_test');
95
-        }
96
-    }
97
-
98
-    /**
99
-     * Fix paths in Bootstrap.php
100
-     *
101
-     * @FIXME Too ad hoc. Must rewrite, because can't handle complex paths.
102
-     */
103
-    private function fixPath()
104
-    {
105
-        $file = $this->test_dir.'/Bootstrap.php';
106
-        $contents = file_get_contents($file);
107
-
108
-        if (! file_exists('system')) {
109
-            if (file_exists('vendor/codeigniter/framework/system')) {
110
-                $contents = str_replace(
111
-                    '$system_path = \'../../system\';',
112
-                    '$system_path = \'../../vendor/codeigniter/framework/system\';',
113
-                    $contents
114
-                );
115
-            } else {
116
-                throw new Exception('Can\'t find "system" folder.');
117
-            }
118
-        }
119
-
120
-        if (! file_exists('index.php')) {
121
-            if (file_exists($this->pub_dir.'/index.php')) {
122
-                // CodeIgniter 3.0.6 and after
123
-                $contents = str_replace(
124
-                    "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);",
125
-                    "define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').DIRECTORY_SEPARATOR);",
126
-                    $contents
127
-                );
128
-                // CodeIgniter 3.0.5 and before
129
-                $contents = str_replace(
130
-                    "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');",
131
-                    "define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').'/');",
132
-                    $contents
133
-                );
134
-            } elseif (file_exists($this->app_dir.'/public/index.php')) {
135
-                // CodeIgniter 3.0.6 and after
136
-                $contents = str_replace(
137
-                    "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);",
138
-                    "define('FCPATH', realpath(dirname(__FILE__).'/../public').DIRECTORY_SEPARATOR);",
139
-                    $contents
140
-                );
141
-                // CodeIgniter 3.0.5 and before
142
-                $contents = str_replace(
143
-                    "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');",
144
-                    "define('FCPATH', realpath(dirname(__FILE__).'/../public').'/');",
145
-                    $contents
146
-                );
147
-                if ($this->app_dir !== 'application') {
148
-                    $contents = str_replace(
149
-                        "\$application_folder = '../../application';",
150
-                        "\$application_folder = '../../{$this->app_dir}';",
151
-                        $contents
152
-                    );
153
-                }
154
-            } else {
155
-                throw new Exception('Can\'t find "index.php".');
156
-            }
157
-        }
158
-
159
-        file_put_contents($file, $contents);
160
-    }
161
-
162
-    public function update()
163
-    {
164
-        $target_dir = $this->test_dir.'/_ci_phpunit_test';
165
-        $this->recursiveUnlink($target_dir);
166
-        $this->recursiveCopy(
167
-            dirname(dirname(__FILE__)).'/application/tests/_ci_phpunit_test',
168
-            $target_dir
169
-        );
170
-    }
171
-
172
-    /**
173
-     * Recursive Copy
174
-     *
175
-     * @param string $src
176
-     * @param string $dst
177
-     */
178
-    private function recursiveCopy($src, $dst)
179
-    {
180
-        @mkdir($dst, 0755);
181
-
182
-        $iterator = new \RecursiveIteratorIterator(
183
-            new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS),
184
-            \RecursiveIteratorIterator::SELF_FIRST
185
-        );
186
-
187
-        foreach ($iterator as $file) {
188
-            if ($file->isDir()) {
189
-                @mkdir($dst.'/'.$iterator->getSubPathName());
190
-            } else {
191
-                $success = copy($file, $dst.'/'.$iterator->getSubPathName());
192
-                if ($success) {
193
-                    if (! $this->silent) {
194
-                        echo 'copied: '.$dst.'/'.$iterator->getSubPathName().PHP_EOL;
195
-                    }
196
-                }
197
-            }
198
-        }
199
-    }
200
-
201
-    /**
202
-     * Recursive Unlink
203
-     *
204
-     * @param string $dir
205
-     */
206
-    private function recursiveUnlink($dir)
207
-    {
208
-        $iterator = new \RecursiveIteratorIterator(
209
-            new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
210
-            \RecursiveIteratorIterator::CHILD_FIRST
211
-        );
212
-
213
-        foreach ($iterator as $file) {
214
-            if ($file->isDir()) {
215
-                rmdir($file);
216
-            } else {
217
-                unlink($file);
218
-            }
219
-        }
220
-
221
-        rmdir($dir);
222
-    }
13
+	private $silent = false;
14
+	private $app_dir = 'application';  // -a DIRECTORY
15
+	private $pub_dir = 'public';       // -p DIRECTORY
16
+	private $test_dir = null;          // -t DIRECTORY
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 application 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 public directory: '.$argv[$i+1]);
59
+					}
60
+					$i++;
61
+					break;
62
+				// php install.php -t application/tests
63
+				case '-t':
64
+					if (is_dir($argv[$i+1])) {
65
+						$this->test_dir = $argv[$i+1];
66
+					} else {
67
+						throw new Exception('No such test directory: '.$argv[$i+1]);
68
+					}
69
+					$i++;
70
+					break;
71
+
72
+				case '--from-composer':
73
+					$this->from_composer = true;
74
+					$i++;
75
+					break;
76
+
77
+				default:
78
+					throw new Exception('Unknown argument: '.$argv[$i]);
79
+			}
80
+		}
81
+		if (is_null($this->test_dir)) {
82
+			$test_dir = $this->app_dir.'/tests';
83
+		}
84
+	}
85
+
86
+	public function install()
87
+	{
88
+		$this->recursiveCopy(
89
+			dirname(dirname(__FILE__)).'/application/tests',
90
+			$this->test_dir
91
+		);
92
+		$this->fixPath();
93
+		if ($this->from_composer) {
94
+			$this->recursiveUnlink($this->app_dir.'/'.$this->test_dir.'/_ci_phpunit_test');
95
+		}
96
+	}
97
+
98
+	/**
99
+	 * Fix paths in Bootstrap.php
100
+	 *
101
+	 * @FIXME Too ad hoc. Must rewrite, because can't handle complex paths.
102
+	 */
103
+	private function fixPath()
104
+	{
105
+		$file = $this->test_dir.'/Bootstrap.php';
106
+		$contents = file_get_contents($file);
107
+
108
+		if (! file_exists('system')) {
109
+			if (file_exists('vendor/codeigniter/framework/system')) {
110
+				$contents = str_replace(
111
+					'$system_path = \'../../system\';',
112
+					'$system_path = \'../../vendor/codeigniter/framework/system\';',
113
+					$contents
114
+				);
115
+			} else {
116
+				throw new Exception('Can\'t find "system" folder.');
117
+			}
118
+		}
119
+
120
+		if (! file_exists('index.php')) {
121
+			if (file_exists($this->pub_dir.'/index.php')) {
122
+				// CodeIgniter 3.0.6 and after
123
+				$contents = str_replace(
124
+					"define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);",
125
+					"define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').DIRECTORY_SEPARATOR);",
126
+					$contents
127
+				);
128
+				// CodeIgniter 3.0.5 and before
129
+				$contents = str_replace(
130
+					"define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');",
131
+					"define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').'/');",
132
+					$contents
133
+				);
134
+			} elseif (file_exists($this->app_dir.'/public/index.php')) {
135
+				// CodeIgniter 3.0.6 and after
136
+				$contents = str_replace(
137
+					"define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);",
138
+					"define('FCPATH', realpath(dirname(__FILE__).'/../public').DIRECTORY_SEPARATOR);",
139
+					$contents
140
+				);
141
+				// CodeIgniter 3.0.5 and before
142
+				$contents = str_replace(
143
+					"define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');",
144
+					"define('FCPATH', realpath(dirname(__FILE__).'/../public').'/');",
145
+					$contents
146
+				);
147
+				if ($this->app_dir !== 'application') {
148
+					$contents = str_replace(
149
+						"\$application_folder = '../../application';",
150
+						"\$application_folder = '../../{$this->app_dir}';",
151
+						$contents
152
+					);
153
+				}
154
+			} else {
155
+				throw new Exception('Can\'t find "index.php".');
156
+			}
157
+		}
158
+
159
+		file_put_contents($file, $contents);
160
+	}
161
+
162
+	public function update()
163
+	{
164
+		$target_dir = $this->test_dir.'/_ci_phpunit_test';
165
+		$this->recursiveUnlink($target_dir);
166
+		$this->recursiveCopy(
167
+			dirname(dirname(__FILE__)).'/application/tests/_ci_phpunit_test',
168
+			$target_dir
169
+		);
170
+	}
171
+
172
+	/**
173
+	 * Recursive Copy
174
+	 *
175
+	 * @param string $src
176
+	 * @param string $dst
177
+	 */
178
+	private function recursiveCopy($src, $dst)
179
+	{
180
+		@mkdir($dst, 0755);
181
+
182
+		$iterator = new \RecursiveIteratorIterator(
183
+			new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS),
184
+			\RecursiveIteratorIterator::SELF_FIRST
185
+		);
186
+
187
+		foreach ($iterator as $file) {
188
+			if ($file->isDir()) {
189
+				@mkdir($dst.'/'.$iterator->getSubPathName());
190
+			} else {
191
+				$success = copy($file, $dst.'/'.$iterator->getSubPathName());
192
+				if ($success) {
193
+					if (! $this->silent) {
194
+						echo 'copied: '.$dst.'/'.$iterator->getSubPathName().PHP_EOL;
195
+					}
196
+				}
197
+			}
198
+		}
199
+	}
200
+
201
+	/**
202
+	 * Recursive Unlink
203
+	 *
204
+	 * @param string $dir
205
+	 */
206
+	private function recursiveUnlink($dir)
207
+	{
208
+		$iterator = new \RecursiveIteratorIterator(
209
+			new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
210
+			\RecursiveIteratorIterator::CHILD_FIRST
211
+		);
212
+
213
+		foreach ($iterator as $file) {
214
+			if ($file->isDir()) {
215
+				rmdir($file);
216
+			} else {
217
+				unlink($file);
218
+			}
219
+		}
220
+
221
+		rmdir($dir);
222
+	}
223 223
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@  discard block
 block discarded – undo
11 11
 class Installer
12 12
 {
13 13
     private $silent = false;
14
-    private $app_dir = 'application';  // -a DIRECTORY
15
-    private $pub_dir = 'public';       // -p DIRECTORY
16
-    private $test_dir = null;          // -t DIRECTORY
14
+    private $app_dir = 'application'; // -a DIRECTORY
15
+    private $pub_dir = 'public'; // -p DIRECTORY
16
+    private $test_dir = null; // -t DIRECTORY
17 17
     private $from_composer = false;
18 18
 
19 19
     public function __construct($argv)
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
         }
31 31
 
32 32
         for ($i = 1; $i <= $argc; $i++) {
33
-            if (! isset($argv[$i])) {
33
+            if ( ! isset($argv[$i])) {
34 34
                 break;
35 35
             }
36 36
 
@@ -42,29 +42,29 @@  discard block
 block discarded – undo
42 42
 
43 43
                 // php install.php -a application
44 44
                 case '-a':
45
-                    if (is_dir($argv[$i+1])) {
46
-                        $this->app_dir = $argv[$i+1];
45
+                    if (is_dir($argv[$i + 1])) {
46
+                        $this->app_dir = $argv[$i + 1];
47 47
                     } else {
48
-                        throw new Exception('No such application directory: '.$argv[$i+1]);
48
+                        throw new Exception('No such application directory: '.$argv[$i + 1]);
49 49
                     }
50 50
                     $i++;
51 51
                     break;
52 52
 
53 53
                 // php install.php -p public
54 54
                 case '-p':
55
-                    if (is_dir($argv[$i+1])) {
56
-                        $this->pub_dir = $argv[$i+1];
55
+                    if (is_dir($argv[$i + 1])) {
56
+                        $this->pub_dir = $argv[$i + 1];
57 57
                     } else {
58
-                        throw new Exception('No such public directory: '.$argv[$i+1]);
58
+                        throw new Exception('No such public directory: '.$argv[$i + 1]);
59 59
                     }
60 60
                     $i++;
61 61
                     break;
62 62
                 // php install.php -t application/tests
63 63
                 case '-t':
64
-                    if (is_dir($argv[$i+1])) {
65
-                        $this->test_dir = $argv[$i+1];
64
+                    if (is_dir($argv[$i + 1])) {
65
+                        $this->test_dir = $argv[$i + 1];
66 66
                     } else {
67
-                        throw new Exception('No such test directory: '.$argv[$i+1]);
67
+                        throw new Exception('No such test directory: '.$argv[$i + 1]);
68 68
                     }
69 69
                     $i++;
70 70
                     break;
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
         $file = $this->test_dir.'/Bootstrap.php';
106 106
         $contents = file_get_contents($file);
107 107
 
108
-        if (! file_exists('system')) {
108
+        if ( ! file_exists('system')) {
109 109
             if (file_exists('vendor/codeigniter/framework/system')) {
110 110
                 $contents = str_replace(
111 111
                     '$system_path = \'../../system\';',
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
             }
118 118
         }
119 119
 
120
-        if (! file_exists('index.php')) {
120
+        if ( ! file_exists('index.php')) {
121 121
             if (file_exists($this->pub_dir.'/index.php')) {
122 122
                 // CodeIgniter 3.0.6 and after
123 123
                 $contents = str_replace(
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
             } else {
191 191
                 $success = copy($file, $dst.'/'.$iterator->getSubPathName());
192 192
                 if ($success) {
193
-                    if (! $this->silent) {
193
+                    if ( ! $this->silent) {
194 194
                         echo 'copied: '.$dst.'/'.$iterator->getSubPathName().PHP_EOL;
195 195
                     }
196 196
                 }
Please login to merge, or discard this patch.