diff --git a/src/Bundle/Resources/config/services.php b/src/Bundle/Resources/config/services.php index c50c6fb..f44acae 100644 --- a/src/Bundle/Resources/config/services.php +++ b/src/Bundle/Resources/config/services.php @@ -8,8 +8,23 @@ use PrismaMedia\Metrics\Bundle\PrismaMediaMetricsBundle; use PrismaMedia\Metrics\MetricAggregator; use PrismaMedia\Metrics\MetricRenderer; +use Symfony\Component\DependencyInjection\Exception\LogicException; +use function function_exists; +use function sprintf; return function (ContainerConfigurator $configurator) { + + $functionRef = sprintf('%s\ref', __NAMESPACE__); + $functionService = sprintf('%s\service', __NAMESPACE__); + + $function = function_exists($functionService) ? $functionService : $functionRef; + + if (!function_exists($function)) { + throw new LogicException( + sprintf('Function "%s" is missing and or not supported by the used Symfony version.', $function) + ); + } + $configurator->services() ->set(MetricAggregator::class) ->args([tagged_iterator(PrismaMediaMetricsBundle::TAG_METRIC)]) @@ -17,7 +32,7 @@ ->set(MetricRenderer::class) ->set(MetricsController::class) - ->args([service(MetricAggregator::class), service(MetricRenderer::class)]) + ->args([$function(MetricAggregator::class), $function(MetricRenderer::class)]) ->tag('controller.service_arguments') ; }; diff --git a/src/MetricRenderer.php b/src/MetricRenderer.php index 93bd2e7..704ba27 100644 --- a/src/MetricRenderer.php +++ b/src/MetricRenderer.php @@ -17,6 +17,6 @@ public function render(Metric $metric): string }, array_keys($metric->getLabels()), $metric->getLabels()))); } - return sprintf("%s%s %s\n", $metric->getName(), $labels, $metric->getValue()); + return sprintf("%s%s %s \n", $metric->getName(), $labels, $metric->getValue()); } } diff --git a/tests/Bundle/FunctionalTest.php b/tests/Bundle/FunctionalTest.php index cff4755..79d8542 100644 --- a/tests/Bundle/FunctionalTest.php +++ b/tests/Bundle/FunctionalTest.php @@ -22,9 +22,9 @@ public function testEndpointMetrics(): void $this->assertResponseIsSuccessful(); $expected = - "article_total{brand=\"Capital\"} 42\n". - "article_total{brand=\"Femme Actuelle\"} 876\n". - "article_total{brand=\"Télé-Loisirs\"} 381\n"; + "article_total{brand=\"Capital\"} 42 \n". + "article_total{brand=\"Femme Actuelle\"} 876 \n". + "article_total{brand=\"Télé-Loisirs\"} 381 \n"; $this->assertSame($expected, $content); $this->assertSame(200, $client->getResponse()->getStatusCode());