Completed
Pull Request — master (#36)
by Timo
02:49
created

NotAuthorizedException::setTopicName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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\Exception;
13
14
/**
15
 * Class NoSuchProcedureException.
16
 *
17
 * Thrown when a router does not support a given meta topic
18
 */
19
class NotAuthorizedException extends \OutOfBoundsException
20
{
21
    const ERROR_RESPONSE = 'wamp.error.not_authorized';
22
23
    const DEFAULT_ERROR_MSG = 'session is not authorized';
24
25
    /**
26
     * @var string name of the topic
27
     */
28
    protected $topicName;
29
30
    /**
31
     * @param string $topicName
32
     * @param string $errorMsg
33
     */
34
    public function __construct($topicName, $errorMsg = self::DEFAULT_ERROR_MSG)
35
    {
36
        $this->setTopicName($topicName);
37
38
        parent::__construct($errorMsg);
39
    }
40
41
    /**
42
     * Checks if a router response is a 'no_such_topic' error.
43
     *
44
     * @param $errorResponse
45
     *
46
     * @return bool
47
     */
48
    public static function isNotAuthrorizedError($errorResponse)
49
    {
50
        return $errorResponse == self::ERROR_RESPONSE;
51
    }
52
53
    /**
54
     * @return string the topic name
55
     */
56
    public function getTopicName()
57
    {
58
        return $this->topicName;
59
    }
60
61
    /**
62
     * @param string $topicName
63
     */
64
    protected function setTopicName($topicName)
65
    {
66
        $this->topicName = $topicName;
67
    }
68
}
69