1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Connection base class. |
5
|
|
|
* |
6
|
|
|
* Abstract connection base class. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace zaporylie\Vipps; |
10
|
|
|
|
11
|
|
|
use Eloquent\Enumeration\AbstractMultiton; |
12
|
|
|
use Http\Discovery\UriFactoryDiscovery; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class ConnectionBase |
16
|
|
|
* @package Vipps |
17
|
|
|
* @subpackage Connection |
18
|
|
|
*/ |
19
|
|
|
class Endpoint extends AbstractMultiton implements EndpointInterface |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
protected static $live = [ |
23
|
|
|
'scheme' => 'https', |
24
|
|
|
'host' => 'api.vipps.no', |
25
|
|
|
'port' => '443', |
26
|
|
|
'path' => '', |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
protected static $test = [ |
30
|
|
|
'scheme' => 'https', |
31
|
|
|
'host' => 'apitest.vipps.no', |
32
|
|
|
'port' => '443', |
33
|
|
|
'path' => '', |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
protected $scheme; |
37
|
|
|
protected $host; |
38
|
|
|
protected $port; |
39
|
|
|
protected $path; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
protected static function initializeMembers() |
45
|
|
|
{ |
46
|
|
|
$reflectionClass = new \ReflectionClass(self::class); |
47
|
|
|
foreach ($reflectionClass->getStaticProperties() as $staticPropertyName => $staticPropertyValue) { |
48
|
|
|
new static( |
49
|
|
|
$staticPropertyName, |
50
|
|
|
$staticPropertyValue['scheme'], |
51
|
|
|
$staticPropertyValue['host'], |
52
|
|
|
$staticPropertyValue['port'], |
53
|
|
|
$staticPropertyValue['path'] |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function __construct($key, $scheme, $host, $port, $path) |
59
|
|
|
{ |
60
|
|
|
parent::__construct($key); |
61
|
|
|
$this->scheme = $scheme; |
62
|
|
|
$this->host = $host; |
63
|
|
|
$this->port = $port; |
64
|
|
|
$this->path = $path; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Gets scheme value. |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
public function getScheme() |
73
|
|
|
{ |
74
|
|
|
return $this->scheme; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Gets host value. |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getHost() |
83
|
|
|
{ |
84
|
|
|
return $this->host; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Gets port value. |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getPort() |
93
|
|
|
{ |
94
|
|
|
return $this->port; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Gets path value. |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getPath() |
103
|
|
|
{ |
104
|
|
|
return $this->path; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get connection base uri. |
109
|
|
|
* |
110
|
|
|
* @return \Psr\Http\Message\UriInterface |
111
|
|
|
*/ |
112
|
|
|
public function getUri() |
113
|
|
|
{ |
114
|
|
|
$uri = UriFactoryDiscovery::find(); |
115
|
|
|
return $uri->createUri(sprintf( |
116
|
|
|
'%s://%s:%s%s', |
117
|
|
|
$this->getScheme(), |
118
|
|
|
$this->getHost(), |
119
|
|
|
$this->getPort(), |
120
|
|
|
$this->getPath() |
121
|
|
|
)); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|