33
44namespace Phpro \SoapClient \Soap ;
55
6- use Soap \CachedEngine \CachedEngine ;
6+ use Psr \Cache \CacheItemPoolInterface ;
7+ use Soap \CachedEngine \CachedDriver ;
78use Soap \Encoding \Driver ;
89use Soap \Engine \Engine ;
910use 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}
0 commit comments