Skip to content

Commit

Permalink
Add Api-Platform's version in debug bar
Browse files Browse the repository at this point in the history
  • Loading branch information
dFayet committed Nov 3, 2019
1 parent 480c077 commit 0ac0ba4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -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.",
Expand Down
13 changes: 13 additions & 0 deletions src/Bridge/Symfony/Bundle/DataCollector/RequestDataCollector.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
*/
Expand Down
Expand Up @@ -80,7 +80,7 @@
{% set icon %}
{% set status_color = collector.counters.ignored_filters|default(false) ? 'yellow' : 'default' %}
{{ include('@ApiPlatform/DataCollector/api-platform-icon.svg') }}
<span class="sf-toolbar-value"></span>
<span class="sf-toolbar-value">{{ collector.version }}</span>
{% endset %}

{% set text %}
Expand Down

0 comments on commit 0ac0ba4

Please sign in to comment.