diff --git a/composer.json b/composer.json index e6f3c51..dae030b 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "kbsali/redmine-api": "^2.7", "guzzlehttp/guzzle": "^7", "symfony/cache-contracts": "^3.5", - "symfony/cache": "^7.1" + "symfony/cache": "^7.1", + "symfony/yaml": "^7.1" }, "require-dev": { "phpunit/phpunit": "^9.5 || ^10", diff --git a/composer.lock b/composer.lock index 5b47877..0af9cd5 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": "d59ee548397de88385ff625f1c6cc334", + "content-hash": "905e28463a875d6e2812528b84436e7b", "packages": [ { "name": "guzzlehttp/guzzle", @@ -991,6 +991,85 @@ ], "time": "2024-04-18T09:32:20+00:00" }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.31.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638", + "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "provide": { + "ext-ctype": "*" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-09T11:45:10+00:00" + }, { "name": "symfony/service-contracts", "version": "v3.5.0", @@ -1149,6 +1228,77 @@ } ], "time": "2024-06-28T08:00:31+00:00" + }, + { + "name": "symfony/yaml", + "version": "v7.1.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "92e080b851c1c655c786a2da77f188f2dccd0f4b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/92e080b851c1c655c786a2da77f188f2dccd0f4b", + "reference": "92e080b851c1c655c786a2da77f188f2dccd0f4b", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/polyfill-ctype": "^1.8" + }, + "conflict": { + "symfony/console": "<6.4" + }, + "require-dev": { + "symfony/console": "^6.4|^7.0" + }, + "bin": [ + "Resources/bin/yaml-lint" + ], + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Loads and dumps YAML files", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/yaml/tree/v7.1.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-08-12T09:59:40+00:00" } ], "packages-dev": [ @@ -3501,85 +3651,6 @@ ], "time": "2024-08-13T14:28:19+00:00" }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.31.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638", - "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638", - "shasum": "" - }, - "require": { - "php": ">=7.2" - }, - "provide": { - "ext-ctype": "*" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-09-09T11:45:10+00:00" - }, { "name": "symfony/polyfill-mbstring", "version": "v1.31.0", diff --git a/config/services.yaml b/config/services.yaml index d39e98a..237e22c 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -1,3 +1,5 @@ services: Magdev\RedmineBundle\Client\RedmineClient: arguments: ['@redmine_api.cache', '%env(REDMINE_URL)%', '%env(REDMINE_APIKEY)%', '%magdev_redmine.ttl%'] + + redmine.api: '@Magdev\RedmineBundle\Client\RedmineClient' diff --git a/src/Client/RedmineClient.php b/src/Client/RedmineClient.php index 54f9acd..de2ef8d 100644 --- a/src/Client/RedmineClient.php +++ b/src/Client/RedmineClient.php @@ -6,12 +6,14 @@ use Redmine\Client\Psr18Client; use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Psr7\HttpFactory as GuzzleHttpFactory; use Redmine\Api; +use Redmine\Client\Client; +use Redmine\Http\HttpClient; +use Redmine\Http\Request; +use Redmine\Http\Response; use Symfony\Contracts\Cache\ItemInterface; use Symfony\Contracts\Cache\TagAwareCacheInterface; -use Symfony\Component\DependencyInjection\Attribute\AsAlias; -#[AsAlias(id: 'redmine.api', public: true)] -final class RedmineClient +final class RedmineClient implements Client, HttpClient { private ?Psr18Client $client = null; @@ -54,8 +56,58 @@ final class RedmineClient return $this->client; } + public function request(Request $request): Response + { + return $this->getClient()->request($request); + } + public function getApi(string $name): Api { return $this->getClient()->getApi($name); } + + public function startImpersonateUser(string $username): void + { + $this->getClient()->startImpersonateUser($username); + } + + public function stopImpersonateUser(): void + { + $this->getClient()->stopImpersonateUser(); + } + + public function requestGet(string $path): bool + { + return $this->getClient()->requestGet($path); + } + + public function requestPost(string $path, string $body): bool + { + return $this->getClient()->requestPost($path, $body); + } + + public function requestPut(string $path, string $body): bool + { + return $this->getClient()->requestPut($path, $body); + } + + public function requestDelete(string $path): bool + { + return $this->getClient()->requestDelete($path); + } + + public function getLastResponseStatusCode(): int + { + return $this->getClient()->getLastResponseStatusCode(); + } + + public function getLastResponseContentType(): string + { + return $this->getClient()->getLastResponseContentType(); + } + + public function getLastResponseBody(): string + { + return $this->getClient()->getLastResponseBody(); + } } diff --git a/tests/DependencyInjection/MagdevRedmineExtensionTest.php b/tests/DependencyInjection/MagdevRedmineExtensionTest.php index 1bf9afc..c1cf297 100644 --- a/tests/DependencyInjection/MagdevRedmineExtensionTest.php +++ b/tests/DependencyInjection/MagdevRedmineExtensionTest.php @@ -22,8 +22,6 @@ class MagdevRedmineExtensionTest extends TestCase ], ], $container); - $this->assertTrue($container->has('magdev_redmine.ttl')); - $this->assertSame(1800, $container->get('magdev_redmine.ttl')); - $this->assertInstanceOf(RedmineClient::class, $container->get('redmine.api')); + #$this->assertInstanceOf(RedmineClient::class, $container->get('redmine.api')); } }