Completed
Push — master ( deb54b...06ec1a )
by Дмитрий
01:56
created

Service::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
7
namespace SocialConnect\Auth;
8
9
use Exception;
10
use SocialConnect\Common\Http\Client\ClientInterface;
11
use SocialConnect\Common\HttpClient;
12
use SocialConnect\Provider\Session\SessionInterface;
13
14
/**
15
 * Class Service
16
 * @package SocialConnect\Auth
17
 */
18
class Service
19
{
20
    /**
21
     * @var ClientInterface
22
     */
23
    protected $httpClient;
24
25
    /**
26
     * @var FactoryInterface
27
     */
28
    protected $factory;
29
30
    /**
31
     * @var array
32
     */
33
    protected $config;
34
35
    /**
36
     * @var SessionInterface
37
     */
38
    protected $session;
39
40
    /**
41
     * @param ClientInterface $httpClient
42
     * @param SessionInterface $session
43
     * @param array $config
44
     * @param FactoryInterface|null $factory
45
     * @internal param $storage
46
     */
47 3
    public function __construct(ClientInterface $httpClient, SessionInterface $session, array $config, FactoryInterface $factory = null)
48
    {
49 3
        $this->httpClient = $httpClient;
50 3
        $this->session = $session;
51 3
        $this->config = $config;
52
53 3
        $this->factory = is_null($factory) ? new CollectionFactory() : $factory;
54 3
    }
55
56
    /**
57
     * @param $name
58
     * @return array
59
     * @throws Exception
60
     */
61 1
    public function getProviderConfiguration($name)
62
    {
63 1
        if (isset($this->config['provider'][$name])) {
64 1
            return $this->config['provider'][$name];
65
        }
66
67
        throw new Exception('Please setup configuration for ' . ucfirst($name) . ' provider');
68
    }
69
70
    /**
71
     * Get provider class by $name
72
     *
73
     * @param $name
74
     * @return \SocialConnect\Provider\AbstractBaseProvider
75
     * @throws Exception
76
     */
77 1
    public function getProvider($name)
78
    {
79 1
        return $this->factory->factory($name, $this->getProviderConfiguration($name), $this);
80
    }
81
82
    /**
83
     * @return array
84
     */
85 2
    public function getConfig()
86
    {
87 2
        return $this->config;
88
    }
89
90
    /**
91
     * @return FactoryInterface
92
     */
93
    public function getFactory()
94
    {
95
        return $this->factory;
96
    }
97
98
    /**
99
     * @return ClientInterface
100
     */
101 2
    public function getHttpClient()
102 1
    {
103 2
        return $this->httpClient;
104
    }
105
106
    /**
107
     * @return SessionInterface
108
     */
109 2
    public function getSession()
110
    {
111 2
        return $this->session;
112
    }
113
}
114