You've already forked redmine-bundle
define services in services.yaml instead of Extension class
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user