These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\Api; |
||
20 | |||
21 | use Pest_BadRequest; |
||
22 | use Pest_Conflict; |
||
23 | use Pest_InvalidRecord; |
||
24 | use Pest_NotFound; |
||
25 | use phparia\Resources\Bridge; |
||
26 | use phparia\Exception\ConflictException; |
||
27 | use phparia\Exception\NotFoundException; |
||
28 | use phparia\Exception\UnprocessableEntityException; |
||
29 | |||
30 | /** |
||
31 | * Bridges API |
||
32 | * |
||
33 | * @author Brian Smith <[email protected]> |
||
34 | */ |
||
35 | class Bridges extends MediaBase |
||
36 | { |
||
37 | /** |
||
38 | * List all active bridges in Asterisk. |
||
39 | * |
||
40 | * @return Bridge[] |
||
41 | */ |
||
42 | 2 | public function getBridges() |
|
43 | { |
||
44 | 2 | $uri = '/bridges'; |
|
45 | 2 | $response = $this->client->getEndpoint()->get($uri); |
|
46 | |||
47 | 2 | $bridges = []; |
|
48 | 2 | foreach ((array)$response as $bridge) { |
|
49 | 2 | $bridges[] = new Bridge($this->client, $bridge); |
|
50 | 2 | } |
|
51 | |||
52 | 2 | return $bridges; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Create a new bridge. This bridge persists until it has been shut down, or Asterisk has been shut down. |
||
57 | * |
||
58 | * @param string $bridgeId Unique ID to give to the bridge being created. |
||
59 | * @param string $type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media). |
||
60 | * @param string $name Name to give to the bridge being created. |
||
61 | * @return Bridge |
||
62 | */ |
||
63 | 23 | View Code Duplication | public function createBridge($bridgeId, $type, $name) |
0 ignored issues
–
show
|
|||
64 | { |
||
65 | 23 | $uri = '/bridges'; |
|
66 | 23 | $response = $this->client->getEndpoint()->post($uri, array( |
|
67 | 23 | 'bridgeId' => $bridgeId, |
|
68 | 23 | 'type' => $type, |
|
69 | 23 | 'name' => $name, |
|
70 | 23 | )); |
|
71 | |||
72 | 23 | return new Bridge($this->client, $response); |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * Create a new bridge or updates an existing one. This bridge persists until it has been shut down, or Asterisk has been shut down. |
||
77 | * |
||
78 | * @param string $bridgeId Unique ID to give to the bridge being created. |
||
79 | * @param string $type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media) to set. |
||
80 | * @param string $name Set the name of the bridge. |
||
81 | * @return Bridge |
||
82 | */ |
||
83 | View Code Duplication | public function updateBridge($bridgeId, $type, $name) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
84 | { |
||
85 | $uri = "/bridges/$bridgeId"; |
||
86 | $response = $this->client->getEndpoint()->post($uri, array( |
||
87 | 'type' => $type, |
||
88 | 'name' => $name, |
||
89 | )); |
||
90 | |||
91 | return new Bridge($this->client, $response); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Get bridge details. |
||
96 | * |
||
97 | * @param string $bridgeId Bridge's id |
||
98 | * @return Bridge |
||
99 | * @throws NotFoundException |
||
100 | */ |
||
101 | 9 | public function getBridge($bridgeId) |
|
102 | { |
||
103 | 9 | $uri = "/bridges/$bridgeId"; |
|
104 | try { |
||
105 | 9 | $response = $this->client->getEndpoint()->get($uri); |
|
106 | 9 | } catch (Pest_NotFound $e) { |
|
107 | 4 | throw new NotFoundException($e); |
|
108 | } |
||
109 | |||
110 | 5 | return new Bridge($this->client, $response); |
|
111 | } |
||
112 | |||
113 | /** |
||
114 | * Shut down a bridge. If any channels are in this bridge, they will be removed and resume whatever they were doing beforehand. |
||
115 | * |
||
116 | * @param string $bridgeId Bridge's id |
||
117 | * @throws NotFoundException |
||
118 | */ |
||
119 | 14 | View Code Duplication | public function deleteBridge($bridgeId) |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
120 | { |
||
121 | 14 | $uri = "/bridges/$bridgeId"; |
|
122 | try { |
||
123 | 14 | $this->client->getEndpoint()->delete($uri); |
|
124 | 14 | } catch (Pest_NotFound $e) { |
|
125 | 2 | throw new NotFoundException($e); |
|
126 | } |
||
127 | 12 | } |
|
128 | |||
129 | /** |
||
130 | * Add a channel to a bridge. |
||
131 | * |
||
132 | * @param string $bridgeId Bridge's id |
||
133 | * @param string $channel (required) Ids of channels to add to bridge. Allows comma separated values. |
||
134 | * @param string $role Channel's role in the bridge |
||
135 | * @throws NotFoundException |
||
136 | * @throws ConflictException |
||
137 | * @throws UnprocessableEntityException |
||
138 | */ |
||
139 | 12 | public function addChannel($bridgeId, $channel, $role = null) |
|
140 | { |
||
141 | 12 | $uri = "/bridges/$bridgeId/addChannel"; |
|
142 | try { |
||
143 | 12 | $this->client->getEndpoint()->post($uri, array( |
|
144 | 12 | 'channel' => $channel, |
|
145 | 12 | 'role' => $role, |
|
146 | 12 | )); |
|
147 | 12 | } catch (Pest_BadRequest $e) { // Channel not found |
|
148 | 2 | throw new NotFoundException($e); |
|
149 | 2 | } catch (Pest_NotFound $e) { // Bridge not found |
|
150 | 2 | throw new NotFoundException($e); |
|
151 | } catch (Pest_Conflict $e) { // Bridge not in Stasis application; Channel currently recording |
||
152 | throw new ConflictException($e); |
||
153 | } catch (Pest_InvalidRecord $e) { // Channel not in Stasis application |
||
154 | throw new UnprocessableEntityException($e); |
||
155 | } |
||
156 | 8 | } |
|
157 | |||
158 | /** |
||
159 | * Remove a channel from a bridge. |
||
160 | * |
||
161 | * @param string $bridgeId Bridge's id |
||
162 | * @param string $channel (required) Ids of channels to remove from bridge. Allows comma separated values. |
||
163 | * @throws NotFoundException |
||
164 | * @throws ConflictException |
||
165 | * @throws UnprocessableEntityException |
||
166 | */ |
||
167 | 6 | View Code Duplication | public function removeChannel($bridgeId, $channel) |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
168 | { |
||
169 | 6 | $uri = "/bridges/$bridgeId/removeChannel"; |
|
170 | try { |
||
171 | 6 | $this->client->getEndpoint()->post($uri, array( |
|
172 | 6 | 'channel' => $channel, |
|
173 | 6 | )); |
|
174 | 6 | } catch (Pest_BadRequest $e) { // Channel not found |
|
175 | 2 | throw new NotFoundException($e); |
|
176 | 2 | } catch (Pest_NotFound $e) { // Bridge not found |
|
177 | 2 | throw new NotFoundException($e); |
|
178 | } catch (Pest_Conflict $e) { // Bridge not in Stasis application |
||
179 | throw new ConflictException($e); |
||
180 | } catch (Pest_InvalidRecord $e) { // Channel not in Stasis application |
||
181 | throw new UnprocessableEntityException($e); |
||
182 | } |
||
183 | 2 | } |
|
184 | |||
185 | 1 | public function getType() |
|
186 | { |
||
187 | 1 | return 'bridges'; |
|
188 | } |
||
189 | } |
||
190 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.