Skip to content

Commit

Permalink
fix: Fixed Roadiz data collector
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Jun 1, 2024
1 parent 5ccb7ca commit 1c65a0c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 41 deletions.
10 changes: 0 additions & 10 deletions lib/RoadizCoreBundle/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,6 @@ services:
decorates: 'api_platform.serializer.normalizer.item'
decoration_priority: 21

RZ\Roadiz\CoreBundle\DataCollector\RequestDataCollector:
autoconfigure: false
arguments: [ '%roadiz_core.cms_version%', '%roadiz_core.cms_version_prefix%']
tags:
- name: data_collector
template: '@RoadizCore/DataCollector/request.html.twig'
# must match the value returned by the getName() method
id: 'roadiz.data_collector.request'
priority: 400

# Document
RZ\Roadiz\CoreBundle\Serializer\Normalizer\DocumentNormalizer:
# By default, .inner is passed as argument
Expand Down
48 changes: 19 additions & 29 deletions lib/RoadizCoreBundle/src/DataCollector/RequestDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,41 @@

namespace RZ\Roadiz\CoreBundle\DataCollector;

use PackageVersions\Versions;
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

#[AutoconfigureTag('data_collector', [
'template' => '@RoadizCore/DataCollector/request.html.twig',
# must match the value returned by the getName() method
'id' => 'roadiz.data_collector.request',
'priority' => 400,
])]
final class RequestDataCollector extends AbstractDataCollector
{
private ?string $cmsVersion = null;
private ?string $cmsVersionPrefix = null;

public function __construct(string $cmsVersion, string $cmsVersionPrefix)
{
$this->cmsVersion = $cmsVersion;
$this->cmsVersionPrefix = $cmsVersionPrefix;
public function __construct(
#[Autowire('%roadiz_core.cms_version%')]
private readonly string $cmsVersion,
#[Autowire('%roadiz_core.cms_version_prefix%')]
private readonly string $cmsVersionPrefix
) {
}

/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Throwable $exception = null): void
{
$this->data = [];
}

public function getVersion(): ?string
{
$fallback = implode(' - ', array_filter([$this->cmsVersionPrefix, $this->cmsVersion]));
if (!class_exists(Versions::class)) {
return $fallback;
}

$version = Versions::getVersion('roadiz/core-bundle');
preg_match('/^v(.*?)@/', $version, $output);

return $output[1] ?? strtok($version, '@') ?: $fallback;
$this->data = [
'version' => implode(' - ', [$this->cmsVersionPrefix, $this->cmsVersion])
];
}

public static function getTemplate(): ?string
public function getVersion(): string
{
return '@RoadizCore/DataCollector/request.html.twig';
return $this->data['version'] ?? '';
}

/**
Expand All @@ -53,9 +48,4 @@ public function getName(): string
{
return 'roadiz.data_collector.request';
}

public function reset(): void
{
$this->data = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
{% set text %}
<div class="sf-toolbar-info-piece">
<b>Roadiz CMS</b>
{% if collector.version %}
<span>{{ collector.version }}</span>
{% endif %}
</div>
{% endset %}

Expand Down

0 comments on commit 1c65a0c

Please sign in to comment.