1 <?php
2
3 namespace Setup;
4
5 use Downloader;
6
7 8 9 10 11
12 abstract class AbstractBinSetup extends AbstractSetup {
13
14 15 16 17 18
19 protected $links;
20
21 22 23 24 25
26 protected $version;
27
28 29 30 31 32
33 protected $unzipped_destination;
34
35 36 37 38 39 40
41 protected function promptDownload() {
42 if(!empty($this->links)) {
43 $version_numbers = array_keys($this->links);
44 _echo('The following versions were found for download: ' . PHP_EOL . "\t"
45 . implode(PHP_EOL . "\t", $version_numbers));
46
47 $io = trim(\IO::readline('Which version would you like to download? Input N to abort'));
48
49 if(!$io) {
50 $this->promptDownload();
51 } elseif($io == 'n') {
52 die('Aborting.');
53 } elseif(!isset($this->links[$io])) {
54 _echo('The version you selected is not available for download.');
55 $this->promptDownload();
56 } else {
57 _echo('Contacting download server...');
58 $this->version = $io;
59 $this->download();
60
61 return $this;
62 }
63 } else {
64 die('Aborting.');
65 }
66
67 return $this;
68 }
69
70 71 72 73 74 75
76 protected function download() {
77 $this->downloader = new Downloader($this->links[$this->version], $this->dest);
78
79 if($this->downloader->download()) {
80 _echo('Download successful. Setting up version ' . $this->version);
81 sleep(1);
82 } else {
83 die('Download failed. Aborting setup.');
84 }
85
86 return $this;
87 }
88 }