public function prepareServers()
{
$defaults = ['scheme' => 'ftp', 'host' => '', 'user' => '', 'pass' => '', 'path' => '/', 'privkey' => '', 'port' => null, 'passive' => null, 'timeout' => null, 'ssl' => false, 'visibility' => 'public', 'permPublic' => 0774, 'permPrivate' => 0700, 'permissions' => null, 'directoryPerm' => 0755, 'branch' => '', 'include' => [], 'exclude' => [], 'copy' => [], 'purge' => [], 'pre-deploy' => [], 'post-deploy' => [], 'pre-deploy-remote' => [], 'post-deploy-remote' => []];
$iniFile = $this->repo . DIRECTORY_SEPARATOR . $this->iniFilename;
$servers = $this->parseIniFile($iniFile);
foreach ($servers as $name => $options) {
// If a server is specified, we can skip adding the others
if ($this->server != '' && $this->server != $name) {
continue;
}
$options = array_merge($defaults, $options);
// Determine if a default server is configured
if ($name == 'default') {
$this->defaultServer = true;
}
// Re-merge parsed URL in quickmode
if (isset($options['quickmode'])) {
$options = array_merge($options, parse_url($options['quickmode']));
}
// Ignoring for the win
$this->filesToExclude[$name] = $this->globalFilesToExclude;
$this->filesToExclude[$name][] = $this->iniFilename;
if (!empty($servers[$name]['exclude'])) {
$this->filesToExclude[$name] = array_merge($this->filesToExclude[$name], $servers[$name]['exclude']);
}
if (!empty($servers[$name]['include'])) {
$this->filesToInclude[$name] = $servers[$name]['include'];
}
if (!empty($servers[$name]['copy'])) {
$this->copyDirs[$name] = $servers[$name]['copy'];
}
if (!empty($servers[$name]['purge'])) {
$this->purgeDirs[$name] = $servers[$name]['purge'];
}
if (!empty($servers[$name]['pre-deploy'])) {
$this->preDeploy[$name] = $servers[$name]['pre-deploy'];
}
if (!empty($servers[$name]['post-deploy'])) {
$this->postDeploy[$name] = $servers[$name]['post-deploy'];
}
if (!empty($servers[$name]['pre-deploy-remote'])) {
$this->preDeployRemote[$name] = $servers[$name]['pre-deploy-remote'];
}
if (!empty($servers[$name]['post-deploy-remote'])) {
$this->postDeployRemote[$name] = $servers[$name]['post-deploy-remote'];
}
// Set host from environment variable if it does not exist in the config
if (empty($options['host']) && !empty(getenv('PHPLOY_HOST'))) {
$options['host'] = getenv('PHPLOY_HOST');
}
// Set port number from environment variable if it does not exist in the config
if (empty($options['port']) && !empty(getenv('PHPLOY_PORT'))) {
$options['port'] = getenv('PHPLOY_PORT');
}
// Set username from environment variable if it does not exist in the config
if (empty($options['user']) && !empty(getenv('PHPLOY_USER'))) {
$options['user'] = getenv('PHPLOY_USER');
}
// Ask for a password if it is empty and a private key is not provided
if ($options['pass'] === '' && $options['privkey'] === '') {
// Look for .phploy config file
if (file_exists($this->getPasswordFile())) {
$options['pass'] = $this->getPasswordFromIniFile($name);
} elseif (!empty(getenv('PHPLOY_PASS'))) {
$options['pass'] = getenv('PHPLOY_PASS');
} else {
fwrite(STDOUT, 'No password has been provided for user "' . $options['user'] . '". Please enter a password: ');
$options['pass'] = $this->getPassword();
$this->cli->lightGreen()->out("\r\n" . 'Password received. Continuing deployment ...');
}
}
// Set the path from environment variable if it does not exist in the config
if (empty($options['path']) && !empty(getenv('PHPLOY_PATH'))) {
$options['path'] = getenv('PHPLOY_PATH');
}
$this->servers[$name] = $options;
}
}