@@ -43,27 +43,27 @@ final class SymfonyToSyliusUserProviderProxy implements SyliusUserProviderInterf
4343 private $ attributeFetcher ;
4444
4545 /**
46- * @var PropertyAccessorInterface
46+ * @var FactoryInterface
4747 */
48- private $ propertyAccessor ;
48+ private $ adminUserFactory ;
4949
5050 /**
51- * @var FactoryInterface
51+ * @var UserSynchronizer
5252 */
53- private $ adminUserFactory ;
53+ private $ userSynchronizer ;
5454
5555 public function __construct (
5656 SymfonyUserProviderInterface $ ldapUserProvider ,
5757 AbstractUserProvider $ adminUserProvider ,
58- PropertyAccessorInterface $ propertyAccessor ,
5958 LdapAttributeFetcherInterface $ attributeFetcher ,
60- FactoryInterface $ adminUserFactory
59+ FactoryInterface $ adminUserFactory ,
60+ UserSynchronizer $ userSynchronizer
6161 ) {
6262 $ this ->ldapUserProvider = $ ldapUserProvider ;
6363 $ this ->adminUserProvider = $ adminUserProvider ;
6464 $ this ->attributeFetcher = $ attributeFetcher ;
65- $ this ->propertyAccessor = $ propertyAccessor ;
6665 $ this ->adminUserFactory = $ adminUserFactory ;
66+ $ this ->userSynchronizer = $ userSynchronizer ;
6767 }
6868
6969 public function loadUserByUsername ($ username ): SymfonyUserInterface
@@ -79,7 +79,7 @@ public function loadUserByUsername($username): SymfonyUserInterface
7979 return $ syliusLdapUser ;
8080 }
8181
82- $ this ->synchroniseUsers ($ syliusLdapUser , $ syliusUser );
82+ $ this ->userSynchronizer -> synchroniseUsers ($ syliusLdapUser , $ syliusUser );
8383
8484 return $ syliusUser ;
8585 }
@@ -95,7 +95,7 @@ public function refreshUser(SymfonyUserInterface $user): SymfonyUserInterface
9595 // Non-sylius-users (e.g.: symfony-users) are immutable and cannot be updated / synced.
9696 Assert::isInstanceOf ($ user , SyliusUserInterface::class);
9797
98- $ this ->synchroniseUsers ($ syliusLdapUser , $ user );
98+ $ this ->userSynchronizer -> synchroniseUsers ($ syliusLdapUser , $ user );
9999
100100 return $ user ;
101101 }
@@ -118,7 +118,6 @@ private function convertSymfonyToSyliusUser(SymfonyUserInterface $symfonyUser):
118118 $ syliusUser ->setPassword ('' );
119119 $ syliusUser ->setLocked ($ locked );
120120 $ syliusUser ->setEnabled (!$ locked );
121- // $syliusUser->setExpiresAt($ldapAttributes['expires_at']);
122121 $ syliusUser ->setLastLogin ($ this ->attributeFetcher ->toDateTime ($ ldapAttributes ['last_login ' ]));
123122 $ syliusUser ->setVerifiedAt ($ this ->attributeFetcher ->toDateTime ($ ldapAttributes ['verified_at ' ]));
124123 $ syliusUser ->setEmailCanonical ($ ldapAttributes ['email_canonical ' ]);
@@ -134,31 +133,4 @@ private function convertSymfonyToSyliusUser(SymfonyUserInterface $symfonyUser):
134133 return $ syliusUser ;
135134 }
136135
137- private function synchroniseUsers (
138- SyliusUserInterface $ sourceUser ,
139- SyliusUserInterface $ targetUser
140- ): void {
141- $ attributesToSync = [
142- 'email ' ,
143- 'expiresAt ' ,
144- 'lastLogin ' ,
145- 'enabled ' ,
146- 'verifiedAt ' ,
147- 'emailCanonical ' ,
148- 'username ' ,
149- 'usernameCanonical ' ,
150- 'credentialsExpireAt ' ,
151- ];
152-
153- if ($ targetUser instanceof AdminUserInterface && $ sourceUser instanceof AdminUserInterface) {
154- $ attributesToSync [] = 'lastName ' ;
155- $ attributesToSync [] = 'firstName ' ;
156- $ attributesToSync [] = 'localeCode ' ;
157- }
158-
159- foreach ($ attributesToSync as $ attributeToSync ) {
160- $ value = $ this ->propertyAccessor ->getValue ($ sourceUser , $ attributeToSync );
161- $ this ->propertyAccessor ->setValue ($ targetUser , $ attributeToSync , $ value );
162- }
163- }
164136}
0 commit comments