mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 23:08:46 +02:00
N°9319 increase php min. version to 8.2 (#887)
* Update minimum PHP version to 8.2 * Fix previous wrong resolution of merge conflict
This commit is contained in:
@@ -40,6 +40,9 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
private EventDispatcherInterface $dispatcher;
|
||||
private array $wrappedListeners = [];
|
||||
private array $orphanedEvents = [];
|
||||
private array $dispatchDepth = [];
|
||||
private array $calledListenerInfos = [];
|
||||
private array $calledOriginalListeners = [];
|
||||
private ?RequestStack $requestStack;
|
||||
private string $currentRequestHash = '';
|
||||
|
||||
@@ -155,20 +158,20 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
|
||||
public function getCalledListeners(?Request $request = null): array
|
||||
{
|
||||
if (null === $this->callStack) {
|
||||
if (!$this->calledListenerInfos) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$hash = $request ? spl_object_hash($request) : null;
|
||||
$called = [];
|
||||
foreach ($this->callStack as $listener) {
|
||||
[$eventName, $requestHash] = $this->callStack->getInfo();
|
||||
|
||||
foreach ($this->calledListenerInfos as $requestHash => $infos) {
|
||||
if (null === $hash || $hash === $requestHash) {
|
||||
$called[] = $listener->getInfo($eventName);
|
||||
$called[] = $infos;
|
||||
}
|
||||
}
|
||||
|
||||
return $called;
|
||||
return $called ? array_merge(...$called) : [];
|
||||
}
|
||||
|
||||
public function getNotCalledListeners(?Request $request = null): array
|
||||
@@ -185,16 +188,14 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
$hash = $request ? spl_object_hash($request) : null;
|
||||
$calledListeners = [];
|
||||
|
||||
if (null !== $this->callStack) {
|
||||
foreach ($this->callStack as $calledListener) {
|
||||
[, $requestHash] = $this->callStack->getInfo();
|
||||
|
||||
if (null === $hash || $hash === $requestHash) {
|
||||
$calledListeners[] = $calledListener->getWrappedListener();
|
||||
}
|
||||
foreach ($this->calledOriginalListeners as $requestHash => $eventListeners) {
|
||||
if (null === $hash || $hash === $requestHash) {
|
||||
$calledListeners[] = array_merge(...array_values($eventListeners));
|
||||
}
|
||||
}
|
||||
|
||||
$calledListeners = $calledListeners ? array_merge(...$calledListeners) : [];
|
||||
|
||||
$notCalled = [];
|
||||
|
||||
foreach ($allListeners as $eventName => $listeners) {
|
||||
@@ -234,6 +235,9 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
$this->callStack = null;
|
||||
$this->orphanedEvents = [];
|
||||
$this->currentRequestHash = '';
|
||||
$this->dispatchDepth = [];
|
||||
$this->calledListenerInfos = [];
|
||||
$this->calledOriginalListeners = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,6 +271,8 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
|
||||
private function preProcess(string $eventName): void
|
||||
{
|
||||
$this->dispatchDepth[$eventName] = ($this->dispatchDepth[$eventName] ?? 0) + 1;
|
||||
|
||||
if (!$this->dispatcher->hasListeners($eventName)) {
|
||||
$this->orphanedEvents[$this->currentRequestHash][] = $eventName;
|
||||
|
||||
@@ -285,6 +291,8 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
|
||||
private function postProcess(string $eventName): void
|
||||
{
|
||||
--$this->dispatchDepth[$eventName];
|
||||
|
||||
unset($this->wrappedListeners[$eventName]);
|
||||
$skipped = false;
|
||||
foreach ($this->dispatcher->getListeners($eventName) as $listener) {
|
||||
@@ -302,10 +310,16 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
|
||||
if ($listener->wasCalled()) {
|
||||
$this->logger?->debug('Notified event "{event}" to listener "{listener}".', $context);
|
||||
} else {
|
||||
unset($this->callStack[$listener]);
|
||||
|
||||
$original = $listener->getWrappedListener();
|
||||
if (!\in_array($original, $this->calledOriginalListeners[$this->currentRequestHash][$eventName] ?? [], true)) {
|
||||
$this->calledOriginalListeners[$this->currentRequestHash][$eventName][] = $original;
|
||||
$this->calledListenerInfos[$this->currentRequestHash][] = $listener->getInfo($eventName);
|
||||
}
|
||||
}
|
||||
|
||||
unset($this->callStack[$listener]);
|
||||
|
||||
if (null !== $this->logger && $skipped) {
|
||||
$this->logger->debug('Listener "{listener}" was not called for event "{event}".', $context);
|
||||
}
|
||||
@@ -316,6 +330,28 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
$skipped = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < $this->dispatchDepth[$eventName]) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean up stale callStack entries left by nested same-event dispatches
|
||||
$stale = [];
|
||||
foreach ($this->callStack as $listener) {
|
||||
if ($this->callStack->getInfo()[0] === $eventName) {
|
||||
$stale[] = $listener;
|
||||
}
|
||||
}
|
||||
foreach ($stale as $listener) {
|
||||
if ($listener->wasCalled()) {
|
||||
$original = $listener->getWrappedListener();
|
||||
if (!\in_array($original, $this->calledOriginalListeners[$this->currentRequestHash][$eventName] ?? [], true)) {
|
||||
$this->calledOriginalListeners[$this->currentRequestHash][$eventName][] = $original;
|
||||
$this->calledListenerInfos[$this->currentRequestHash][] = $listener->getInfo($eventName);
|
||||
}
|
||||
}
|
||||
unset($this->callStack[$listener]);
|
||||
}
|
||||
}
|
||||
|
||||
private function sortNotCalledListeners(array $a, array $b): int
|
||||
|
||||
Reference in New Issue
Block a user