|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Tidal/WampWatch package. |
|
5
|
|
|
* (c) 2016 Timo Michna <timomichna/yahoo.de> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Tidal\WampWatch\Model\Factory; |
|
13
|
|
|
|
|
14
|
|
|
use Guzzle\Common\Exception\RuntimeException; |
|
15
|
|
|
use Tidal\WampWatch\Model\Contract\RouterInterface; |
|
16
|
|
|
use Tidal\WampWatch\Model\Contract\RealmInterface; |
|
17
|
|
|
use Tidal\WampWatch\Model\Contract\SessionInterface; |
|
18
|
|
|
use Tidal\WampWatch\Model\Connection; |
|
19
|
|
|
|
|
20
|
|
|
class ConnectionFactory |
|
21
|
|
|
{ |
|
22
|
|
|
private $router; |
|
23
|
|
|
|
|
24
|
|
|
private $realm; |
|
25
|
|
|
|
|
26
|
|
|
private $session; |
|
27
|
|
|
|
|
28
|
|
|
private function __construct(RouterInterface $router, |
|
29
|
|
|
RealmInterface $realm = null, |
|
30
|
|
|
SessionInterface $session = null |
|
31
|
|
|
) { |
|
32
|
|
|
$this->router = $router; |
|
33
|
|
|
$this->realm = $realm; |
|
34
|
|
|
$this->session = $session; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param RouterInterface $router |
|
39
|
|
|
* |
|
40
|
|
|
* @return ConnectionFactory |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function get(RouterInterface $router) |
|
43
|
|
|
{ |
|
44
|
|
|
return new self($router); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param RealmInterface $realm |
|
49
|
|
|
* |
|
50
|
|
|
* @return ConnectionFactory |
|
51
|
|
|
*/ |
|
52
|
|
|
public function select(RealmInterface $realm) |
|
53
|
|
|
{ |
|
54
|
|
|
return new self($this->router, $realm); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param SessionInterface $session |
|
59
|
|
|
* |
|
60
|
|
|
* @return ConnectionFactory |
|
61
|
|
|
*/ |
|
62
|
|
|
public function establish(SessionInterface $session) |
|
63
|
|
|
{ |
|
64
|
|
|
return new self($this->router, $this->realm, $session); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return Connection |
|
69
|
|
|
*/ |
|
70
|
|
|
public function create() |
|
71
|
|
|
{ |
|
72
|
|
|
if (!isset($this->realm)) { |
|
73
|
|
|
throw new RuntimeException('No realm set.'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return new Connection($this->router, $this->realm, $this->session); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|