-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(build) update per extension removal
- Loading branch information
Showing
17 changed files
with
2,435 additions
and
2,584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace lucatume\WPBrowser\Extension; | ||
|
||
use Codeception\Event\SuiteEvent; | ||
use Codeception\Events; | ||
use Codeception\Exception\ExtensionException; | ||
use Codeception\Extension; | ||
use lucatume\WPBrowser\Events\Dispatcher; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcher; | ||
|
||
class EventDispatcherBridge extends Extension | ||
{ | ||
/** | ||
* @var array<string,string> | ||
*/ | ||
public static array $events = [ | ||
Events::MODULE_INIT => 'onModuleInit', | ||
Events::SUITE_INIT => 'onSuiteInit', | ||
Events::SUITE_BEFORE => 'onSuiteBefore', | ||
]; | ||
private bool $eventDispatcherCaptured = false; | ||
|
||
public function onModuleInit(SuiteEvent $event): void | ||
{ | ||
$this->captureEventDispatcher($event, Events::MODULE_INIT); | ||
} | ||
|
||
public function onSuiteInit(SuiteEvent $event): void | ||
{ | ||
$this->captureEventDispatcher($event, Events::SUITE_INIT); | ||
} | ||
|
||
public function onSuiteBefore(SuiteEvent $event): void | ||
{ | ||
$this->captureEventDispatcher($event, Events::SUITE_BEFORE); | ||
} | ||
|
||
private function captureEventDispatcher(SuiteEvent $event, string $eventName): void | ||
{ | ||
if ($this->eventDispatcherCaptured) { | ||
return; | ||
} | ||
|
||
$eventDispatcher = null; | ||
$trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 5); | ||
foreach ($trace as $traceEntry) { | ||
if (!(isset($traceEntry['object']) && $traceEntry['object'] instanceof SymfonyEventDispatcher)) { | ||
continue; | ||
} | ||
$eventDispatcher = $traceEntry['object']; | ||
break; | ||
} | ||
|
||
if ($eventDispatcher === null) { | ||
throw new ExtensionException($this, 'Could not find the application event dispatcher.'); | ||
} | ||
|
||
$previousDispatcher = Dispatcher::getEventDispatcher(); | ||
/** @var callable[] $listeners */ | ||
$listeners = $previousDispatcher->getListeners($eventName); | ||
|
||
// Call the listeners for this event now,remove them from the previous dispatcher. | ||
foreach ($listeners as $listener) { | ||
$listener($event, $eventName, $eventDispatcher); | ||
$previousDispatcher->removeListener($eventName, $listener); | ||
} | ||
|
||
Dispatcher::setEventDispatcher($eventDispatcher); | ||
$this->eventDispatcherCaptured = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.