Completed
Push — master ( fec6f1...fc6f01 )
by Alexandre
03:31
created

OAuthServerBuilder::addExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Alexandre
5
 * Date: 23/06/2018
6
 * Time: 18:08
7
 */
8
9
namespace OAuth2;
10
11
12
use OAuth2\Extensions\ExtensionInterface;
13
use OAuth2\Roles\AuthorizationServer\EndUserInterface;
14
use OAuth2\Storages\StorageManager;
15
use OAuth2\Storages\StorageRepositoryBuilder;
16
17
class OAuthServerBuilder
18
{
19
    /**
20
     * @var ExtensionInterface[]
21
     */
22
    protected $extensions = [];
23
24
    /**
25
     * @var Config
26
     */
27
    protected $config;
28
29
    /**
30
     * @var StorageRepositoryBuilder
31
     */
32
    protected $storages;
33
    /**
34
     * @var EndUserInterface
35
     */
36
    private $endUser;
37
38
    public function __construct(EndUserInterface $endUser)
39
    {
40
        $this->config = new Config();
41
        $this->storages = new StorageRepositoryBuilder();
42
        $this->endUser = $endUser;
43
    }
44
45
    public function getConfig() {
46
        return $this->config;
47
    }
48
49
    public function getStorages() {
50
        return $this->storages;
51
    }
52
53
    public function addExtension(ExtensionInterface $extension)
54
    {
55
        $this->extensions[] = $extension;
56
    }
57
58
    public function build()
59
    {
60
        foreach ($this->extensions as $extension) {
61
            $extension->load($this);
62
        }
63
        $storageManager = $this->storages->build();
64
        return new OAuthServer($this->config, $this->endUser, $storageManager);
65
    }
66
}