Skip to content

Commit

Permalink
Added badges and fixing small bug when using Eloquent models as crede…
Browse files Browse the repository at this point in the history
…ntials
  • Loading branch information
zzantares committed Jul 13, 2014
1 parent 98f5a02 commit 0be98ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This **PHP 5.3+** library allows you to interact with your Proxmox server via AP
[![Build Status](https://travis-ci.org/ZzAntares/ProxmoxVE.svg?branch=master)](https://travis-ci.org/ZzAntares/ProxmoxVE)
[![Latest Stable Version](https://poser.pugx.org/zzantares/proxmoxve/v/stable.svg)](https://packagist.org/packages/zzantares/proxmoxve)
[![Total Downloads](https://poser.pugx.org/zzantares/proxmoxve/downloads.svg)](https://packagist.org/packages/zzantares/proxmoxve)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ZzAntares/ProxmoxVE/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ZzAntares/ProxmoxVE/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/ZzAntares/ProxmoxVE/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/ZzAntares/ProxmoxVE/?branch=master)
[![Latest Unstable Version](https://poser.pugx.org/zzantares/proxmoxve/v/unstable.svg)](https://packagist.org/packages/zzantares/proxmoxve)
[![License](https://poser.pugx.org/zzantares/proxmoxve/license.svg)](https://packagist.org/packages/zzantares/proxmoxve)

Expand Down
25 changes: 23 additions & 2 deletions src/Proxmox.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ public function validCredentialsObject($credentials)
return true;
}

// Find properties that are using magic function
$hasHostname = isset($credentials->hostname);
$hasUsername = isset($credentials->username);
$hasPassword = isset($credentials->password);

if ($hasHostname and $hasUsername and $hasPassword) {
$this->accessibleBy = '__get';
return true;
}

$this->accessibleBy = false;
return false;
}
Expand All @@ -426,6 +436,17 @@ protected function loginUsingCredentials($credentials)
);
}

// In eloquent models properties not set are emppty thus null
if ($this->accessibleBy == '__get') {
return new Credentials(
$credentials->hostname,
$credentials->username,
$credentials->password,
empty($credentials->realm) ? 'pam' : $credentials->realm,
empty($credentials->port) ? '8006' : $credentials->port
);
}

if ($this->accessibleBy == 'methods') {
if (method_exists($credentials, 'getRealm')) {
$realm = $credentials->getRealm();
Expand All @@ -443,8 +464,8 @@ protected function loginUsingCredentials($credentials)
$credentials->getHostname(),
$credentials->getUsername(),
$credentials->getPassword(),
$realm, // Make it optional?
$port // Make it optional?
$realm,
$port
);
}

Expand Down

0 comments on commit 0be98ef

Please sign in to comment.