Skip to content

Commit 272facb

Browse files
committed
feature #130 Decoupled models from managers issue (pistej)
This PR was squashed before being merged into the 0.4-dev branch. Discussion ---------- Decoupled models from managers issue Issue #128 Commits ------- 547e571 Decoupled models from managers issue
2 parents b1036a3 + 547e571 commit 272facb

21 files changed

+186
-70
lines changed

src/Event/PreSaveClientEvent.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace League\Bundle\OAuth2ServerBundle\Event;
66

7-
use League\Bundle\OAuth2ServerBundle\Model\AbstractClient;
7+
use League\Bundle\OAuth2ServerBundle\Model\ClientInterface;
88
use Symfony\Contracts\EventDispatcher\Event;
99

1010
/**
@@ -13,21 +13,21 @@
1313
class PreSaveClientEvent extends Event
1414
{
1515
/**
16-
* @var AbstractClient
16+
* @var ClientInterface
1717
*/
1818
private $client;
1919

20-
public function __construct(AbstractClient $client)
20+
public function __construct(ClientInterface $client)
2121
{
2222
$this->client = $client;
2323
}
2424

25-
public function getClient(): AbstractClient
25+
public function getClient(): ClientInterface
2626
{
2727
return $this->client;
2828
}
2929

30-
public function setClient(AbstractClient $client): void
30+
public function setClient(ClientInterface $client): void
3131
{
3232
$this->client = $client;
3333
}

src/Manager/AccessTokenManagerInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace League\Bundle\OAuth2ServerBundle\Manager;
66

7-
use League\Bundle\OAuth2ServerBundle\Model\AccessToken;
7+
use League\Bundle\OAuth2ServerBundle\Model\AccessTokenInterface;
88

99
interface AccessTokenManagerInterface
1010
{
11-
public function find(string $identifier): ?AccessToken;
11+
public function find(string $identifier): ?AccessTokenInterface;
1212

13-
public function save(AccessToken $accessToken): void;
13+
public function save(AccessTokenInterface $accessToken): void;
1414

1515
public function clearExpired(): int;
1616
}

src/Manager/AuthorizationCodeManagerInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace League\Bundle\OAuth2ServerBundle\Manager;
66

7-
use League\Bundle\OAuth2ServerBundle\Model\AuthorizationCode;
7+
use League\Bundle\OAuth2ServerBundle\Model\AuthorizationCodeInterface;
88

99
interface AuthorizationCodeManagerInterface
1010
{
11-
public function find(string $identifier): ?AuthorizationCode;
11+
public function find(string $identifier): ?AuthorizationCodeInterface;
1212

13-
public function save(AuthorizationCode $authCode): void;
13+
public function save(AuthorizationCodeInterface $authCode): void;
1414

1515
public function clearExpired(): int;
1616
}

src/Manager/ClientManagerInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55
namespace League\Bundle\OAuth2ServerBundle\Manager;
66

7-
use League\Bundle\OAuth2ServerBundle\Model\AbstractClient;
7+
use League\Bundle\OAuth2ServerBundle\Model\ClientInterface;
88

99
interface ClientManagerInterface
1010
{
11-
public function save(AbstractClient $client): void;
11+
public function save(ClientInterface $client): void;
1212

13-
public function remove(AbstractClient $client): void;
13+
public function remove(ClientInterface $client): void;
1414

15-
public function find(string $identifier): ?AbstractClient;
15+
public function find(string $identifier): ?ClientInterface;
1616

1717
/**
18-
* @return list<AbstractClient>
18+
* @return list<ClientInterface>
1919
*/
2020
public function list(?ClientFilter $clientFilter): array;
2121
}

src/Manager/Doctrine/AccessTokenManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\ORM\EntityManagerInterface;
88
use League\Bundle\OAuth2ServerBundle\Manager\AccessTokenManagerInterface;
99
use League\Bundle\OAuth2ServerBundle\Model\AccessToken;
10+
use League\Bundle\OAuth2ServerBundle\Model\AccessTokenInterface;
1011

1112
final class AccessTokenManager implements AccessTokenManagerInterface
1213
{
@@ -24,7 +25,7 @@ public function __construct(EntityManagerInterface $entityManager, bool $persist
2425
$this->persistAccessToken = $persistAccessToken;
2526
}
2627

27-
public function find(string $identifier): ?AccessToken
28+
public function find(string $identifier): ?AccessTokenInterface
2829
{
2930
if (!$this->persistAccessToken) {
3031
return null;
@@ -33,7 +34,7 @@ public function find(string $identifier): ?AccessToken
3334
return $this->entityManager->find(AccessToken::class, $identifier);
3435
}
3536

36-
public function save(AccessToken $accessToken): void
37+
public function save(AccessTokenInterface $accessToken): void
3738
{
3839
if (!$this->persistAccessToken) {
3940
return;

src/Manager/Doctrine/AuthorizationCodeManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\ORM\EntityManagerInterface;
88
use League\Bundle\OAuth2ServerBundle\Manager\AuthorizationCodeManagerInterface;
99
use League\Bundle\OAuth2ServerBundle\Model\AuthorizationCode;
10+
use League\Bundle\OAuth2ServerBundle\Model\AuthorizationCodeInterface;
1011

1112
final class AuthorizationCodeManager implements AuthorizationCodeManagerInterface
1213
{
@@ -20,12 +21,12 @@ public function __construct(EntityManagerInterface $entityManager)
2021
$this->entityManager = $entityManager;
2122
}
2223

23-
public function find(string $identifier): ?AuthorizationCode
24+
public function find(string $identifier): ?AuthorizationCodeInterface
2425
{
2526
return $this->entityManager->find(AuthorizationCode::class, $identifier);
2627
}
2728

28-
public function save(AuthorizationCode $authCode): void
29+
public function save(AuthorizationCodeInterface $authCode): void
2930
{
3031
$this->entityManager->persist($authCode);
3132
$this->entityManager->flush();

src/Manager/Doctrine/ClientManager.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use League\Bundle\OAuth2ServerBundle\Manager\ClientFilter;
1010
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
1111
use League\Bundle\OAuth2ServerBundle\Model\AbstractClient;
12+
use League\Bundle\OAuth2ServerBundle\Model\ClientInterface;
1213
use League\Bundle\OAuth2ServerBundle\OAuth2Events;
1314
use League\Bundle\OAuth2ServerBundle\ValueObject\Grant;
1415
use League\Bundle\OAuth2ServerBundle\ValueObject\RedirectUri;
@@ -45,14 +46,14 @@ public function __construct(
4546
$this->clientFqcn = $clientFqcn;
4647
}
4748

48-
public function find(string $identifier): ?AbstractClient
49+
public function find(string $identifier): ?ClientInterface
4950
{
5051
$repository = $this->entityManager->getRepository($this->clientFqcn);
5152

5253
return $repository->findOneBy(['identifier' => $identifier]);
5354
}
5455

55-
public function save(AbstractClient $client): void
56+
public function save(ClientInterface $client): void
5657
{
5758
$event = $this->dispatcher->dispatch(new PreSaveClientEvent($client), OAuth2Events::PRE_SAVE_CLIENT);
5859
$client = $event->getClient();
@@ -61,7 +62,7 @@ public function save(AbstractClient $client): void
6162
$this->entityManager->flush();
6263
}
6364

64-
public function remove(AbstractClient $client): void
65+
public function remove(ClientInterface $client): void
6566
{
6667
$this->entityManager->remove($client);
6768
$this->entityManager->flush();

src/Manager/Doctrine/RefreshTokenManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\ORM\EntityManagerInterface;
88
use League\Bundle\OAuth2ServerBundle\Manager\RefreshTokenManagerInterface;
99
use League\Bundle\OAuth2ServerBundle\Model\RefreshToken;
10+
use League\Bundle\OAuth2ServerBundle\Model\RefreshTokenInterface;
1011

1112
final class RefreshTokenManager implements RefreshTokenManagerInterface
1213
{
@@ -20,12 +21,12 @@ public function __construct(EntityManagerInterface $entityManager)
2021
$this->entityManager = $entityManager;
2122
}
2223

23-
public function find(string $identifier): ?RefreshToken
24+
public function find(string $identifier): ?RefreshTokenInterface
2425
{
2526
return $this->entityManager->find(RefreshToken::class, $identifier);
2627
}
2728

28-
public function save(RefreshToken $refreshToken): void
29+
public function save(RefreshTokenInterface $refreshToken): void
2930
{
3031
$this->entityManager->persist($refreshToken);
3132
$this->entityManager->flush();

src/Manager/InMemory/AccessTokenManager.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
namespace League\Bundle\OAuth2ServerBundle\Manager\InMemory;
66

77
use League\Bundle\OAuth2ServerBundle\Manager\AccessTokenManagerInterface;
8-
use League\Bundle\OAuth2ServerBundle\Model\AccessToken;
8+
use League\Bundle\OAuth2ServerBundle\Model\AccessTokenInterface;
99

1010
final class AccessTokenManager implements AccessTokenManagerInterface
1111
{
1212
/**
13-
* @var array<string, AccessToken>
13+
* @var array<string, AccessTokenInterface>
1414
*/
1515
private $accessTokens = [];
1616

@@ -25,7 +25,7 @@ public function __construct(bool $persistAccessToken)
2525
/**
2626
* @psalm-mutation-free
2727
*/
28-
public function find(string $identifier): ?AccessToken
28+
public function find(string $identifier): ?AccessTokenInterface
2929
{
3030
if (!$this->persistAccessToken) {
3131
return null;
@@ -34,7 +34,7 @@ public function find(string $identifier): ?AccessToken
3434
return $this->accessTokens[$identifier] ?? null;
3535
}
3636

37-
public function save(AccessToken $accessToken): void
37+
public function save(AccessTokenInterface $accessToken): void
3838
{
3939
if (!$this->persistAccessToken) {
4040
return;
@@ -52,7 +52,7 @@ public function clearExpired(): int
5252
$count = \count($this->accessTokens);
5353

5454
$now = new \DateTimeImmutable();
55-
$this->accessTokens = array_filter($this->accessTokens, static function (AccessToken $accessToken) use ($now): bool {
55+
$this->accessTokens = array_filter($this->accessTokens, static function (AccessTokenInterface $accessToken) use ($now): bool {
5656
return $accessToken->getExpiry() >= $now;
5757
});
5858

src/Manager/InMemory/AuthorizationCodeManager.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
namespace League\Bundle\OAuth2ServerBundle\Manager\InMemory;
66

77
use League\Bundle\OAuth2ServerBundle\Manager\AuthorizationCodeManagerInterface;
8-
use League\Bundle\OAuth2ServerBundle\Model\AuthorizationCode;
8+
use League\Bundle\OAuth2ServerBundle\Model\AuthorizationCodeInterface;
99

1010
final class AuthorizationCodeManager implements AuthorizationCodeManagerInterface
1111
{
1212
/**
13-
* @var array<string, AuthorizationCode>
13+
* @var array<string, AuthorizationCodeInterface>
1414
*/
1515
private $authorizationCodes = [];
1616

1717
/**
1818
* @psalm-mutation-free
1919
*/
20-
public function find(string $identifier): ?AuthorizationCode
20+
public function find(string $identifier): ?AuthorizationCodeInterface
2121
{
2222
return $this->authorizationCodes[$identifier] ?? null;
2323
}
2424

25-
public function save(AuthorizationCode $authCode): void
25+
public function save(AuthorizationCodeInterface $authCode): void
2626
{
2727
$this->authorizationCodes[$authCode->getIdentifier()] = $authCode;
2828
}
@@ -32,7 +32,7 @@ public function clearExpired(): int
3232
$count = \count($this->authorizationCodes);
3333

3434
$now = new \DateTimeImmutable();
35-
$this->authorizationCodes = array_filter($this->authorizationCodes, static function (AuthorizationCode $authorizationCode) use ($now): bool {
35+
$this->authorizationCodes = array_filter($this->authorizationCodes, static function (AuthorizationCodeInterface $authorizationCode) use ($now): bool {
3636
return $authorizationCode->getExpiryDateTime() >= $now;
3737
});
3838

src/Manager/InMemory/ClientManager.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use League\Bundle\OAuth2ServerBundle\Event\PreSaveClientEvent;
88
use League\Bundle\OAuth2ServerBundle\Manager\ClientFilter;
99
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
10-
use League\Bundle\OAuth2ServerBundle\Model\AbstractClient;
10+
use League\Bundle\OAuth2ServerBundle\Model\ClientInterface;
1111
use League\Bundle\OAuth2ServerBundle\OAuth2Events;
1212
use League\Bundle\OAuth2ServerBundle\ValueObject\Grant;
1313
use League\Bundle\OAuth2ServerBundle\ValueObject\RedirectUri;
@@ -17,7 +17,7 @@
1717
final class ClientManager implements ClientManagerInterface
1818
{
1919
/**
20-
* @var array<string, AbstractClient>
20+
* @var array<string, ClientInterface>
2121
*/
2222
private $clients = [];
2323

@@ -31,34 +31,34 @@ public function __construct(EventDispatcherInterface $dispatcher)
3131
$this->dispatcher = $dispatcher;
3232
}
3333

34-
public function find(string $identifier): ?AbstractClient
34+
public function find(string $identifier): ?ClientInterface
3535
{
3636
return $this->clients[$identifier] ?? null;
3737
}
3838

39-
public function save(AbstractClient $client): void
39+
public function save(ClientInterface $client): void
4040
{
4141
$event = $this->dispatcher->dispatch(new PreSaveClientEvent($client), OAuth2Events::PRE_SAVE_CLIENT);
4242
$client = $event->getClient();
4343

4444
$this->clients[$client->getIdentifier()] = $client;
4545
}
4646

47-
public function remove(AbstractClient $client): void
47+
public function remove(ClientInterface $client): void
4848
{
4949
unset($this->clients[$client->getIdentifier()]);
5050
}
5151

5252
/**
53-
* @return list<AbstractClient>
53+
* @return list<ClientInterface>
5454
*/
5555
public function list(?ClientFilter $clientFilter): array
5656
{
5757
if (null === $clientFilter || !$clientFilter->hasFilters()) {
5858
return array_values($this->clients);
5959
}
6060

61-
return array_values(array_filter($this->clients, static function (AbstractClient $client) use ($clientFilter): bool {
61+
return array_values(array_filter($this->clients, static function (ClientInterface $client) use ($clientFilter): bool {
6262
if (!self::passesFilter($client->getGrants(), $clientFilter->getGrants())) {
6363
return false;
6464
}

src/Manager/InMemory/RefreshTokenManager.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
namespace League\Bundle\OAuth2ServerBundle\Manager\InMemory;
66

77
use League\Bundle\OAuth2ServerBundle\Manager\RefreshTokenManagerInterface;
8-
use League\Bundle\OAuth2ServerBundle\Model\RefreshToken;
8+
use League\Bundle\OAuth2ServerBundle\Model\RefreshTokenInterface;
99

1010
final class RefreshTokenManager implements RefreshTokenManagerInterface
1111
{
1212
/**
13-
* @var array<string, RefreshToken>
13+
* @var array<string, RefreshTokenInterface>
1414
*/
1515
private $refreshTokens = [];
1616

1717
/**
1818
* @psalm-mutation-free
1919
*/
20-
public function find(string $identifier): ?RefreshToken
20+
public function find(string $identifier): ?RefreshTokenInterface
2121
{
2222
return $this->refreshTokens[$identifier] ?? null;
2323
}
2424

25-
public function save(RefreshToken $refreshToken): void
25+
public function save(RefreshTokenInterface $refreshToken): void
2626
{
2727
$this->refreshTokens[$refreshToken->getIdentifier()] = $refreshToken;
2828
}
@@ -32,7 +32,7 @@ public function clearExpired(): int
3232
$count = \count($this->refreshTokens);
3333

3434
$now = new \DateTimeImmutable();
35-
$this->refreshTokens = array_filter($this->refreshTokens, static function (RefreshToken $refreshToken) use ($now): bool {
35+
$this->refreshTokens = array_filter($this->refreshTokens, static function (RefreshTokenInterface $refreshToken) use ($now): bool {
3636
return $refreshToken->getExpiry() >= $now;
3737
});
3838

src/Manager/RefreshTokenManagerInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace League\Bundle\OAuth2ServerBundle\Manager;
66

7-
use League\Bundle\OAuth2ServerBundle\Model\RefreshToken;
7+
use League\Bundle\OAuth2ServerBundle\Model\RefreshTokenInterface;
88

99
interface RefreshTokenManagerInterface
1010
{
11-
public function find(string $identifier): ?RefreshToken;
11+
public function find(string $identifier): ?RefreshTokenInterface;
1212

13-
public function save(RefreshToken $refreshToken): void;
13+
public function save(RefreshTokenInterface $refreshToken): void;
1414

1515
public function clearExpired(): int;
1616
}

0 commit comments

Comments
 (0)