| 1 | <?php |
||
| 5 | class OutstandingCalls |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var OutstandingCall[] |
||
| 9 | */ |
||
| 10 | protected $calls = []; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @param callable $canceller |
||
| 14 | * @return OutstandingCall |
||
| 15 | */ |
||
| 16 | 3 | public function newCall(callable $canceller = null) |
|
| 17 | { |
||
| 18 | 3 | $uniqid = $this->getNewUniqid(); |
|
| 19 | |||
| 20 | 3 | $this->calls[$uniqid] = new OutstandingCall($uniqid, $canceller, function (OutstandingCall $call) { |
|
| 21 | 1 | unset($this->calls[$call->getUniqid()]); |
|
| 22 | 3 | }); |
|
| 23 | |||
| 24 | 3 | return $this->calls[$uniqid]; |
|
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param string $uniqid |
||
| 29 | * |
||
| 30 | * @return OutstandingCall |
||
| 31 | */ |
||
| 32 | 2 | public function getCall($uniqid) |
|
| 36 | |||
| 37 | /** |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | 2 | public function getCalls() |
|
| 44 | |||
| 45 | /** |
||
| 46 | * @return string |
||
| 47 | */ |
||
| 48 | 3 | protected function getNewUniqid() |
|
| 56 | } |
||
| 57 |