Skip to content

Commit

Permalink
Merge pull request #35 from lukasbruha/master
Browse files Browse the repository at this point in the history
onActionExecuted event for better logs handling
  • Loading branch information
franklupo authored May 17, 2024
2 parents 42376fd + 4921cdc commit db18a55
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/PveClientBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class PveClientBase
*/
private $validateCertificate = false;


/** @var callable[]
*
*/
public $onActionExecuted = [];

/**
* Client constructor.
* @param string $hostname Host Proxmox VE
Expand Down Expand Up @@ -332,7 +338,7 @@ public function delete($resource, $parameters = [])
/**
* @ignore
*/
private function executeAction($resource, $method, $parameters = [])
protected function executeAction($resource, $method, $parameters = [])
{
//url resource
$url = "{$this->getApiUrl()}{$resource}";
Expand Down Expand Up @@ -390,7 +396,7 @@ private function executeAction($resource, $method, $parameters = [])
array_push($headers, 'Content-Type: application/json');
array_push($headers, 'Content-Length: ' . strlen($data));
}

curl_setopt($prox_ch, CURLOPT_POSTFIELDS, $data);
$methodType = "CREATE";
break;
Expand Down Expand Up @@ -462,6 +468,21 @@ private function executeAction($resource, $method, $parameters = [])
$this->responseType
);

if (is_array($this->onActionExecuted) && count($this->onActionExecuted)) {
foreach ($this->onActionExecuted as $call) {
if (is_callable($call)) {
call_user_func_array($call, [
$this->lastResult, [
'url' => $url,
'method' => $method,
'parameters' => $parameters,
'headers' => $headers
]
]);
}
}
}

if ($this->getDebugLevel() >= 2) {
if (is_array($obj)) {
echo '<pre>';
Expand Down

0 comments on commit db18a55

Please sign in to comment.