Skip to content

Commit

Permalink
Merge pull request #7 from DiegoKarabin/patch-3
Browse files Browse the repository at this point in the history
Update VestaAPI.php
  • Loading branch information
AlexR1712 committed Aug 10, 2018
2 parents 1d9850a + a06b8ab commit fa249cc
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/Services/VestaAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ class VestaAPI
{
use BD, DNS, User, Web, Service, Cron, FileSystem;

/**
* @var
*/
public $userName = '';

/**
* return no|yes|json.
*
* @var string
*/
public $returnCode = 'yes';

/**
* @var
*/
private $userName = '';

/**
* @var string
*/
Expand Down Expand Up @@ -50,11 +50,14 @@ public function server($server = '')
}

if ($this->keysCheck($server, $allServers)) {
throw new \Exception('Specified server config does not contain host or key');
throw new \Exception(
'Specified server config does not contain host, user or key'
);
}

$this->key = (string) $allServers[$server]['key'];
$this->host = (string) $allServers[$server]['host'];
$this->username = (string) $allServers[$server]['admin_user'];
$this->key = (string) $allServers[$server]['admin_password'];

return $this;
}
Expand All @@ -67,23 +70,31 @@ public function server($server = '')
*/
private function keysCheck($server, $config)
{
return !isset($config[$server]['key']) || !isset($config[$server]['host']);
return !isset($config[$server]['admin_user']) ||
!isset($config[$server]['host']) ||
!isset($config[$server]['admin_password']);
}

/**
* @param string $userName
*
* @throws \Exception
*
* @return $this
*/
public function setUserName($userName = '')
public function setCredentials($userName = '', $password = '')
{
if (empty($userName)) {
throw new \Exception('Server is not specified');
throw new \Exception('Username is not specified');
}
$this->userName = $userName;

if (empty($password)) {
throw new \Exception('Password is not specified');
}

$this->key = $password;

return $this;
}

Expand Down

0 comments on commit fa249cc

Please sign in to comment.