Skip to content

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:

php
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:

php
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

php
// Before
public function getUser(): AuthenticableLogInterface

// After
public function getUser(): AuthLogUserInterface

3. Replace the factory with a repository

Delete your AuthenticationLogFactoryInterface implementation and move its job to the Doctrine repository, which now implements two interfaces:

php
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:

php
$event->userIdentifier();   // was: getUserReference()
$event->userInformation();  // was: getUserInformation()

// Removed: markAsHandled(), isLogHandled()

5. Configuration

Unchanged — see the configuration reference.

Reference

RemovedReplacement
AuthenticableLogInterfaceAuthLogUserInterface
AuthenticationLogFactoryInterfaceAuthenticationLogRepositoryInterface + AuthenticationLogCreatorInterface
FetchAuthenticationLogFactory, AuthenticationLogFactoryPassDoctrineAuthenticationLogHandler + registerForAutoconfiguration() (internal)
AuthenticationContext, AuthenticationContextBuilder, AuthenticationEventPublisherLoginService (internal, centralized orchestration)
SpiriitAuthLogExtension, ConfigurationMerged into SpiriitAuthLogBundle, which now extends AbstractBundle
ChangedChange
AuthenticationLogEventRemoved markAsHandled() / isLogHandled(); new userIdentifier() and userInformation()
UserReferenceNow final readonly with public properties; removed setNotificationParameters(), getEmail(), getDisplayName()
LoginParameterDtoRemoved factoryName
LoginListenerNow final; message bus injected through the constructor
AbstractAuthenticationLoggetUser() returns AuthLogUserInterface; fixed getLocation() bug

Built and maintained by Spiriit — released under the MIT License.