| Total Complexity | 5 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | final class TransportRegistry |
||
| 20 | { |
||
| 21 | /** @var HttpTransportInterface[] */ |
||
| 22 | private $transports = []; |
||
| 23 | |||
| 24 | /** @var string */ |
||
| 25 | private $default; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param string $name |
||
| 29 | */ |
||
| 30 | public function setDefaultTransport(string $name): void |
||
| 31 | { |
||
| 32 | $this->default = $name; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $name |
||
| 37 | * @param HttpTransportInterface $transport |
||
| 38 | */ |
||
| 39 | public function setTransport(string $name, HttpTransportInterface $transport): void |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param string|null $name |
||
| 46 | * @return HttpTransportInterface |
||
| 47 | */ |
||
| 48 | public function getTransport(string $name = null): HttpTransportInterface |
||
| 49 | { |
||
| 50 | $name = $name ?? $this->default; |
||
| 51 | |||
| 52 | if (!isset($this->transports[$name])) { |
||
| 53 | throw new TransportException("Undefined auth transport {$name}"); |
||
| 54 | } |
||
| 55 | |||
| 56 | return $this->transports[$name]; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return HttpTransportInterface[] |
||
| 61 | */ |
||
| 62 | public function getTransports(): array |
||
| 65 | } |
||
| 66 | } |
||
| 67 |