1 <?php
2
3 4 5 6 7
8 class Setup {
9
10 11 12 13 14 15 16 17 18 19
20 function checkDir($path, $msg = null) {
21 if(!$msg) {
22 $msg = $path;
23 }
24
25 if(file_exists($path)) {
26 _echo($msg . ' OK');
27 } else {
28 mkdir($path, 777, true);
29 _echo($msg . ' created');
30 }
31
32 return $this;
33 }
34
35 36 37 38 39 40
41 function checkPHP() {
42 return $this->checkBinaries(DIR_PHP, 'PHP directory', '\Setup\PHP');
43 }
44
45 46 47 48 49 50 51 52 53 54 55
56 protected function checkBinaries($dir, $message, $setup_class) {
57 if(!file_exists($dir)) {
58 _echo('Creating ' . $message);
59 mkdir($dir, 777, true);
60 }
61
62 $scan = scandir($dir);
63 Format::formatScandir($scan);
64
65 if(!empty($scan)) {
66 _echo($message . ' OK');
67 } else {
68 new $setup_class();
69 }
70
71 return $this;
72 }
73
74 75 76 77 78 79
80 function checkApache() {
81 return $this->checkBinaries(DIR_APACHE, 'Apache directory', '\Setup\Apache');
82 }
83
84 85 86 87 88 89
90 function checkMySQL() {
91 return $this->checkBinaries(DIR_MYSQL, 'MySQL directory', '\Setup\MySQL');
92 }
93
94 95 96 97 98 99
100 function checkDateTimezone() {
101 if(Settings::$s->{'php_date_timezone'}) {
102 _echo('PHP\'s date.timezone OK');
103 } else {
104 $timezone = trim(IO::readline('Please input the timezone for PHP, e.g. Europe/London]'));
105
106 if(!$timezone) {
107 $this->checkDateTimezone();
108 } else {
109 $split = explode('/', $timezone);
110 foreach($split as &$t) {
111 $t = trim(ucfirst($t));
112 }
113
114 Settings::$s->php_date_timezone = implode('/', $split);
115 Settings::$s->save();
116 _echo('Timezone set');
117 }
118 }
119
120 return $this;
121 }
122
123 124 125 126 127 128
129 function checkWWW() {
130 if(file_exists(DIR_WWW)) {
131 _echo('www dir OK');
132 } else {
133 _echo('www directory not found. Creating...');
134
135 $dir = DIR_WWW . 'my-default-website' . DIRECTORY_SEPARATOR;
136 mkdir($dir, 777, true);
137
138 copy(DIR_CORE . 'file_placeholders' . DIRECTORY_SEPARATOR . 'sample_index.php', $dir . 'index.php');
139 }
140
141 if(!\Settings::$s->web_dir) {
142 _echo('Set default website directory in AloWAMP settings');
143 \Settings::$s->web_dir = 'my-default-website';
144 \Settings::$s->save();
145 }
146
147 return $this;
148 }
149
150 151 152 153 154 155
156 function checkMemcache() {
157 if(file_exists(DIR_MEMCACHE)) {
158 _echo('Memcache OK');
159 } else {
160 $rl = \IO::readline('Memcache not found. Would you like to download it? It\'s an optional module. [Y/N]');
161 switch($rl) {
162 case 'y':
163 _echo('Contacting download server...');
164 new \Setup\Memcache();
165 break;
166 case 'n':
167 _echo('Memcache skipped');
168 break;
169 default:
170 return $this->checkMemcache();
171 }
172 }
173
174 return $this;
175 }
176
177 178 179 180 181 182
183 function checkRedis() {
184 return $this->checkBinaries(DIR_REDIS, 'Redis directory', '\Setup\Redis');
185 }
186 }