From 9fe535edbb8a2f719105ad3adc976da720cd58af Mon Sep 17 00:00:00 2001 From: Thorsten Hack Date: Wed, 15 May 2024 10:51:14 +0200 Subject: [PATCH] Update to middleware instead of EventSubscriber --- CHANGELOG.md | 5 ++++ README.md | 4 --- composer.json | 4 +-- ...tPass.php => AddOracleSessionInitPass.php} | 12 ++++---- .../Compiler/PassIndex.php | 2 +- lib/DependencyInjection/Compiler/ShimPass.php | 18 +++++------ .../Compiler/ShimPassInterface.php | 30 ------------------- .../Listeners/OnDemandOracleSessionInit.php | 16 ++++++---- .../oracle-listener-init-session-vars.xml | 2 +- 9 files changed, 31 insertions(+), 62 deletions(-) rename lib/DependencyInjection/Compiler/{AddOracleSesssionInitPass.php => AddOracleSessionInitPass.php} (86%) delete mode 100644 lib/DependencyInjection/Compiler/ShimPassInterface.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 7421037..88685e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# v1.2.0 +* Use middleware instead of listener +* Require doctrine/dbal >= 3.2 +* Require symfony >= 6.x + # v1.1.0 * Drop compatibility workaround for PostgreSQL 10 on PHP 5.x * Require doctrine/dbal >= 2.7 (for proper upstream PostgreSQL >= 10 support) diff --git a/README.md b/README.md index 085067e..baa3eaa 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ -NOTE: [older versions](https://github.com/WhereGroup/doctrine-dbal-shims/tree/v1.0.1) contained compatibility workarounds for -PostgreSQL >= 10 on unmaintained DBAL (<=2.6.x). This support has been removed. Only the Oracle -session init logic remains. - ## Oracle session variable preinitialization Included is an event subscriber that automatically sets Oracle session variables required by DBAL and Doctrine ORM to work properly (date formats etc). diff --git a/composer.json b/composer.json index 3baf8ee..69eadcf 100644 --- a/composer.json +++ b/composer.json @@ -4,8 +4,8 @@ "type": "library", "license": "MIT", "require": { - "php": ">=5.5", - "doctrine/dbal": "^2.7 || ^3" + "php": ">=8.1", + "doctrine/dbal": "^3.2" }, "autoload": { "psr-4": { "Wheregroup\\DoctrineDbalShims\\": "lib" } diff --git a/lib/DependencyInjection/Compiler/AddOracleSesssionInitPass.php b/lib/DependencyInjection/Compiler/AddOracleSessionInitPass.php similarity index 86% rename from lib/DependencyInjection/Compiler/AddOracleSesssionInitPass.php rename to lib/DependencyInjection/Compiler/AddOracleSessionInitPass.php index a820bcc..b1d9b52 100644 --- a/lib/DependencyInjection/Compiler/AddOracleSesssionInitPass.php +++ b/lib/DependencyInjection/Compiler/AddOracleSessionInitPass.php @@ -9,29 +9,27 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -class AddOracleSesssionInitPass extends ShimPass +class AddOracleSessionInitPass extends ShimPass { - /** @var FileLocator */ - protected $fileLocator; + protected FileLocator $fileLocator; public function __construct() { $this->fileLocator = new FileLocator(realpath(__DIR__ . '/../../Resources/config')); } - public static function isShimRequired(ContainerBuilder $container) + public static function isShimRequired(ContainerBuilder $container): bool { - // Can't hurt return true; } - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $loader = new XmlFileLoader($container, $this->fileLocator); $loader->import('oracle-listener-init-session-vars.xml'); } - public static function register(ContainerBuilder $container) + public static function register(ContainerBuilder $container): void { /** * Register for execution BEFORE doctrine event listeners are collected and diff --git a/lib/DependencyInjection/Compiler/PassIndex.php b/lib/DependencyInjection/Compiler/PassIndex.php index 369a8ab..addc97f 100644 --- a/lib/DependencyInjection/Compiler/PassIndex.php +++ b/lib/DependencyInjection/Compiler/PassIndex.php @@ -18,7 +18,7 @@ class PassIndex public static function getAllPasses() { return array( - new AddOracleSesssionInitPass(), + new AddOracleSessionInitPass(), ); } diff --git a/lib/DependencyInjection/Compiler/ShimPass.php b/lib/DependencyInjection/Compiler/ShimPass.php index c28635c..c7df049 100644 --- a/lib/DependencyInjection/Compiler/ShimPass.php +++ b/lib/DependencyInjection/Compiler/ShimPass.php @@ -4,15 +4,17 @@ namespace Wheregroup\DoctrineDbalShims\DependencyInjection\Compiler; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; -abstract class ShimPass implements ShimPassInterface +abstract class ShimPass implements CompilerPassInterface { + public abstract static function isShimRequired(ContainerBuilder $container): bool; + /** * Registers the compiler pass (invariantly) to the container builder. - * @param ContainerBuilder $container */ - public static function register(ContainerBuilder $container) + public static function register(ContainerBuilder $container): void { $container->addCompilerPass(new static()); } @@ -20,10 +22,8 @@ public static function register(ContainerBuilder $container) /** * Registers the compiler pass to the container builder ONLY IF it * is required / applicable to current DBAL setup. - * - * @param ContainerBuilder $container */ - public static function autoRegister(ContainerBuilder $container) + public static function autoRegister(ContainerBuilder $container): void { if (static::isShimRequired($container)) { static::register($container); @@ -35,12 +35,8 @@ public static function autoRegister(ContainerBuilder $container) * before a certain other pass (by class name). * Performs no action unless a compiler pass of given $className was already * added to the builder. - * - * @param ContainerBuilder $container - * @param string $className - * @return bool if pass was injected */ - protected static function registerBefore(ContainerBuilder $container, $className) + protected static function registerBefore(ContainerBuilder $container, string $className): bool { $passConfig = $container->getCompilerPassConfig(); $searchPasses = $passConfig->getBeforeOptimizationPasses(); diff --git a/lib/DependencyInjection/Compiler/ShimPassInterface.php b/lib/DependencyInjection/Compiler/ShimPassInterface.php deleted file mode 100644 index 4bab7e4..0000000 --- a/lib/DependencyInjection/Compiler/ShimPassInterface.php +++ /dev/null @@ -1,30 +0,0 @@ -getConnection()->getDriver() instanceof AbstractOracleDriver) { - parent::postConnect($args); + $platform = $driver->getDatabasePlatform(); + if ($platform instanceof OraclePlatform) { + return parent::wrap($driver); } + + return $driver; } } diff --git a/lib/Resources/config/oracle-listener-init-session-vars.xml b/lib/Resources/config/oracle-listener-init-session-vars.xml index acac800..824bedb 100644 --- a/lib/Resources/config/oracle-listener-init-session-vars.xml +++ b/lib/Resources/config/oracle-listener-init-session-vars.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - +