From 028fbf39c7c05ac8e1a240aa02759197aa2e9b9b Mon Sep 17 00:00:00 2001 From: MrKampf Date: Tue, 3 Jan 2023 10:01:53 +0100 Subject: [PATCH] Change composer information Example added for lazy login and custom http client Changed code for lazy login --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ composer.json | 2 +- composer.lock | 28 ++++++++++++++-------------- src/Proxmox/PVE.php | 11 ++++++++--- 4 files changed, 66 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5f71dda..a8eaa86 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,49 @@ print_r($proxmox->nodes()->node("node_name")->qemu()->get()); ``` +--- +### Example for lazy login + +```php +getApi()->login(); + +// Read all nodes +print_r($proxmox->nodes()->get()); + +``` + +--- +### Example for custom http client + +```php +nodes()->get()); + +``` + --- ### For version 3.1 diff --git a/composer.json b/composer.json index 7dd4380..6d39454 100644 --- a/composer.json +++ b/composer.json @@ -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": "*" diff --git a/composer.lock b/composer.lock index 18181ce..98800d8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "02c245ecc30853c259a08d0a083a20bc", + "content-hash": "f69ae526626a0300c225d854ee45d6c0", "packages": [ { "name": "guzzlehttp/guzzle", @@ -220,16 +220,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "2.4.1", + "version": "2.4.3", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "69568e4293f4fa993f3b0e51c9723e1e17c41379" + "reference": "67c26b443f348a51926030c83481b85718457d3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/69568e4293f4fa993f3b0e51c9723e1e17c41379", - "reference": "69568e4293f4fa993f3b0e51c9723e1e17c41379", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/67c26b443f348a51926030c83481b85718457d3d", + "reference": "67c26b443f348a51926030c83481b85718457d3d", "shasum": "" }, "require": { @@ -319,7 +319,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.4.1" + "source": "https://github.com/guzzle/psr7/tree/2.4.3" }, "funding": [ { @@ -335,7 +335,7 @@ "type": "tidelift" } ], - "time": "2022-08-28T14:45:39+00:00" + "time": "2022-10-26T14:07:24+00:00" }, { "name": "psr/http-client", @@ -543,16 +543,16 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.1.1", + "version": "v3.2.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918" + "reference": "1ee04c65529dea5d8744774d474e7cbd2f1206d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918", - "reference": "07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/1ee04c65529dea5d8744774d474e7cbd2f1206d3", + "reference": "1ee04c65529dea5d8744774d474e7cbd2f1206d3", "shasum": "" }, "require": { @@ -561,7 +561,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.1-dev" + "dev-main": "3.3-dev" }, "thanks": { "name": "symfony/contracts", @@ -590,7 +590,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.1.1" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.2.0" }, "funding": [ { @@ -606,7 +606,7 @@ "type": "tidelift" } ], - "time": "2022-02-25T11:15:52+00:00" + "time": "2022-11-25T10:21:52+00:00" } ], "packages-dev": [], diff --git a/src/Proxmox/PVE.php b/src/Proxmox/PVE.php index fac6009..8904069 100644 --- a/src/Proxmox/PVE.php +++ b/src/Proxmox/PVE.php @@ -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 @@ -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 + } } /**