Skip to content

Commit

Permalink
Remove Symfony 4.3 deprecations (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
acasademont authored and markitosgv committed Jul 3, 2019
1 parent 39ce962 commit ad47537
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ matrix:
env: SYMFONY_VERSION=3.4.*
- php: 7.2
env: SYMFONY_VERSION=3.4.*
# 4.2.*
# 4.3.*
- php: 7.1
env: SYMFONY_VERSION=4.2.*
env: SYMFONY_VERSION=4.3.*
- php: 7.2
env: SYMFONY_VERSION=4.2.*
env: SYMFONY_VERSION=4.3.*

cache:
directories:
Expand Down
18 changes: 18 additions & 0 deletions Event/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Gesdinet\JWTRefreshTokenBundle\Event;

use Symfony\Component\EventDispatcher\Event as BaseEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Contracts\EventDispatcher\Event as ContractsBaseEvent;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

if (is_subclass_of(EventDispatcher::class, EventDispatcherInterface::class)) {
class Event extends ContractsBaseEvent
{
}
} else {
class Event extends BaseEvent
{
}
}
1 change: 0 additions & 1 deletion Event/RefreshEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Gesdinet\JWTRefreshTokenBundle\Event;

use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;

class RefreshEvent extends Event
Expand Down
7 changes: 6 additions & 1 deletion Service/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Gesdinet\JWTRefreshTokenBundle\Event\RefreshEvent;
use Gesdinet\JWTRefreshTokenBundle\Security\Authenticator\RefreshTokenAuthenticator;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
use InvalidArgumentException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
Expand Down Expand Up @@ -147,7 +148,11 @@ public function refresh(Request $request)
$this->refreshTokenManager->save($refreshToken);
}

$this->eventDispatcher->dispatch('gesdinet.refresh_token', new RefreshEvent($refreshToken, $postAuthenticationToken));
if ($this->eventDispatcher instanceof ContractsEventDispatcherInterface) {
$this->eventDispatcher->dispatch(new RefreshEvent($refreshToken, $postAuthenticationToken), 'gesdinet.refresh_token');
} else {
$this->eventDispatcher->dispatch('gesdinet.refresh_token', new RefreshEvent($refreshToken, $postAuthenticationToken));
}

return $this->successHandler->onAuthenticationSuccess($request, $postAuthenticationToken);
}
Expand Down

0 comments on commit ad47537

Please sign in to comment.