Skip to content

[SecurityBundle] Improve profiler’s data #57425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,78 +27,72 @@
final class TraceableFirewallListener extends FirewallListener implements ResetInterface
{
private array $wrappedListeners = [];
private array $authenticatorsInfo = [];
private ?TraceableAuthenticatorManagerListener $authenticatorManagerListener = null;

public function getWrappedListeners(): array
{
return $this->wrappedListeners;
return array_map(
static fn (WrappedListener|WrappedLazyListener $listener) => $listener->getInfo(),
$this->wrappedListeners
);
}

public function getAuthenticatorsInfo(): array
{
return $this->authenticatorsInfo;
return $this->authenticatorManagerListener?->getAuthenticatorsInfo() ?? [];
}

public function reset(): void
{
$this->wrappedListeners = [];
$this->authenticatorsInfo = [];
$this->authenticatorManagerListener = null;
}

protected function callListeners(RequestEvent $event, iterable $listeners): void
{
$wrappedListeners = [];
$wrappedLazyListeners = [];
$authenticatorManagerListener = null;

$requestListeners = [];
foreach ($listeners as $listener) {
if ($listener instanceof LazyFirewallContext) {
\Closure::bind(function () use (&$wrappedLazyListeners, &$wrappedListeners, &$authenticatorManagerListener) {
$listeners = [];
$contextWrappedListeners = [];
$contextAuthenticatorManagerListener = null;

\Closure::bind(function () use (&$contextWrappedListeners, &$contextAuthenticatorManagerListener) {
foreach ($this->listeners as $listener) {
if (!$authenticatorManagerListener && $listener instanceof TraceableAuthenticatorManagerListener) {
$authenticatorManagerListener = $listener;
}
if ($listener instanceof FirewallListenerInterface) {
$listener = new WrappedLazyListener($listener);
$listeners[] = $listener;
$wrappedLazyListeners[] = $listener;
} else {
$listeners[] = function (RequestEvent $event) use ($listener, &$wrappedListeners) {
$wrappedListener = new WrappedListener($listener);
$wrappedListener($event);
$wrappedListeners[] = $wrappedListener->getInfo();
};
if ($listener instanceof TraceableAuthenticatorManagerListener) {
$contextAuthenticatorManagerListener ??= $listener;
}
$contextWrappedListeners[] = $listener instanceof FirewallListenerInterface
? new WrappedLazyListener($listener)
: new WrappedListener($listener)
;
}
$this->listeners = $listeners;
$this->listeners = $contextWrappedListeners;
}, $listener, FirewallContext::class)();

$listener($event);
$this->authenticatorManagerListener ??= $contextAuthenticatorManagerListener;
$this->wrappedListeners = array_merge($this->wrappedListeners, $contextWrappedListeners);

$requestListeners[] = $listener;
} else {
$wrappedListener = $listener instanceof FirewallListenerInterface ? new WrappedLazyListener($listener) : new WrappedListener($listener);
$wrappedListener($event);
$wrappedListeners[] = $wrappedListener->getInfo();
if (!$authenticatorManagerListener && $listener instanceof TraceableAuthenticatorManagerListener) {
$authenticatorManagerListener = $listener;
if ($listener instanceof TraceableAuthenticatorManagerListener) {
$this->authenticatorManagerListener ??= $listener;
}
}
$wrappedListener = $listener instanceof FirewallListenerInterface
? new WrappedLazyListener($listener)
: new WrappedListener($listener)
;
$this->wrappedListeners[] = $wrappedListener;

if ($event->hasResponse()) {
break;
$requestListeners[] = $wrappedListener;
}
}

if ($wrappedLazyListeners) {
foreach ($wrappedLazyListeners as $lazyListener) {
$this->wrappedListeners[] = $lazyListener->getInfo();
}
}

$this->wrappedListeners = array_merge($this->wrappedListeners, $wrappedListeners);
foreach ($requestListeners as $listener) {
$listener($event);

if ($authenticatorManagerListener) {
$this->authenticatorsInfo = $authenticatorManagerListener->getAuthenticatorsInfo();
if ($event->hasResponse()) {
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@

<tr>
<td class="font-normal">{{ profiler_dump(listener.stub) }}</td>
<td class="no-wrap">{{ '%0.2f'|format(listener.time * 1000) }} ms</td>
<td class="no-wrap">{{ listener.time is null ? '(none)' : '%0.2f ms'|format(listener.time * 1000) }}</td>
<td class="font-normal">{{ listener.response ? profiler_dump(listener.response) : '(none)' }}</td>
</tr>

Expand Down Expand Up @@ -362,7 +362,7 @@
<td class="font-normal">{{ profiler_dump(authenticator.stub) }}</td>
<td class="no-wrap">{{ source('@WebProfiler/Icon/' ~ (authenticator.supports ? 'yes' : 'no') ~ '.svg') }}</td>
<td class="no-wrap">{{ authenticator.authenticated is not null ? source('@WebProfiler/Icon/' ~ (authenticator.authenticated ? 'yes' : 'no') ~ '.svg') : '' }}</td>
<td class="no-wrap">{{ '%0.2f'|format(authenticator.duration * 1000) }} ms</td>
<td class="no-wrap">{{ authenticator.duration is null ? '(none)' : '%0.2f ms'|format(authenticator.duration * 1000) }}</td>
<td class="font-normal">{{ authenticator.passport ? profiler_dump(authenticator.passport) : '(none)' }}</td>
<td class="font-normal">
{% for badge in authenticator.badges ?? [] %}
Expand Down
Loading