AloWAMP source documentation
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • None
  • PHP
  • Setup
  • VersionSwitch

Classes

  • cURL
  • Downloader
  • Format
  • Handler
  • IO
  • Router
  • Service
  • Settings
  • Setup

Functions

  • _echo
  • get
  1 <?php
  2 
  3    /**
  4     * Setup script walkthrough
  5     *
  6     * @author Art <a.molcanovas@gmail.com>
  7     */
  8    class Setup {
  9 
 10       /**
 11        * Checks if a directory exists
 12        *
 13        * @author Art <a.molcanovas@gmail.com>
 14        *
 15        * @param string $path Path to check
 16        * @param string $msg  Check identifier (for echo)
 17        *
 18        * @return Setup
 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        * Checks if PHP is set up
 37        *
 38        * @author Art <a.molcanovas@gmail.com>
 39        * @return Setup
 40        */
 41       function checkPHP() {
 42          return $this->checkBinaries(DIR_PHP, 'PHP directory', '\Setup\PHP');
 43       }
 44 
 45       /**
 46        * Generic method to check if binaries are installed properly
 47        *
 48        * @author Art <a.molcanovas@gmail.com>
 49        *
 50        * @param string $dir         dir to scan
 51        * @param string $message     scan identifier
 52        * @param string $setup_class Setup class name
 53        *
 54        * @return Setup
 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        * Checks if Apache HTTPD is installed properly
 76        *
 77        * @author Art <a.molcanovas@gmail.com>
 78        * @return Setup
 79        */
 80       function checkApache() {
 81          return $this->checkBinaries(DIR_APACHE, 'Apache directory', '\Setup\Apache');
 82       }
 83 
 84       /**
 85        * Checks if MySQL is installed properly
 86        *
 87        * @author Art <a.molcanovas@gmail.com>
 88        * @return Setup
 89        */
 90       function checkMySQL() {
 91          return $this->checkBinaries(DIR_MYSQL, 'MySQL directory', '\Setup\MySQL');
 92       }
 93 
 94       /**
 95        * Checks if date.timezone is set up for PHP
 96        *
 97        * @author Art <a.molcanovas@gmail.com>
 98        * @return Setup
 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        * Checks if the WWW dir is set up
125        *
126        * @author Art <a.molcanovas@gmail.com>
127        * @return Setup
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        * Checks and creates the memcache directory
152        *
153        * @author Art <a.molcanovas@gmail.com>
154        * @return Setup
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        * Checks if Redis is set up properly
179        *
180        * @author Art <a.molcanovas@gmail.com>
181        * @return Setup
182        */
183       function checkRedis() {
184          return $this->checkBinaries(DIR_REDIS, 'Redis directory', '\Setup\Redis');
185       }
186    }
AloWAMP source documentation API documentation generated byApiGen 2.8.0