GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — thruway-0.4 ( 2e415f...2c60a9 )
by Cees-Jan
09:33
created

ConstructListener::construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
nc 2
nop 1
dl 0
loc 21
rs 9.3142
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Ratchet.
5
 *
6
 ** (c) 2016 Cees-Jan Kiewiet
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WyriHaximus\Ratchet\Event;
13
14
use Cake\Core\Configure;
15
use Cake\Event\EventListenerInterface;
16
use Cake\Event\EventManager;
17
use React\EventLoop\LoopInterface;
18
use Thruway\Authentication\AuthenticationManager;
19
use Thruway\Peer\Router;
20
use Thruway\Transport\RatchetTransportProvider;
21
use WyriHaximus\Ratchet\Security\AuthorizationManager;
22
use WyriHaximus\Ratchet\Security\JWTAuthProvider;
23
use WyriHaximus\Ratchet\Security\WampCraAuthProvider;
24
use WyriHaximus\Ratchet\Websocket\InternalClient;
25
26
final class ConstructListener implements EventListenerInterface
27
{
28
    /**
29
     * @var Router
30
     */
31
    private $router;
32
33
    /**
34
     * @var LoopInterface
35
     */
36
    private $loop;
37
38
    /**
39
     * @return array
40
     */
41
    public function implementedEvents()
42
    {
43
        return [
44
            ConstructEvent::EVENT => 'construct',
45
        ];
46
    }
47
48
    /**
49
     * @param ConstructEvent $event
50
     */
51
    public function construct(ConstructEvent $event)
52
    {
53
        $this->loop = $event->getLoop();
54
        $this->router = new Router($this->loop);
55
56
        $this->router->registerModule(new AuthenticationManager());
57
58
        foreach (Configure::read('WyriHaximus.Ratchet.realms') as $realm => $config) {
59
            $this->setUpRealm($realm, $config, $event->getEventManager());
60
        }
61
        $this->router->addTransportProvider(
62
            new RatchetTransportProvider(
63
                Configure::read('WyriHaximus.Ratchet.internal.address'),
64
                Configure::read('WyriHaximus.Ratchet.internal.port')
65
            )
66
        );
67
68
        $event->getEventManager()->dispatch(WebsocketStartEvent::create($this->loop));
69
70
        $this->router->start(false);
71
    }
72
73
    protected function setUpRealm($realm, array $config, EventManager $eventManager)
74
    {
75
        $internalClient = new InternalClient($realm, $this->loop);
76
        $internalClient->setEventManager($eventManager);
77
        $this->router->addInternalClient($internalClient);
78
        if (!\igorw\get_in($config, ['auth'], false)) {
79
            return;
80
        }
81
82
        $this->router->registerModule(new AuthorizationManager($realm, $this->loop));
83
        $this->router->addInternalClient((new JWTAuthProvider([$realm], $this->loop))->setKey($config['auth_key']));
84
    }
85
}