-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Roadiz custom data-collector for web-profiler
- Loading branch information
1 parent
84a611b
commit d0e01fa
Showing
4 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
lib/RoadizCoreBundle/src/DataCollector/RequestDataCollector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\DataCollector; | ||
|
||
use PackageVersions\Versions; | ||
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
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; | ||
} | ||
|
||
/** | ||
* {@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; | ||
} | ||
|
||
public static function getTemplate(): ?string | ||
{ | ||
return '@RoadizCore/DataCollector/request.html.twig'; | ||
} | ||
|
||
public function getMethod() | ||
{ | ||
return $this->data['method']; | ||
} | ||
|
||
public function getAcceptableContentTypes() | ||
{ | ||
return $this->data['acceptable_content_types']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'roadiz.data_collector.request'; | ||
} | ||
|
||
public function reset(): void | ||
{ | ||
$this->data = []; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
lib/RoadizCoreBundle/templates/DataCollector/request.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% extends '@WebProfiler/Profiler/layout.html.twig' %} | ||
|
||
{% block toolbar %} | ||
{% set icon %} | ||
{{ include('@RoadizCore/DataCollector/roadiz-icon.svg') }} | ||
{% endset %} | ||
|
||
{% set text %} | ||
<div class="sf-toolbar-info-piece"> | ||
<b>Roadiz CMS</b> | ||
{% if collector.version %} | ||
<span>{{ collector.version }}</span> | ||
{% endif %} | ||
</div> | ||
{% endset %} | ||
|
||
{{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { 'link': false }) }} | ||
{% endblock %} |
23 changes: 23 additions & 0 deletions
23
lib/RoadizCoreBundle/templates/DataCollector/roadiz-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.