From c25458146da3ebce41fb9809784da1d567d01269 Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Thu, 27 Mar 2025 14:55:17 +0100 Subject: [PATCH] Cache driver instead of the full engine to avoid transport serialization issues. --- .github/workflows/grumphp.yml | 2 +- .../SoapClient/Soap/DefaultEngineFactory.php | 34 +++++++++++-------- src/Phpro/SoapClient/Soap/EngineOptions.php | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/.github/workflows/grumphp.yml b/.github/workflows/grumphp.yml index c5365d48..862005bd 100644 --- a/.github/workflows/grumphp.yml +++ b/.github/workflows/grumphp.yml @@ -30,7 +30,7 @@ jobs: id: composercache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ steps.composercache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/src/Phpro/SoapClient/Soap/DefaultEngineFactory.php b/src/Phpro/SoapClient/Soap/DefaultEngineFactory.php index 9f8d3821..1284e4ed 100644 --- a/src/Phpro/SoapClient/Soap/DefaultEngineFactory.php +++ b/src/Phpro/SoapClient/Soap/DefaultEngineFactory.php @@ -3,7 +3,8 @@ namespace Phpro\SoapClient\Soap; -use Soap\CachedEngine\CachedEngine; +use Psr\Cache\CacheItemPoolInterface; +use Soap\CachedEngine\CachedDriver; use Soap\Encoding\Driver; use Soap\Engine\Engine; use Soap\Engine\LazyEngine; @@ -15,32 +16,37 @@ final class DefaultEngineFactory public static function create( EngineOptions $options ): Engine { + return new LazyEngine(static fn (): Engine => self::configureEngine($options)); + } - $cache = $options->getCache(); - $factory = static fn(): Engine => self::configureEngine($options); + private static function configureEngine(EngineOptions $options): Engine + { + $driver = $options->getCache()->mapOrElse( + static fn (CacheItemPoolInterface $cache) => new CachedDriver( + $cache, + $options->getCacheConfig(), + static fn () => self::configureDriver($options), + ), + static fn () => self::configureDriver($options) + )->unwrap(); - return match (true) { - $cache->isSome() => new CachedEngine($cache->unwrap(), $options->getCacheConfig(), $factory), - default => new LazyEngine($factory), - }; + return new SimpleEngine( + $driver, + $options->getTransport() + ); } - private static function configureEngine(EngineOptions $options): Engine + private static function configureDriver(EngineOptions $options): Driver { $wsdl = (new Wsdl1Reader($options->getWsdlLoader()))( $options->getWsdl(), $options->getWsdlParserContext() ); - $driver = Driver::createFromWsdl1( + return Driver::createFromWsdl1( $wsdl, $options->getWsdlServiceSelectionCriteria(), $options->getEncoderRegistry() ); - - return new SimpleEngine( - $driver, - $options->getTransport() - ); } } diff --git a/src/Phpro/SoapClient/Soap/EngineOptions.php b/src/Phpro/SoapClient/Soap/EngineOptions.php index d63e7866..1adba9d6 100644 --- a/src/Phpro/SoapClient/Soap/EngineOptions.php +++ b/src/Phpro/SoapClient/Soap/EngineOptions.php @@ -130,7 +130,7 @@ public function getCache(): Option public function getCacheConfig(): CacheConfig { - return $this->cacheConfig ?? new CacheConfig('soap-engine-'.md5($this->wsdl)); + return $this->cacheConfig ?? new CacheConfig('soap-driver-'.md5($this->wsdl)); } public function getWsdlServiceSelectionCriteria(): ServiceSelectionCriteria