You've already forked redmine-bundle
switch to enable/disable cache, added dedicated RedmineClientInterface
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
services:
|
||||
Magdev\RedmineBundle\Client\RedmineClient:
|
||||
arguments: ['@redmine_api.cache', '%magdev_redmine.url%', '%magdev_redmine.apiKey%', '%magdev_redmine.cache.ttl%']
|
||||
arguments:
|
||||
- '@redmine_api.cache'
|
||||
- '%magdev_redmine.url%'
|
||||
- '%magdev_redmine.apiKey%'
|
||||
- '%magdev_redmine.cache.ttl%'
|
||||
- '%magdev_redmine.cache.enabled%'
|
||||
|
||||
redmine.api: '@Magdev\RedmineBundle\Client\RedmineClient'
|
||||
|
||||
@@ -6,14 +6,13 @@ 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;
|
||||
|
||||
final class RedmineClient implements Client, HttpClient
|
||||
final class RedmineClient implements RedmineClientInterface, HttpClient
|
||||
{
|
||||
private ?Psr18Client $client = null;
|
||||
|
||||
@@ -21,11 +20,21 @@ final class RedmineClient implements Client, HttpClient
|
||||
private TagAwareCacheInterface $cache,
|
||||
private string $url,
|
||||
private string $apiKey,
|
||||
private int $ttl
|
||||
private int $ttl,
|
||||
private bool $cacheEnabled
|
||||
) {}
|
||||
|
||||
public function call(string $api, string $method, array $arguments = []): mixed
|
||||
{
|
||||
if (!$this->cacheEnabled) {
|
||||
$client = $this->getClient()->getApi($api);
|
||||
|
||||
return \call_user_func_array(
|
||||
[$client, $method],
|
||||
$arguments
|
||||
);
|
||||
}
|
||||
|
||||
$cacheKey = sprintf('%s_%s_%s', $api, $method, sha1(serialize($arguments)));
|
||||
|
||||
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($api, $method, $arguments): array {
|
||||
@@ -33,7 +42,10 @@ final class RedmineClient implements Client, HttpClient
|
||||
$item->tag([$api, $method]);
|
||||
|
||||
$client = $this->getClient()->getApi($api);
|
||||
$value = \call_user_func_array([$client, $method], $arguments);
|
||||
$value = \call_user_func_array(
|
||||
[$client, $method],
|
||||
$arguments
|
||||
);
|
||||
|
||||
return $value;
|
||||
});
|
||||
|
||||
11
src/Client/RedmineClientInterface.php
Normal file
11
src/Client/RedmineClientInterface.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Magdev\RedmineBundle\Client;
|
||||
|
||||
use Redmine\Client\Client;
|
||||
|
||||
interface RedmineClientInterface extends Client
|
||||
{
|
||||
public function call(string $api, string $method, array $arguments = []): mixed;
|
||||
public function getClient(): ?Psr18Client;
|
||||
}
|
||||
@@ -17,6 +17,7 @@ final class MagdevRedmineExtension extends Extension
|
||||
{
|
||||
$config = $this->processConfiguration(new Configuration(), $configs);
|
||||
|
||||
$container->setParameter('magdev_redmine.cache.enabled', $config['cache']['enabled']);
|
||||
$container->setParameter('magdev_redmine.cache.ttl', $config['cache']['ttl']);
|
||||
$container->setParameter('magdev_redmine.url', $config['url']);
|
||||
$container->setParameter('magdev_redmine.apiKey', $config['apiKey']);
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Magdev\RedmineBundle\Enum;
|
||||
|
||||
enum ApiName
|
||||
{
|
||||
case attachment;
|
||||
case group;
|
||||
case custom_fields;
|
||||
case issue;
|
||||
case issue_category;
|
||||
case issue_priority;
|
||||
case issue_relation;
|
||||
case issue_status;
|
||||
case membership;
|
||||
case news;
|
||||
case project;
|
||||
case query;
|
||||
case role;
|
||||
case time_entry;
|
||||
case time_entry_activity;
|
||||
case tracker;
|
||||
case user;
|
||||
case version;
|
||||
case wiki;
|
||||
case search;
|
||||
}
|
||||
Reference in New Issue
Block a user