Completed
Push — master ( df9f00...ccd20f )
by dan
01:37
created

PusherAuthController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 4
dl 0
loc 34
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A connectAction() 0 23 1
1
<?php
2
3
namespace IrishDan\NotificationBundle\Controller;
4
5
use IrishDan\NotificationBundle\PusherChannel;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
12
class PusherAuthController extends Controller
13
{
14
    /**
15
     * Routing for private pusher channel authentication.
16
     * @Route(
17
     *     path = "/pusher/auth",
18
     *     name = "notification_pusher_auth"
19
     * )
20
     * @Method("POST")
21
     */
22
    public function connectAction(Request $request)
23
    {
24
        $pusher = $this->get('notification.pusher_manager')->getPusherClient();
25
26
        $channelName = $request->get('channel_name');
27
        $socketId    = $request->get('socket_id');
28
29
        $pusherChannel = new PusherChannel($channelName, $socketId);
30
31
        // Check if user should have access.
32
        $this->denyAccessUnlessGranted('subscribe', $pusherChannel);
33
34
        // Creates a json encoded string.
35
        $responseBody = $pusher->socket_auth($channelName, $socketId);
36
37
        return new Response(
38
            $responseBody,
39
            '200',
40
            [
41
                'Content-Type' => 'application/json',
42
            ]
43
        );
44
    }
45
}
46