Last active
January 6, 2023 03:51
-
-
Save tg666/0747d03d4356061585f9f635f7b054d3 to your computer and use it in GitHub Desktop.
Nettrine/dbal EventManager::getAllListeners() fix
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
extensions: | |
nettrine.dbal.fix: App\Bridge\Nettrine\Dbal\DbalFixExtension |
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
<?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(); | |
} | |
} |
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
<?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); | |
} | |
} | |
} |
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
<?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