Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/bundle/DependencyInjection/EzPlatformAdminUiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Yaml\Yaml;

class EzPlatformAdminUiExtension extends Extension implements PrependExtensionInterface
Expand Down Expand Up @@ -39,6 +40,8 @@ public function load(array $configs, ContainerBuilder $container)
if ($environment === 'behat') {
$loader->load('services/feature_contexts.yaml');
}

$this->registerDebugConfiguration($container, $loader);
}

/**
Expand Down Expand Up @@ -143,4 +146,13 @@ private function prependJMSTranslation(ContainerBuilder $container): void
],
]);
}

private function registerDebugConfiguration(ContainerBuilder $container, YamlFileLoader $loader): void
{
$debug = $container->getParameter('kernel.debug');

if ($debug && class_exists(Stopwatch::class)) {
$loader->load('services.debug.yaml');
}
}
}
7 changes: 7 additions & 0 deletions src/bundle/Resources/config/services.debug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
EzSystems\EzPlatformAdminUi\Component\Renderer\TraceableRenderer:
decorates: EzSystems\EzPlatformAdminUi\Component\Renderer\RendererInterface
public: false
arguments:
- '@.inner'
- '@debug.stopwatch'
2 changes: 2 additions & 0 deletions src/bundle/Resources/config/services/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ services:

EzSystems\EzPlatformAdminUi\Component\Renderer\DefaultRenderer:
public: false
calls:
- setRenderer: ['@EzSystems\EzPlatformAdminUi\Component\Renderer\RendererInterface']

EzSystems\EzPlatformAdminUi\Component\Renderer\RendererInterface: '@EzSystems\EzPlatformAdminUi\Component\Renderer\DefaultRenderer'
5 changes: 0 additions & 5 deletions src/bundle/Templating/Twig/ComponentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,17 @@

namespace EzSystems\EzPlatformAdminUiBundle\Templating\Twig;

use EzSystems\EzPlatformAdminUi\Component\Registry as ComponentRegistry;
use EzSystems\EzPlatformAdminUi\Component\Renderer\RendererInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class ComponentExtension extends AbstractExtension
{
protected $registry;

protected $renderer;

public function __construct(
ComponentRegistry $registry,
RendererInterface $renderer
) {
$this->registry = $registry;
$this->renderer = $renderer;
}

Expand Down
12 changes: 11 additions & 1 deletion src/lib/Component/Renderer/DefaultRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,26 @@

class DefaultRenderer implements RendererInterface
{
/** @var \EzSystems\EzPlatformAdminUi\Component\Registry */
protected $registry;

/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */
protected $eventDispatcher;

/** @var \EzSystems\EzPlatformAdminUi\Component\Renderer\RendererInterface */
protected $renderer;

public function __construct(Registry $registry, EventDispatcherInterface $eventDispatcher)
{
$this->registry = $registry;
$this->eventDispatcher = $eventDispatcher;
}

public function setRenderer(RendererInterface $renderer): void
{
$this->renderer = $renderer;
}

public function renderGroup(string $groupName, array $parameters = []): array
{
$this->eventDispatcher->dispatch(new RenderGroupEvent(
Expand All @@ -38,7 +48,7 @@ public function renderGroup(string $groupName, array $parameters = []): array

$rendered = [];
foreach ($components as $id => $component) {
$rendered[] = $this->renderSingle($id, $groupName, $parameters);
$rendered[] = $this->renderer->renderSingle($id, $groupName, $parameters);
}

return $rendered;
Expand Down
56 changes: 56 additions & 0 deletions src/lib/Component/Renderer/TraceableRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformAdminUi\Component\Renderer;

use Symfony\Component\Stopwatch\Stopwatch;

final class TraceableRenderer implements RendererInterface
{
/** @var \EzSystems\EzPlatformAdminUi\Component\Renderer\RendererInterface */
private $decorated;

/** @var \Symfony\Component\Stopwatch\Stopwatch */
private $stopwatch;

public function __construct(RendererInterface $decorated, Stopwatch $stopwatch)
{
$this->decorated = $decorated;
$this->stopwatch = $stopwatch;
}

public function renderGroup(string $groupName, array $parameters = []): array
{
$event = $this->stopwatch->start(sprintf('%s', $groupName), 'admin-ui');

try {
$rendered = $this->decorated->renderGroup($groupName, $parameters);
} finally {
if ($event->isStarted()) {
$event->stop();
}
}

return $rendered;
}

public function renderSingle(string $name, $groupName, array $parameters = []): string
{
$event = $this->stopwatch->start(sprintf('%s - %s', $groupName, $name), 'admin-ui');

try {
$rendered = $this->decorated->renderSingle($name, $groupName, $parameters);
} finally {
if ($event->isStarted()) {
$event->stop();
}
}

return $rendered;
}
}