use new Psr18Client

This commit is contained in:
2024-09-13 01:04:38 +02:00
parent a698255f01
commit 72023d4591
2 changed files with 37 additions and 2 deletions

View File

@@ -2,9 +2,43 @@
namespace Magdev\RedmineBundle\Client;
use Redmine\Client\NativeCurlClient;
use Redmine\Client\Psr18Client;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory as GuzzleHttpFactory;
class RedmineClient extends NativeCurlClient
final class RedmineClient
{
private ?Psr18Client $client = null;
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($name, $arguments)
{
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);
}
}

View File

@@ -21,6 +21,7 @@ final class MagdevRedmineExtension extends Extension
foreach ($config['connections'] as $name => $connection) {
$id = sprintf('magdev.redmine.%s', $name);
$container->register($id, RedmineClient::class)
->setArguments([$connection['url'], $connection['apikey']]);
$container->registerAliasForArgument($id, RedmineClient::class, "{$name}Client");