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