5050class User implements IUser {
5151 private const CONFIG_KEY_MANAGERS = 'manager ' ;
5252
53- private IConfig $ config ;
54- private IURLGenerator $ urlGenerator ;
5553 protected ?IAccountManager $ accountManager = null ;
5654
5755 private ?string $ displayName = null ;
@@ -63,15 +61,13 @@ class User implements IUser {
6361 private ?IAvatarManager $ avatarManager = null ;
6462
6563 public function __construct (
66- private string $ uid ,
67- private ?UserInterface $ backend ,
68- private IEventDispatcher $ dispatcher ,
69- private Emitter |Manager | null $ emitter = null ,
70- ? IConfig $ config = null ,
71- $ urlGenerator = null ,
64+ private readonly string $ uid ,
65+ private readonly ?UserInterface $ backend ,
66+ private readonly IEventDispatcher $ dispatcher ,
67+ private readonly Emitter |Manager $ emitter ,
68+ private readonly IConfig $ config ,
69+ private readonly IURLGenerator $ urlGenerator ,
7270 ) {
73- $ this ->config = $ config ?? Server ::get (IConfig::class);
74- $ this ->urlGenerator = $ urlGenerator ?? Server ::get (IURLGenerator::class);
7571 }
7672
7773 #[\Override]
@@ -251,10 +247,8 @@ public function delete(): bool {
251247 return false ;
252248 }
253249
254- if ($ this ->emitter ) {
255- /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
256- $ this ->emitter ->emit ('\OC\User ' , 'preDelete ' , [$ this ]);
257- }
250+ /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
251+ $ this ->emitter ->emit ('\OC\User ' , 'preDelete ' , [$ this ]);
258252 $ this ->dispatcher ->dispatchTyped (new BeforeUserDeletedEvent ($ this ));
259253
260254 // Set delete flag on the user - this is needed to ensure that the user data is removed if there happen any exception in the backend
@@ -315,10 +309,8 @@ public function delete(): bool {
315309 throw $ e ;
316310 }
317311
318- if ($ this ->emitter !== null ) {
319- /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
320- $ this ->emitter ->emit ('\OC\User ' , 'postDelete ' , [$ this ]);
321- }
312+ /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
313+ $ this ->emitter ->emit ('\OC\User ' , 'postDelete ' , [$ this ]);
322314 $ this ->dispatcher ->dispatchTyped (new UserDeletedEvent ($ this ));
323315
324316 // Finally we can unset the delete flag and all other states
@@ -336,19 +328,15 @@ public function delete(): bool {
336328 #[\Override]
337329 public function setPassword ($ password , $ recoveryPassword = null ): bool {
338330 $ this ->dispatcher ->dispatchTyped (new BeforePasswordUpdatedEvent ($ this , $ password , $ recoveryPassword ));
339- if ($ this ->emitter ) {
340- $ this ->emitter ->emit ('\OC\User ' , 'preSetPassword ' , [$ this , $ password , $ recoveryPassword ]);
341- }
331+ $ this ->emitter ->emit ('\OC\User ' , 'preSetPassword ' , [$ this , $ password , $ recoveryPassword ]);
342332 if ($ this ->backend ->implementsActions (Backend::SET_PASSWORD )) {
343333 /** @var ISetPasswordBackend $backend */
344334 $ backend = $ this ->backend ;
345335 $ result = $ backend ->setPassword ($ this ->uid , $ password );
346336
347337 if ($ result !== false ) {
348338 $ this ->dispatcher ->dispatchTyped (new PasswordUpdatedEvent ($ this , $ password , $ recoveryPassword ));
349- if ($ this ->emitter ) {
350- $ this ->emitter ->emit ('\OC\User ' , 'postSetPassword ' , [$ this , $ password , $ recoveryPassword ]);
351- }
339+ $ this ->emitter ->emit ('\OC\User ' , 'postSetPassword ' , [$ this , $ password , $ recoveryPassword ]);
352340 }
353341
354342 return !($ result === false );
@@ -676,8 +664,6 @@ private function removeProtocolFromUrl(string $url): string {
676664
677665 public function triggerChange ($ feature , $ value = null , $ oldValue = null ): void {
678666 $ this ->dispatcher ->dispatchTyped (new UserChangedEvent ($ this , $ feature , $ value , $ oldValue ));
679- if ($ this ->emitter ) {
680- $ this ->emitter ->emit ('\OC\User ' , 'changeUser ' , [$ this , $ feature , $ value , $ oldValue ]);
681- }
667+ $ this ->emitter ->emit ('\OC\User ' , 'changeUser ' , [$ this , $ feature , $ value , $ oldValue ]);
682668 }
683669}
0 commit comments