Skip to content

Commit

Permalink
Added deprecation for RememberMe services without logout() method
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed May 16, 2020
1 parent 0a33fc2 commit 44ab5cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions EventListener/RememberMeLogoutListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Exception\LogicException;
use Symfony\Component\Security\Http\Event\LogoutEvent;
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;

/**
* @author Wouter de Jong <[email protected]>
Expand All @@ -25,13 +25,21 @@ class RememberMeLogoutListener implements EventSubscriberInterface
{
private $rememberMeServices;

public function __construct(LogoutHandlerInterface $rememberMeServices)
public function __construct(RememberMeServicesInterface $rememberMeServices)
{
if (!method_exists($rememberMeServices, 'logout')) {
trigger_deprecation('symfony/security-core', '5.1', '"%s" should implement the "logout(Request $request, Response $response, TokenInterface $token)" method, this method will be added to the "%s" in version 6.0.', \get_class($rememberMeServices), RememberMeServicesInterface::class);
}

$this->rememberMeServices = $rememberMeServices;
}

public function onLogout(LogoutEvent $event): void
{
if (!method_exists($this->rememberMeServices, 'logout')) {
return;
}

if (null === $event->getResponse()) {
throw new LogicException(sprintf('No response was set for this logout action. Make sure the DefaultLogoutListener or another listener has set the response before "%s" is called.', __CLASS__));
}
Expand Down
2 changes: 2 additions & 0 deletions RememberMe/RememberMeServicesInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* - PersistentTokenBasedRememberMeServices (requires a TokenProvider)
*
* @author Johannes M. Schmitt <[email protected]>
*
* @method logout(Request $request, Response $response, TokenInterface $token)
*/
interface RememberMeServicesInterface
{
Expand Down

0 comments on commit 44ab5cb

Please sign in to comment.