2727
2828class Jwks
2929{
30- protected DateIntervalDecorator $ maxCacheDuration ;
31- protected DateIntervalDecorator $ timestampValidationLeeway ;
30+ protected DateIntervalDecorator $ maxCacheDurationDecorator ;
31+ protected DateIntervalDecorator $ timestampValidationLeewayDecorator ;
3232 protected ?CacheDecorator $ cacheDecorator ;
3333 protected ?JwksFetcher $ jwksFetcher = null ;
3434 protected HttpClientDecorator $ httpClientDecorator ;
35- protected JwsSerializerManager $ jwsSerializerManager ;
36- protected JwsParser $ jwsParser ;
37- protected JwsVerifier $ jwsVerifier ;
35+ protected ? JwsSerializerManager $ jwsSerializerManager = null ;
36+ protected ? JwsParser $ jwsParser = null ;
37+ protected ? JwsVerifier $ jwsVerifier = null ;
3838 protected ?JwksFactory $ jwksFactory = null ;
3939 protected ?SignedJwksFactory $ signedJwksFactory = null ;
40+ protected ?Helpers $ helpers = null ;
41+ protected ?AlgorithmManagerFactory $ algorithmManagerFactory = null ;
42+ protected ?JwsSerializerManagerFactory $ jwsSerializerManagerFactory = null ;
43+ protected ?JwsParserFactory $ jwsParserFactory = null ;
44+ protected ?JwsVerifierFactory $ jwsVerifierFactory = null ;
45+ protected ?DateIntervalDecoratorFactory $ dateIntervalDecoratorFactory = null ;
46+ protected ?CacheDecoratorFactory $ cacheDecoratorFactory = null ;
47+ protected ?HttpClientDecoratorFactory $ httpClientDecoratorFactory = null ;
4048
4149 public function __construct (
4250 protected readonly SupportedAlgorithms $ supportedAlgorithms = new SupportedAlgorithms (),
4351 protected readonly SupportedSerializers $ supportedSerializers = new SupportedSerializers (),
4452 DateInterval $ maxCacheDuration = new DateInterval ('PT1H ' ),
53+ DateInterval $ timestampValidationLeeway = new DateInterval ('PT1M ' ),
4554 ?CacheInterface $ cache = null ,
46- ?Client $ httpClient = null ,
4755 protected readonly ?LoggerInterface $ logger = null ,
48- protected readonly Helpers $ helpers = new Helpers (),
49- AlgorithmManagerFactory $ algorithmManagerFactory = new AlgorithmManagerFactory (),
50- JwsSerializerManagerFactory $ jwsSerializerManagerFactory = new JwsSerializerManagerFactory (),
51- JwsParserFactory $ jwsParserFactory = new JwsParserFactory (),
52- JwsVerifierFactory $ jwsVerifierFactory = new JwsVerifierFactory (),
53- DateInterval $ timestampValidationLeeway = new DateInterval ('PT1M ' ),
54- DateIntervalDecoratorFactory $ dateIntervalDecoratorFactory = new DateIntervalDecoratorFactory (),
55- CacheDecoratorFactory $ cacheDecoratorFactory = new CacheDecoratorFactory (),
56- HttpClientDecoratorFactory $ httpClientDecoratorFactory = new HttpClientDecoratorFactory (),
56+ ?Client $ httpClient = null ,
5757 ) {
58- $ this ->maxCacheDuration = $ dateIntervalDecoratorFactory ->build ($ maxCacheDuration );
59- $ this ->timestampValidationLeeway = $ dateIntervalDecoratorFactory ->build ($ timestampValidationLeeway );
60- $ this ->cacheDecorator = is_null ($ cache ) ? null : $ cacheDecoratorFactory ->build ($ cache );
61- $ this ->httpClientDecorator = $ httpClientDecoratorFactory ->build ($ httpClient );
62-
63- $ this ->jwsSerializerManager = $ jwsSerializerManagerFactory ->build ($ this ->supportedSerializers );
64- $ this ->jwsParser = $ jwsParserFactory ->build ($ this ->jwsSerializerManager );
65- $ this ->jwsVerifier = $ jwsVerifierFactory ->build ($ algorithmManagerFactory ->build ($ this ->supportedAlgorithms ));
58+ $ this ->maxCacheDurationDecorator = $ this ->dateIntervalDecoratorFactory ()->build ($ maxCacheDuration );
59+ $ this ->timestampValidationLeewayDecorator = $ this ->dateIntervalDecoratorFactory ()
60+ ->build ($ timestampValidationLeeway );
61+ $ this ->cacheDecorator = is_null ($ cache ) ? null : $ this ->cacheDecoratorFactory ()->build ($ cache );
62+ $ this ->httpClientDecorator = $ this ->httpClientDecoratorFactory ()->build ($ httpClient );
6663 }
6764
6865 public function jwksFactory (): JwksFactory
@@ -73,12 +70,12 @@ public function jwksFactory(): JwksFactory
7370 public function signedJwksFactory (): SignedJwksFactory
7471 {
7572 return $ this ->signedJwksFactory ??= new SignedJwksFactory (
76- $ this ->jwsParser ,
77- $ this ->jwsVerifier ,
73+ $ this ->jwsParser () ,
74+ $ this ->jwsVerifier () ,
7875 $ this ->jwksFactory (),
79- $ this ->jwsSerializerManager ,
80- $ this ->timestampValidationLeeway ,
81- $ this ->helpers ,
76+ $ this ->jwsSerializerManager () ,
77+ $ this ->timestampValidationLeewayDecorator ,
78+ $ this ->helpers () ,
8279 );
8380 }
8481
@@ -88,10 +85,91 @@ public function jwksFetcher(): JwksFetcher
8885 $ this ->httpClientDecorator ,
8986 $ this ->jwksFactory (),
9087 $ this ->signedJwksFactory (),
91- $ this ->maxCacheDuration ,
88+ $ this ->maxCacheDurationDecorator ,
9289 $ this ->cacheDecorator ,
9390 $ this ->logger ,
94- $ this ->helpers ,
91+ $ this ->helpers () ,
9592 );
9693 }
94+
95+ public function helpers (): Helpers
96+ {
97+ return $ this ->helpers ??= new Helpers ();
98+ }
99+
100+ public function algorithmManagerFactory (): AlgorithmManagerFactory
101+ {
102+ if (is_null ($ this ->algorithmManagerFactory )) {
103+ $ this ->algorithmManagerFactory = new AlgorithmManagerFactory ();
104+ }
105+ return $ this ->algorithmManagerFactory ;
106+ }
107+
108+ public function jwsSerializerManagerFactory (): JwsSerializerManagerFactory
109+ {
110+ if (is_null ($ this ->jwsSerializerManagerFactory )) {
111+ $ this ->jwsSerializerManagerFactory = new JwsSerializerManagerFactory ();
112+ }
113+ return $ this ->jwsSerializerManagerFactory ;
114+ }
115+
116+ public function jwsParserFactory (): JwsParserFactory
117+ {
118+ if (is_null ($ this ->jwsParserFactory )) {
119+ $ this ->jwsParserFactory = new JwsParserFactory ();
120+ }
121+ return $ this ->jwsParserFactory ;
122+ }
123+
124+ public function jwsVerifierFactory (): JwsVerifierFactory
125+ {
126+ if (is_null ($ this ->jwsVerifierFactory )) {
127+ $ this ->jwsVerifierFactory = new JwsVerifierFactory ();
128+ }
129+ return $ this ->jwsVerifierFactory ;
130+ }
131+
132+ public function dateIntervalDecoratorFactory (): DateIntervalDecoratorFactory
133+ {
134+ if (is_null ($ this ->dateIntervalDecoratorFactory )) {
135+ $ this ->dateIntervalDecoratorFactory = new DateIntervalDecoratorFactory ();
136+ }
137+
138+ return $ this ->dateIntervalDecoratorFactory ;
139+ }
140+
141+ public function cacheDecoratorFactory (): CacheDecoratorFactory
142+ {
143+ if (is_null ($ this ->cacheDecoratorFactory )) {
144+ $ this ->cacheDecoratorFactory = new CacheDecoratorFactory ();
145+ }
146+
147+ return $ this ->cacheDecoratorFactory ;
148+ }
149+
150+ public function httpClientDecoratorFactory (): HttpClientDecoratorFactory
151+ {
152+ if (is_null ($ this ->httpClientDecoratorFactory )) {
153+ $ this ->httpClientDecoratorFactory = new HttpClientDecoratorFactory ();
154+ }
155+
156+ return $ this ->httpClientDecoratorFactory ;
157+ }
158+
159+ public function jwsVerifier (): JwsVerifier
160+ {
161+ return $ this ->jwsVerifier ??= $ this ->jwsVerifierFactory ()->build (
162+ $ this ->algorithmManagerFactory ()->build ($ this ->supportedAlgorithms ),
163+ );
164+ }
165+
166+ public function jwsParser (): JwsParser
167+ {
168+ return $ this ->jwsParser ??= $ this ->jwsParserFactory ()->build ($ this ->jwsSerializerManager ());
169+ }
170+
171+ public function jwsSerializerManager (): JwsSerializerManager
172+ {
173+ return $ this ->jwsSerializerManager ??= $ this ->jwsSerializerManagerFactory ()->build ($ this ->supportedSerializers );
174+ }
97175}
0 commit comments