1 <?php
2
3 namespace Setup;
4
5 use Service;
6
7 8 9 10 11
12 class Memcache extends AbstractSetup {
13
14 15 16 17 18
19 const MEMCACHE_DOWNLOAD_SOURCE = 'https://github.com/Alorel/AloWAMP/archive/bin/memcached.zip';
20
21 22 23 24 25
26 function __construct() {
27 $this->dest = DIR_TMP . 'memcache.zip';
28 $this->dest_unzip = DIR_TMP . 'AloWAMP-bin-memcached' . DIRECTORY_SEPARATOR;
29 $this->download()
30 ->unzip()
31 ->copy()
32 ->installService();
33 }
34
35 36 37 38 39 40
41 protected function installService() {
42 if(Service::exists('alomemcache')) {
43 _echo('Removing previous AloWAMP Memcache service');
44 _echo(Service::delete('alomemcache'));
45 }
46
47 _echo('Installing Memcache service');
48 _echo(Service::installExe('alomemcache', DIR_MEMCACHE . 'memcached.exe -d runservice', 'AloWAMP Memcache'));
49
50 return $this;
51 }
52
53 54 55 56 57 58
59 protected function copy() {
60 _echo('Copying unzipped contents..');
61
62 shell_exec('xcopy /s /e "' .
63 rtrim($this->dest_unzip, DIRECTORY_SEPARATOR) .
64 '" "' .
65 rtrim(DIR_INDEX, DIRECTORY_SEPARATOR) .
66 '"');
67
68 if(file_exists(DIR_INDEX . 'README.md')) {
69 unlink(DIR_INDEX . 'README.md');
70 }
71
72 if(file_exists(DIR_MEMCACHE)) {
73 _echo('Copy successful!');
74 $this->cleanup();
75 } else {
76 die('Failed to copy. Terminating setup.');
77 }
78
79 return $this;
80 }
81
82 83 84 85 86 87
88 protected function unzip() {
89 _echo('Unzipping...');
90 $zip = new \ZipArchive();
91 $res = $zip->open($this->dest);
92
93 if($res === true) {
94 if(file_exists($this->dest_unzip)) {
95 rmdir($this->dest_unzip);
96 }
97
98 $zip->extractTo(DIR_TMP);
99 $zip->close();
100 } else {
101 die('Failed to unzip ' . $this->dest . '. Terminating.');
102 }
103
104 return $this;
105 }
106
107 108 109 110 111 112
113 protected function download() {
114 $this->downloader = new \Downloader(self::MEMCACHE_DOWNLOAD_SOURCE, $this->dest);
115
116 if($this->downloader->download()) {
117 _echo('Download successful. Setting up Memcache...');
118 } else {
119 die('Download failed. Aborting setup.');
120 }
121
122 return $this;
123 }
124 }