diff --git a/CHANGELOG.md b/CHANGELOG.md
index 935a1e20322..4c1baa61c29 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## 2.6.0
+* Display the Api-Platform's version in the debug-bar
* MongoDB: Possibility to add execute options (aggregate command fields) for a resource, like `allowDiskUse` (#3144)
## 2.5.0
diff --git a/composer.json b/composer.json
index 8c55e696b37..e3a75202cd2 100644
--- a/composer.json
+++ b/composer.json
@@ -97,6 +97,7 @@
"elasticsearch/elasticsearch": "To support Elasticsearch.",
"friendsofsymfony/user-bundle": "To use the FOSUserBundle bridge.",
"guzzlehttp/guzzle": "To use the HTTP cache invalidation system.",
+ "ocramius/package-versions": "To display the Api-Platform's version in the debug bar.",
"phpdocumentor/reflection-docblock": "To support extracting metadata from PHPDoc.",
"psr/cache-implementation": "To use metadata caching.",
"ramsey/uuid": "To support Ramsey's UUID identifiers.",
diff --git a/src/Bridge/Symfony/Bundle/DataCollector/RequestDataCollector.php b/src/Bridge/Symfony/Bundle/DataCollector/RequestDataCollector.php
index 3f407c8d507..756b03fddc5 100644
--- a/src/Bridge/Symfony/Bundle/DataCollector/RequestDataCollector.php
+++ b/src/Bridge/Symfony/Bundle/DataCollector/RequestDataCollector.php
@@ -23,6 +23,7 @@
use ApiPlatform\Core\DataProvider\SubresourceDataProviderInterface;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Util\RequestAttributesExtractor;
+use PackageVersions\Versions;
use Psr\Container\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -158,6 +159,18 @@ public function getDataPersisters(): array
return $this->data['dataPersisters'] ?? ['responses' => []];
}
+ public function getVersion(): ?string
+ {
+ if (!class_exists(Versions::class)) {
+ return null;
+ }
+
+ $version = Versions::getVersion('api-platform/core');
+ preg_match('/^v(.*?)@/', $version, $output);
+
+ return $output[1] ?? strtok($version, '@');
+ }
+
/**
* {@inheritdoc}
*/
diff --git a/src/Bridge/Symfony/Bundle/Resources/views/DataCollector/request.html.twig b/src/Bridge/Symfony/Bundle/Resources/views/DataCollector/request.html.twig
index 79d78a25bf2..56e22891e32 100644
--- a/src/Bridge/Symfony/Bundle/Resources/views/DataCollector/request.html.twig
+++ b/src/Bridge/Symfony/Bundle/Resources/views/DataCollector/request.html.twig
@@ -80,7 +80,7 @@
{% set icon %}
{% set status_color = collector.counters.ignored_filters|default(false) ? 'yellow' : 'default' %}
{{ include('@ApiPlatform/DataCollector/api-platform-icon.svg') }}
-
+ {{ collector.version }}
{% endset %}
{% set text %}