Completed
Push — master ( a72aaa...aa1c76 )
by Brian
03:39
created

ChannelDestroyed::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1
Metric Value
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4286
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * Copyright 2014 Brian Smith <[email protected]>.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *      http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace phparia\Events;
20
21
use phparia\Client\AriClient;
22
use phparia\Resources\Channel;
23
24
/**
25
 * Notification that a channel has been destroyed.
26
 *
27
 * @author Brian Smith <[email protected]>
28
 */
29
class ChannelDestroyed extends Event implements IdentifiableEventInterface
30
{
31
    /* Causes for disconnection (from Q.931) */
32
    const AST_CAUSE_UNALLOCATED = 1;
33
    const AST_CAUSE_NO_ROUTE_TRANSIT_NET = 2;
34
    const AST_CAUSE_NO_ROUTE_DESTINATION = 3;
35
    const AST_CAUSE_CHANNEL_UNACCEPTABLE = 6;
36
    const AST_CAUSE_CALL_AWARDED_DELIVERED = 7;
37
    const AST_CAUSE_NORMAL_CLEARING = 16;
38
    const AST_CAUSE_USER_BUSY = 17;
39
    const AST_CAUSE_NO_USER_RESPONSE = 18;
40
    const AST_CAUSE_NO_ANSWER = 19;
41
    const AST_CAUSE_CALL_REJECTED = 21;
42
    const AST_CAUSE_NUMBER_CHANGED = 22;
43
    const AST_CAUSE_DESTINATION_OUT_OF_ORDER = 27;
44
    const AST_CAUSE_INVALID_NUMBER_FORMAT = 28;
45
    const AST_CAUSE_FACILITY_REJECTED = 29;
46
    const AST_CAUSE_RESPONSE_TO_STATUS_ENQUIRY = 30;
47
    const AST_CAUSE_NORMAL_UNSPECIFIED = 31;
48
    const AST_CAUSE_NORMAL_CIRCUIT_CONGESTION = 34;
49
    const AST_CAUSE_NETWORK_OUT_OF_ORDER = 38;
50
    const AST_CAUSE_NORMAL_TEMPORARY_FAILURE = 41;
51
    const AST_CAUSE_SWITCH_CONGESTION = 42;
52
    const AST_CAUSE_ACCESS_INFO_DISCARDED = 43;
53
    const AST_CAUSE_REQUESTED_CHAN_UNAVAIL = 44;
54
    const AST_CAUSE_PRE_EMPTED = 45;
55
    const AST_CAUSE_FACILITY_NOT_SUBSCRIBED = 50;
56
    const AST_CAUSE_OUTGOING_CALL_BARRED = 52;
57
    const AST_CAUSE_INCOMING_CALL_BARRED = 54;
58
    const AST_CAUSE_BEARERCAPABILITY_NOTAUTH = 57;
59
    const AST_CAUSE_BEARERCAPABILITY_NOTAVAIL = 58;
60
    const AST_CAUSE_BEARERCAPABILITY_NOTIMPL = 65;
61
    const AST_CAUSE_CHAN_NOT_IMPLEMENTED = 66;
62
    const AST_CAUSE_FACILITY_NOT_IMPLEMENTED = 69;
63
    const AST_CAUSE_INVALID_CALL_REFERENCE = 81;
64
    const AST_CAUSE_INCOMPATIBLE_DESTINATION = 88;
65
    const AST_CAUSE_INVALID_MSG_UNSPECIFIED = 95;
66
    const AST_CAUSE_MANDATORY_IE_MISSING = 96;
67
    const AST_CAUSE_MESSAGE_TYPE_NONEXIST = 97;
68
    const AST_CAUSE_WRONG_MESSAGE = 98;
69
    const AST_CAUSE_IE_NONEXIST = 99;
70
    const AST_CAUSE_INVALID_IE_CONTENTS = 100;
71
    const AST_CAUSE_WRONG_CALL_STATE = 101;
72
    const AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE = 102;
73
    const AST_CAUSE_MANDATORY_IE_LENGTH_ERROR = 103;
74
    const AST_CAUSE_PROTOCOL_ERROR = 111;
75
    const AST_CAUSE_INTERWORKING = 127;
76
77
    /**
78
     * @var int Integer representation of the cause of the hangup
79
     */
80
    private $cause;
81
82
    /**
83
     * @var string Text representation of the cause of the hangup
84
     */
85
    private $causeTxt;
86
87
    /**
88
     * @var Channel
89
     */
90
    private $channel;
91
92
    /**
93
     * @return int Integer representation of the cause of the hangup
94
     */
95
    public function getCause()
96
    {
97
        return $this->cause;
98
    }
99
100
    /**
101
     * @return string Text representation of the cause of the hangup
102
     */
103
    public function getCauseTxt()
104
    {
105
        return $this->causeTxt;
106
    }
107
108
    /**
109
     * @return Channel
110
     */
111 1
    public function getChannel()
112
    {
113 1
        return $this->channel;
114
    }
115
116 1
    public function getEventId()
117
    {
118 1
        return "{$this->getType()}_{$this->getChannel()->getId()}";
119
    }
120
121
    /**
122
     * @param AriClient $client
123
     * @param string $response
124
     */
125 1
    public function __construct(AriClient $client, $response)
126
    {
127 1
        parent::__construct($client, $response);
128
129 1
        $this->cause = $this->response->cause;
130 1
        $this->causeTxt = $this->response->cause_txt;
131 1
        $this->channel = new Channel($client, $this->response->channel);
132 1
    }
133
134
}
135