Files
redmine-bundle/src/Client/RedmineClient.php

45 lines
1.0 KiB
PHP
Raw Normal View History

2024-09-13 00:43:53 +02:00
<?php
namespace Magdev\RedmineBundle\Client;
2024-09-13 01:04:38 +02:00
use Redmine\Client\Psr18Client;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory as GuzzleHttpFactory;
2024-09-13 00:43:53 +02:00
2024-09-13 01:04:38 +02:00
final class RedmineClient
2024-09-13 00:43:53 +02:00
{
2024-09-13 01:04:38 +02:00
private ?Psr18Client $client = null;
2024-09-13 00:43:53 +02:00
2024-09-13 01:04:38 +02:00
public function __construct(
string $url,
string $apikeyOrUsername,
?string $password = null
) {
$guzzle = new GuzzleClient();
$factory = new GuzzleHttpFactory();
$this->client = new Psr18Client(
$guzzle,
$factory,
$factory,
$url,
$apikeyOrUsername,
$password
);
}
public function __call(mixed $name, mixed $arguments): mixed
2024-09-13 01:04:38 +02:00
{
if (!method_exists($this->client, $name)) {
throw new \BadMethodCallException(sprintf(
'Method %s, doesn\'t exist in class %s',
$name,
get_class($this->client)
));
}
return call_user_func_array([$this->client, $name], $arguments);
}
2024-09-13 00:43:53 +02:00
}