Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Channels | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| release | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Ably; |
| 3 | |
| 4 | class Channels { |
| 5 | |
| 6 | private $ably; |
| 7 | private $channels = []; |
| 8 | |
| 9 | /** |
| 10 | * Constructor |
| 11 | * @param AblyRest $ably Ably API instance |
| 12 | */ |
| 13 | public function __construct( AblyRest $ably ) { |
| 14 | $this->ably = $ably; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Creates a new Channel object for the specified channel if none exists, or returns the existing channel |
| 19 | * Note that if you request the same channel with different parameters, all the instances |
| 20 | * of the channel will be updated. |
| 21 | * @param string $name Name of the channel |
| 22 | * @param array|null $options ChannelOptions for the channel |
| 23 | * @return \Ably\Channel |
| 24 | */ |
| 25 | public function get( $name, $options = null ) { |
| 26 | |
| 27 | if ( isset( $this->channels[$name] ) ) { |
| 28 | if ( !is_null( $options ) ) { |
| 29 | $this->channels[$name]->setOptions( $options ); |
| 30 | } |
| 31 | |
| 32 | return $this->channels[$name]; |
| 33 | } else { |
| 34 | $this->channels[$name] = new Channel( $this->ably, $name, is_null( $options ) ? [] : $options ); |
| 35 | |
| 36 | return $this->channels[$name]; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Releases the channel resource i.e. it’s deleted and can then be garbage collected |
| 42 | * @param string $name Name of the channel |
| 43 | */ |
| 44 | public function release( $name ) { |
| 45 | if ( isset( $this->channels[$name] ) ) { |
| 46 | unset( $this->channels[$name] ); |
| 47 | } |
| 48 | } |
| 49 | } |