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\Bundle\Tests\TestBundle\Entity; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\IssuerDiscoveryEndpoint\Resource; |
17
|
|
|
use OAuth2Framework\Component\IssuerDiscoveryEndpoint\ResourceId; |
18
|
|
|
use OAuth2Framework\Component\IssuerDiscoveryEndpoint\ResourceRepository as ResourceRepositoryInterface; |
19
|
|
|
|
20
|
|
|
final class ResourceRepository implements ResourceRepositoryInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Resource[] |
24
|
|
|
*/ |
25
|
|
|
private $resources = []; |
26
|
|
|
|
27
|
|
|
public function __construct() |
28
|
|
|
{ |
29
|
|
|
$this->resources['john'] = new ResourceObject('https://server.example.com'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function find(ResourceId $resourceId): ?Resource |
36
|
|
|
{ |
37
|
|
|
$server = 'my-service.com:9000'; |
38
|
|
|
$length = mb_strlen($server, 'utf-8'); |
39
|
|
|
if ('https://'.$server.'/+' === mb_substr($resourceId->getValue(), 0, $length + 10, 'utf-8')) { |
40
|
|
|
$resourceName = mb_substr($resourceId->getValue(), $length + 10, null, 'utf-8'); |
41
|
|
|
} elseif ('acct:' === mb_substr($resourceId->getValue(), 0, 5, 'utf-8') && '@'.$server === mb_substr($resourceId->getValue(), -($length + 1), null, 'utf-8')) { |
42
|
|
|
$resourceName = mb_substr($resourceId->getValue(), 5, -($length + 1), 'utf-8'); |
43
|
|
|
} else { |
44
|
|
|
return null; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return array_key_exists($resourceName, $this->resources) ? $this->resources[$resourceName] : null; |
|
|
|
|
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|