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