Skip to content

Commit

Permalink
Merge pull request #41 from MrKampf/0.4.4
Browse files Browse the repository at this point in the history
Change composer information
  • Loading branch information
MrKampf authored Jan 3, 2023
2 parents ce5bfac + 028fbf3 commit b0c858d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 18 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,49 @@ print_r($proxmox->nodes()->node("node_name")->qemu()->get());

```

---
### Example for lazy login

```php
<?php
// Require the autoloader
require_once 'vendor/autoload.php';

// Use the library namespace
use Proxmox\PVE;

//Example for lazy login
$proxmox = new PVE("hostname", "username", "password", 8006, "pve", false, true);

//Login
$proxmox->getApi()->login();

// Read all nodes
print_r($proxmox->nodes()->get());

```

---
### Example for custom http client

```php
<?php
// Require the autoloader
require_once 'vendor/autoload.php';

// Use the library namespace
use Proxmox\PVE;

$customGuzzleHttpClient = new GuzzleHttp\Client();

//Example for lazy login
$proxmox = new PVE("hostname", "username", "password", 8006, "pve", false, false, $customGuzzleHttpClient);

// Read all nodes
print_r($proxmox->nodes()->get());

```

---
### For version 3.1

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"source": "https://github.com/MrKampf/proxmoxVE"
},
"require": {
"php": "^8.0|7.4|^8.1",
"php": "^8.0|^8.1",
"lib-curl": "*",
"guzzlehttp/guzzle": "*",
"ext-json": "*"
Expand Down
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Proxmox/PVE.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ class PVE
* @param int $port
* @param string $authType
* @param bool $debug
* @param bool $lazyLogin
* @param Client|null $httpClient
*/
public function __construct(string $hostname, string $username, string $password, int $port = 8006, string $authType = "pam", bool $debug = false, Client|NULL $httpClient = NULL)
public function __construct(string $hostname, string $username, string $password, int $port = 8006, string $authType = "pam", bool $debug = false, bool $lazyLogin = false, Client|null $httpClient = null)
{
if($httpClient === NULL) {
if ($httpClient === NULL) {
$httpClient = new Client();
}
$this->setHostname($hostname); //Save hostname in class variable
Expand All @@ -75,7 +77,10 @@ public function __construct(string $hostname, string $username, string $password
$this->setApiURL('https://' . $this->getHostname() . ':' . $this->getPort() . '/api2/json/'); //Create the basic api url
$this->setApi(new Api($this)); //Create the api object
$this->setHttpClient($httpClient); //Create a new guzzle client
$this->getApi()->login(); //Login to the api

if (!$lazyLogin) {
$this->getApi()->login(); //Login to the api
}
}

/**
Expand Down

0 comments on commit b0c858d

Please sign in to comment.