|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
|
9
|
|
|
* |
|
10
|
|
|
* This software may be modified and distributed under the terms |
|
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace OAuth2Framework\ServerBundle\Tests\TestBundle\Entity; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface; |
|
17
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
|
18
|
|
|
use OAuth2Framework\Component\Core\Client\Client as ClientInterface; |
|
19
|
|
|
use OAuth2Framework\Component\Core\Client\ClientId; |
|
20
|
|
|
use OAuth2Framework\Component\Core\Client\ClientRepository as ClientRepositoryInterface; |
|
21
|
|
|
use OAuth2Framework\Component\Core\DataBag\DataBag; |
|
22
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccountId; |
|
23
|
|
|
|
|
24
|
|
|
final class ClientRepository implements ClientRepositoryInterface, ServiceEntityRepositoryInterface |
|
25
|
|
|
{ |
|
26
|
|
|
private $entityRepository; |
|
27
|
|
|
private $entityManager; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct(ManagerRegistry $managerRegistry) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->entityManager = $managerRegistry->getManagerForClass(Client::class); |
|
32
|
|
|
$this->entityRepository = $this->entityManager->getRepository(Client::class); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function find(ClientId $clientId): ?ClientInterface |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->entityRepository->find($clientId); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function save(ClientInterface $client) |
|
41
|
|
|
{ |
|
42
|
|
|
if (!$client instanceof Client) { |
|
43
|
|
|
throw new \InvalidArgumentException('Unsupported client class'); |
|
44
|
|
|
} |
|
45
|
|
|
$this->entityManager->persist($client); |
|
46
|
|
|
$this->entityManager->flush(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function create(ClientId $clientId, DataBag $parameters, ?UserAccountId $ownerId): ClientInterface |
|
50
|
|
|
{ |
|
51
|
|
|
return new Client($clientId, $parameters, $ownerId); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function createClientId(): ClientId |
|
55
|
|
|
{ |
|
56
|
|
|
return new ClientId(\bin2hex(random_bytes(32))); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|