define services in services.yaml instead of Extension class

This commit is contained in:
2024-09-13 03:02:22 +02:00
parent 0eaddfd7e1
commit a859a4a3ec
2 changed files with 6 additions and 18 deletions

View File

@@ -5,6 +5,7 @@ namespace Magdev\RedmineBundle\Client;
use Redmine\Client\Psr18Client;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory as GuzzleHttpFactory;
use Redmine\Api;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;
@@ -49,4 +50,9 @@ final class RedmineClient
}
return $this->client;
}
public function getApi(string $name): Api
{
return $this->getClient()->getApi($name);
}
}

View File

@@ -17,24 +17,6 @@ final class MagdevRedmineExtension extends Extension
{
$config = $this->processConfiguration(new Configuration(), $configs);
if (!isset($config['default_connection'])) {
$config['default_connection'] = array_key_first($config['connections']);
}
foreach ($config['connections'] as $name => $connection) {
$id = sprintf('magdev.redmine.%s', $name);
$container->register($id, RedmineClient::class)
->addMethodCall('setUrl', [$connection['url']])
->addMethodCall('setApiKey', [$connection['apikey']]);
$container->registerAliasForArgument($id, RedmineClient::class, "{$name}Client");
if ($name === $config['default_connection']) {
$container->setAlias(RedmineClient::class, $id);
}
}
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');
}