diff --git a/src/Client/RedmineClient.php b/src/Client/RedmineClient.php index a50f559..251d0e8 100644 --- a/src/Client/RedmineClient.php +++ b/src/Client/RedmineClient.php @@ -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); + } } diff --git a/src/DependencyInjection/MagdevRedmineExtension.php b/src/DependencyInjection/MagdevRedmineExtension.php index bf4f572..275444e 100644 --- a/src/DependencyInjection/MagdevRedmineExtension.php +++ b/src/DependencyInjection/MagdevRedmineExtension.php @@ -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");