2023-04-25 15:09:11 +02:00
|
|
|
<?php declare(strict_types=1);
|
2023-04-25 15:00:03 +02:00
|
|
|
|
|
|
|
|
namespace Magdev\RedmineBundle\DependencyInjection;
|
|
|
|
|
|
2024-09-13 00:43:53 +02:00
|
|
|
use Magdev\RedmineBundle\Client\RedmineClient;
|
2023-04-25 15:00:03 +02:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Marco Grätsch <magdev3.0@gmail.com>
|
|
|
|
|
*/
|
|
|
|
|
final class MagdevRedmineExtension extends Extension
|
|
|
|
|
{
|
|
|
|
|
public function load(array $configs, ContainerBuilder $container)
|
|
|
|
|
{
|
|
|
|
|
$config = $this->processConfiguration(new Configuration(), $configs);
|
|
|
|
|
|
2023-04-25 17:46:49 +02:00
|
|
|
if (!isset($config['default_connection'])) {
|
2023-04-25 15:00:03 +02:00
|
|
|
$config['default_connection'] = array_key_first($config['connections']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($config['connections'] as $name => $connection) {
|
2023-04-25 17:46:49 +02:00
|
|
|
$id = sprintf('magdev.redmine.%s', $name);
|
2024-09-13 01:04:38 +02:00
|
|
|
|
2024-09-13 00:43:53 +02:00
|
|
|
$container->register($id, RedmineClient::class)
|
2024-09-13 02:09:15 +02:00
|
|
|
->addMethodCall('setUrl', [$connection['url']]);
|
|
|
|
|
->addMethodCall('setApiKey', [$connection['apikey']]);
|
2024-09-13 00:43:53 +02:00
|
|
|
$container->registerAliasForArgument($id, RedmineClient::class, "{$name}Client");
|
2023-04-25 15:00:03 +02:00
|
|
|
|
|
|
|
|
if ($name === $config['default_connection']) {
|
2024-09-13 00:43:53 +02:00
|
|
|
$container->setAlias(RedmineClient::class, $id);
|
2023-04-25 15:00:03 +02:00
|
|
|
}
|
2023-04-25 17:46:49 +02:00
|
|
|
}
|
2023-04-25 15:00:03 +02:00
|
|
|
}
|
|
|
|
|
}
|