[WebProfilerBundle] Use CPP

This commit is contained in:
Simon André
2024-04-13 06:42:55 +02:00
parent 183346e95c
commit 7d907c338e
8 changed files with 54 additions and 80 deletions

View File

@@ -25,13 +25,10 @@ use Symfony\Component\HttpKernel\Profiler\Profiler;
*/
class ExceptionPanelController
{
private HtmlErrorRenderer $errorRenderer;
private ?Profiler $profiler;
public function __construct(HtmlErrorRenderer $errorRenderer, ?Profiler $profiler = null)
{
$this->errorRenderer = $errorRenderer;
$this->profiler = $profiler;
public function __construct(
private HtmlErrorRenderer $errorRenderer,
private ?Profiler $profiler = null,
) {
}
/**

View File

@@ -34,21 +34,15 @@ use Twig\Environment;
class ProfilerController
{
private TemplateManager $templateManager;
private UrlGeneratorInterface $generator;
private ?Profiler $profiler;
private Environment $twig;
private array $templates;
private ?ContentSecurityPolicyHandler $cspHandler;
private ?string $baseDir;
public function __construct(UrlGeneratorInterface $generator, ?Profiler $profiler, Environment $twig, array $templates, ?ContentSecurityPolicyHandler $cspHandler = null, ?string $baseDir = null)
{
$this->generator = $generator;
$this->profiler = $profiler;
$this->twig = $twig;
$this->templates = $templates;
$this->cspHandler = $cspHandler;
$this->baseDir = $baseDir;
public function __construct(
private UrlGeneratorInterface $generator,
private ?Profiler $profiler,
private Environment $twig,
private array $templates,
private ?ContentSecurityPolicyHandler $cspHandler = null,
private ?string $baseDir = null,
) {
}
/**

View File

@@ -30,23 +30,19 @@ use Twig\Environment;
*/
class RouterController
{
private ?Profiler $profiler;
private Environment $twig;
private ?UrlMatcherInterface $matcher;
private ?RouteCollection $routes;
/**
* @var ExpressionFunctionProviderInterface[]
* @param ExpressionFunctionProviderInterface[] $expressionLanguageProviders
*/
private iterable $expressionLanguageProviders;
public function __construct(?Profiler $profiler, Environment $twig, ?UrlMatcherInterface $matcher = null, ?RouteCollection $routes = null, iterable $expressionLanguageProviders = [])
{
$this->profiler = $profiler;
$this->twig = $twig;
$this->matcher = $matcher;
$this->routes = (null === $routes && $matcher instanceof RouterInterface) ? $matcher->getRouteCollection() : $routes;
$this->expressionLanguageProviders = $expressionLanguageProviders;
public function __construct(
private ?Profiler $profiler,
private Environment $twig,
private ?UrlMatcherInterface $matcher = null,
private ?RouteCollection $routes = null,
private iterable $expressionLanguageProviders = [],
) {
if ($this->matcher instanceof RouterInterface) {
$this->routes ??= $this->matcher->getRouteCollection();
}
}
/**

View File

@@ -23,12 +23,11 @@ use Symfony\Component\HttpFoundation\Response;
*/
class ContentSecurityPolicyHandler
{
private NonceGenerator $nonceGenerator;
private bool $cspDisabled = false;
public function __construct(NonceGenerator $nonceGenerator)
{
$this->nonceGenerator = $nonceGenerator;
public function __construct(
private NonceGenerator $nonceGenerator,
) {
}
/**
@@ -124,10 +123,10 @@ class ContentSecurityPolicyHandler
$headers = $this->getCspHeaders($response);
$types = [
'script-src' => 'csp_script_nonce',
'script-src-elem' => 'csp_script_nonce',
'style-src' => 'csp_style_nonce',
'style-src-elem' => 'csp_style_nonce',
'script-src' => 'csp_script_nonce',
'script-src-elem' => 'csp_script_nonce',
'style-src' => 'csp_style_nonce',
'style-src-elem' => 'csp_style_nonce',
];
foreach ($headers as $header => $directives) {

View File

@@ -40,23 +40,15 @@ class WebDebugToolbarListener implements EventSubscriberInterface
public const DISABLED = 1;
public const ENABLED = 2;
private Environment $twig;
private ?UrlGeneratorInterface $urlGenerator;
private bool $interceptRedirects;
private int $mode;
private string $excludedAjaxPaths;
private ?ContentSecurityPolicyHandler $cspHandler;
private ?DumpDataCollector $dumpDataCollector;
public function __construct(Environment $twig, bool $interceptRedirects = false, int $mode = self::ENABLED, ?UrlGeneratorInterface $urlGenerator = null, string $excludedAjaxPaths = '^/bundles|^/_wdt', ?ContentSecurityPolicyHandler $cspHandler = null, ?DumpDataCollector $dumpDataCollector = null)
{
$this->twig = $twig;
$this->urlGenerator = $urlGenerator;
$this->interceptRedirects = $interceptRedirects;
$this->mode = $mode;
$this->excludedAjaxPaths = $excludedAjaxPaths;
$this->cspHandler = $cspHandler;
$this->dumpDataCollector = $dumpDataCollector;
public function __construct(
private Environment $twig,
private bool $interceptRedirects = false,
private int $mode = self::ENABLED,
private ?UrlGeneratorInterface $urlGenerator = null,
private string $excludedAjaxPaths = '^/bundles|^/_wdt',
private ?ContentSecurityPolicyHandler $cspHandler = null,
private ?DumpDataCollector $dumpDataCollector = null,
) {
}
public function isEnabled(): bool

View File

@@ -26,14 +26,14 @@ use Twig\TwigFilter;
final class CodeExtension extends AbstractExtension
{
private string|FileLinkFormatter|array|false $fileLinkFormat;
private string $charset;
private string $projectDir;
public function __construct(string|FileLinkFormatter $fileLinkFormat, string $projectDir, string $charset)
{
public function __construct(
string|FileLinkFormatter $fileLinkFormat,
private string $projectDir,
private string $charset,
) {
$this->fileLinkFormat = $fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
$this->projectDir = str_replace('\\', '/', $projectDir).'/';
$this->charset = $charset;
}
public function getFilters(): array

View File

@@ -24,15 +24,11 @@ use Twig\Environment;
*/
class TemplateManager
{
protected Environment $twig;
protected array $templates;
protected Profiler $profiler;
public function __construct(Profiler $profiler, Environment $twig, array $templates)
{
$this->profiler = $profiler;
$this->twig = $twig;
$this->templates = $templates;
public function __construct(
protected Profiler $profiler,
protected Environment $twig,
protected array $templates,
) {
}
/**

View File

@@ -179,11 +179,11 @@ class WebProfilerExtensionTest extends TestCase
public static function getInterceptRedirectsToolbarConfig()
{
return [
[
'toolbarEnabled' => false,
'interceptRedirects' => true,
'listenerInjected' => true,
'listenerEnabled' => false,
[
'toolbarEnabled' => false,
'interceptRedirects' => true,
'listenerInjected' => true,
'listenerEnabled' => false,
],
[
'toolbarEnabled' => false,