Skip to content

Instantly share code, notes, and snippets.

@tg666
Last active January 6, 2023 03:51
Show Gist options
  • Save tg666/0747d03d4356061585f9f635f7b054d3 to your computer and use it in GitHub Desktop.
Save tg666/0747d03d4356061585f9f635f7b054d3 to your computer and use it in GitHub Desktop.
Nettrine/dbal EventManager::getAllListeners() fix
extensions:
nettrine.dbal.fix: App\Bridge\Nettrine\Dbal\DbalFixExtension
<?php
declare(strict_types=1);
namespace App\Bridge\Nettrine\Dbal;
use Nettrine\DBAL\Events\ContainerAwareEventManager as NettrineContainerAwareEventManager;
final class ContainerAwareEventManager extends NettrineContainerAwareEventManager
{
public function getAllListeners(): array
{
return $this->getListeners();
}
}
<?php
declare(strict_types=1);
namespace App\Bridge\Nettrine\Dbal;
use RuntimeException;
use Nette\DI\CompilerExtension;
use Nettrine\DBAL\DI\DbalExtension;
use Nette\DI\Definitions\ServiceDefinition;
/**
* Hotfix for missing method EventManager::getAllListeners()
*
* @see https://github.com/contributte/doctrine-extensions-atlantic18/issues/31
*/
final class DbalFixExtension extends CompilerExtension
{
public function beforeCompile(): void
{
$dbalExtension = array_values($this->compiler->getExtensions(DbalExtension::class))[0] ?? null;
if (!$dbalExtension instanceof DbalExtension) {
throw new RuntimeException('DbalExtension is not registered.');
}
$builder = $this->getContainerBuilder();
$dbalExtensionName = $dbalExtension->name;
if ($builder->hasDefinition($dbalExtensionName . '.eventManager')) {
$containerAwareEventManager = $builder->getDefinition($dbalExtensionName . '.eventManager');
assert($containerAwareEventManager instanceof ServiceDefinition);
$containerAwareEventManager->setFactory(ContainerAwareEventManager::class);
}
if ($builder->hasDefinition($dbalExtensionName . '.eventManager.debug')) {
$debugEventManager = $builder->getDefinition($dbalExtensionName . '.eventManager.debug');
assert($debugEventManager instanceof ServiceDefinition);
$debugEventManager->setFactory(DebugEventManager::class, $debugEventManager->getFactory()->arguments);
}
}
}
<?php
declare(strict_types=1);
namespace App\Bridge\Nettrine\Dbal;
use Nettrine\DBAL\Events\DebugEventManager as NettrineDebugEventManager;
final class DebugEventManager extends NettrineDebugEventManager
{
public function getAllListeners(): array
{
return $this->getListeners();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment