Completed
Push — master ( 26e625...88c602 )
by Timo
02:58
created

ConnectionFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
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, RealmInterface $realm = null, SessionInterface $session = null)
29
    {
30
        $this->router = $router;
31
        $this->realm = $realm;
32
        $this->session = $session;
33
    }
34
35
    /**
36
     * @param RouterInterface $router
37
     *
38
     * @return ConnectionFactory
39
     */
40
    public static function get(RouterInterface $router)
41
    {
42
        return new self($router);
43
    }
44
45
    /**
46
     * @param RealmInterface $realm
47
     *
48
     * @return ConnectionFactory
49
     */
50
    public function select(RealmInterface $realm)
51
    {
52
        return new self($this->router, $realm);
53
    }
54
55
    /**
56
     * @param SessionInterface $session
57
     *
58
     * @return ConnectionFactory
59
     */
60
    public function establish(SessionInterface $session)
61
    {
62
        return new self($this->router, $this->realm, $session);
63
    }
64
65
    /**
66
     * @return Connection
67
     */
68
    public function create()
69
    {
70
        if (!isset($this->realm)) {
71
            throw new RuntimeException('No realm set.');
72
        }
73
74
        return new Connection($this->router, $this->realm, $this->session);
75
    }
76
}
77