Skip to content

Commit

Permalink
minor #54585 [WebProfilerBundle] Use CPP (smnandre)
Browse files Browse the repository at this point in the history
This PR was merged into the 7.1 branch.

Discussion
----------

[WebProfilerBundle] Use CPP

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #...
| License       | MIT

Commits
-------

a0ad9a7 [WebProfilerBundle] Use CPP
  • Loading branch information
fabpot committed Apr 14, 2024
2 parents cfd9ad0 + a0ad9a7 commit 47d1ecb
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@
*/
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,
) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,15 @@
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,
) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,19 @@
*/
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();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
*/
class ContentSecurityPolicyHandler
{
private NonceGenerator $nonceGenerator;
private bool $cspDisabled = false;

public function __construct(NonceGenerator $nonceGenerator)
{
$this->nonceGenerator = $nonceGenerator;
public function __construct(
private NonceGenerator $nonceGenerator,
) {
}

/**
Expand Down Expand Up @@ -124,10 +123,10 @@ private function updateCspHeaders(Response $response, array $nonces = []): array
$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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Bundle/WebProfilerBundle/Profiler/CodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@
*/
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,
) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ public function testToolbarConfigUsingInterceptRedirects(
public static function getInterceptRedirectsToolbarConfig()
{
return [
[
'toolbarEnabled' => false,
'interceptRedirects' => true,
'listenerInjected' => true,
'listenerEnabled' => false,
[
'toolbarEnabled' => false,
'interceptRedirects' => true,
'listenerInjected' => true,
'listenerEnabled' => false,
],
[
'toolbarEnabled' => false,
Expand Down

0 comments on commit 47d1ecb

Please sign in to comment.