Skip to content

Commit a6ad03a

Browse files
committed
Cache driver instead of the full engine to avoid transport serialization issues.
1 parent 004d3e6 commit a6ad03a

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/Phpro/SoapClient/Soap/DefaultEngineFactory.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
namespace Phpro\SoapClient\Soap;
55

6-
use Soap\CachedEngine\CachedEngine;
6+
use Psr\Cache\CacheItemPoolInterface;
7+
use Soap\CachedEngine\CachedDriver;
78
use Soap\Encoding\Driver;
89
use Soap\Engine\Engine;
910
use Soap\Engine\LazyEngine;
@@ -15,32 +16,37 @@ final class DefaultEngineFactory
1516
public static function create(
1617
EngineOptions $options
1718
): Engine {
19+
return new LazyEngine(static fn (): Engine => self::configureEngine($options));
20+
}
1821

19-
$cache = $options->getCache();
20-
$factory = static fn(): Engine => self::configureEngine($options);
22+
private static function configureEngine(EngineOptions $options): Engine
23+
{
24+
$driver = $options->getCache()->mapOrElse(
25+
static fn (CacheItemPoolInterface $cache) => new CachedDriver(
26+
$cache,
27+
$options->getCacheConfig(),
28+
static fn () => self::configureDriver($options),
29+
),
30+
static fn () => self::configureDriver($options)
31+
)->unwrap();
2132

22-
return match (true) {
23-
$cache->isSome() => new CachedEngine($cache->unwrap(), $options->getCacheConfig(), $factory),
24-
default => new LazyEngine($factory),
25-
};
33+
return new SimpleEngine(
34+
$driver,
35+
$options->getTransport()
36+
);
2637
}
2738

28-
private static function configureEngine(EngineOptions $options): Engine
39+
private static function configureDriver(EngineOptions $options): Driver
2940
{
3041
$wsdl = (new Wsdl1Reader($options->getWsdlLoader()))(
3142
$options->getWsdl(),
3243
$options->getWsdlParserContext()
3344
);
3445

35-
$driver = Driver::createFromWsdl1(
46+
return Driver::createFromWsdl1(
3647
$wsdl,
3748
$options->getWsdlServiceSelectionCriteria(),
3849
$options->getEncoderRegistry()
3950
);
40-
41-
return new SimpleEngine(
42-
$driver,
43-
$options->getTransport()
44-
);
4551
}
4652
}

src/Phpro/SoapClient/Soap/EngineOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function getCache(): Option
130130

131131
public function getCacheConfig(): CacheConfig
132132
{
133-
return $this->cacheConfig ?? new CacheConfig('soap-engine-'.md5($this->wsdl));
133+
return $this->cacheConfig ?? new CacheConfig('soap-driver-'.md5($this->wsdl));
134134
}
135135

136136
public function getWsdlServiceSelectionCriteria(): ServiceSelectionCriteria

0 commit comments

Comments
 (0)