1313use Patchlevel \Hydrator \Metadata \ClassNotFound ;
1414use Patchlevel \Hydrator \Metadata \MetadataFactory ;
1515use Patchlevel \Hydrator \Normalizer \HydratorAwareNormalizer ;
16- use Psr \EventDispatcher \EventDispatcherInterface ;
1716use ReflectionParameter ;
1817use Symfony \Component \EventDispatcher \EventDispatcher ;
18+ use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
1919use Throwable ;
2020use TypeError ;
2121
@@ -29,22 +29,22 @@ final class MetadataHydrator implements Hydrator
2929 /** @var array<int, class-string> */
3030 private array $ stack = [];
3131
32- private readonly EventDispatcherInterface |null $ eventDispatcher ;
33-
3432 public function __construct (
3533 private readonly MetadataFactory $ metadataFactory = new AttributeMetadataFactory (),
36- PayloadCryptographer |EventDispatcherInterface |null $ cryptographer = null ,
34+ PayloadCryptographer |null $ cryptographer = null ,
35+ private EventDispatcherInterface |null $ eventDispatcher = null ,
3736 ) {
38- if ($ cryptographer === null ) {
39- $ this -> eventDispatcher = null ;
40- } elseif ( $ cryptographer instanceof EventDispatcherInterface) {
41- $ this -> eventDispatcher = $ cryptographer ;
42- } else {
37+ if (! $ cryptographer ) {
38+ return ;
39+ }
40+
41+ if (! $ this -> eventDispatcher ) {
4342 $ this ->eventDispatcher = new EventDispatcher ();
44- $ this ->eventDispatcher ->addSubscriber (
45- new CryptographySubscriber ($ cryptographer ),
46- );
4743 }
44+
45+ $ this ->eventDispatcher ->addSubscriber (
46+ new CryptographySubscriber ($ cryptographer ),
47+ );
4848 }
4949
5050 /**
0 commit comments