Skip to content

Commit 4468854

Browse files
committed
add a setRepository function for more flexibility
1 parent bfcab29 commit 4468854

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/Factory/AuthorizationServerFactory.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@ class AuthorizationServerFactory
2222
final public function __construct(Config $config)
2323
{
2424
$this->config = $config;
25+
$client = $config->getClient();
26+
$this->repositoryFactory = new RepositoryFactory([
27+
Repository::CLIENT => new Client(
28+
$client->getIdentifier(),
29+
$client->getSecret(),
30+
$client->getName(),
31+
$grantTypes,
32+
$client->getRedirectUris()
33+
),
34+
]);
2535
}
2636

27-
final public function setRepositoryFactory(RepositoryFactory $repositoryFactory)
37+
final public function setRepository($type, $repository)
2838
{
29-
$this->repositoryFactory = $repositoryFactory;
39+
$this->repositoryFactory->setRepository($type, $repository);
3040
}
3141

3242
final public function create() : AuthorizationServer
@@ -38,15 +48,7 @@ final public function create() : AuthorizationServer
3848
$grantTypes = $config->getGrantTypes();
3949
$keys = $config->getKeys();
4050

41-
$repositoryFactory = $this->repositoryFactory ?? new RepositoryFactory([
42-
Repository::CLIENT => new Client(
43-
$client->getIdentifier(),
44-
$client->getSecret(),
45-
$client->getName(),
46-
$grantTypes,
47-
$client->getRedirectUris()
48-
),
49-
]);
51+
$repositoryFactory = $this->repositoryFactory;
5052

5153
$server = new AuthorizationServer(
5254
$repositoryFactory->createClientRepository(),

src/Factory/RepositoryFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public function __construct(array $repositories = [])
2626
$this->repositories = $repositories;
2727
}
2828

29+
public function setRepository($type, $repository)
30+
{
31+
$this->repositories[$type] = $repository;
32+
}
33+
2934
final public function createAccessTokenRepository() : AccessTokenRepositoryInterface
3035
{
3136
return $this->createOnce(Repository::ACCESS_TOKEN);

0 commit comments

Comments
 (0)