Upgrading from 1.x to 2.0
2.0 removes the factory pattern: the bundle now persists logs itself, through your Doctrine repository. The signatures below are those of 2.0 — jumping straight to 3.x or 4.x means applying this guide, then the next ones.
1. User entity: AuthenticableLogInterface becomes AuthLogUserInterface
Before:
class User implements UserInterface, AuthenticableLogInterface
{
public function getAuthenticationLogFactoryName(): string { return 'user'; }
public function getAuthenticationLogsToEmail(): string { return $this->email; }
public function getAuthenticationLogsToEmailName(): string { return $this->displayName; }
}After:
use Spiriit\Bundle\AuthLogBundle\Entity\AuthLogUserInterface;
class User implements AuthLogUserInterface
{
public function getAuthLogEmail(): string { return $this->email; }
public function getAuthLogDisplayName(): string { return $this->displayName; }
}AuthLogUserInterface extends UserInterface, so declaring it is no longer needed. getAuthenticationLogFactoryName() is gone with the factories (step 3).
2. Log entity: getUser() return type
// Before
public function getUser(): AuthenticableLogInterface
// After
public function getUser(): AuthLogUserInterface3. Replace the factory with a repository
Delete your AuthenticationLogFactoryInterface implementation and move its job to the Doctrine repository, which now implements two interfaces:
use Doctrine\ORM\EntityRepository;
use Spiriit\Bundle\AuthLogBundle\AuthenticationLog\AuthenticationLogCreatorInterface;
use Spiriit\Bundle\AuthLogBundle\Entity\AbstractAuthenticationLog;
use Spiriit\Bundle\AuthLogBundle\FetchUserInformation\UserInformation;
use Spiriit\Bundle\AuthLogBundle\Repository\AuthenticationLogRepositoryInterface;
class UserAuthLogRepository extends EntityRepository implements
AuthenticationLogRepositoryInterface,
AuthenticationLogCreatorInterface
{
public function save(AbstractAuthenticationLog $log): void
{
$this->getEntityManager()->persist($log);
$this->getEntityManager()->flush();
}
public function findExistingLog(string $userIdentifier, UserInformation $userInformation): bool
{
return null !== $this->findOneBy([
'user' => $userIdentifier,
'ipAddress' => $userInformation->ipAddress,
]);
}
public function createLog(string $userIdentifier, UserInformation $userInformation): AbstractAuthenticationLog
{
return new UserAuthLog($userIdentifier, $userInformation);
}
}4. Delete your event listener
markAsHandled() is gone: the bundle persists logs internally through your repository. Delete the listener entirely.
Listening to AuthenticationLogEvents::NEW_DEVICE for your own logic still works, with a new signature:
$event->userIdentifier(); // was: getUserReference()
$event->userInformation(); // was: getUserInformation()
// Removed: markAsHandled(), isLogHandled()5. Configuration
Unchanged — see the configuration reference.
Reference
| Removed | Replacement |
|---|---|
AuthenticableLogInterface | AuthLogUserInterface |
AuthenticationLogFactoryInterface | AuthenticationLogRepositoryInterface + AuthenticationLogCreatorInterface |
FetchAuthenticationLogFactory, AuthenticationLogFactoryPass | DoctrineAuthenticationLogHandler + registerForAutoconfiguration() (internal) |
AuthenticationContext, AuthenticationContextBuilder, AuthenticationEventPublisher | LoginService (internal, centralized orchestration) |
SpiriitAuthLogExtension, Configuration | Merged into SpiriitAuthLogBundle, which now extends AbstractBundle |
| Changed | Change |
|---|---|
AuthenticationLogEvent | Removed markAsHandled() / isLogHandled(); new userIdentifier() and userInformation() |
UserReference | Now final readonly with public properties; removed setNotificationParameters(), getEmail(), getDisplayName() |
LoginParameterDto | Removed factoryName |
LoginListener | Now final; message bus injected through the constructor |
AbstractAuthenticationLog | getUser() returns AuthLogUserInterface; fixed getLocation() bug |