| 1 | <?php |
||
| 11 | class DriverManager |
||
| 12 | { |
||
| 13 | /** @var Driver[] */ |
||
| 14 | private $drivers; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Add driver. |
||
| 18 | * |
||
| 19 | * @param string $alias |
||
| 20 | * @param Driver $instance |
||
| 21 | */ |
||
| 22 | 2 | public function add(string $alias, Driver $instance): void |
|
| 26 | |||
| 27 | /** |
||
| 28 | * Get driver instance. |
||
| 29 | * |
||
| 30 | * @param Channel $channel |
||
| 31 | * |
||
| 32 | * @param array $request |
||
| 33 | * @param array $headers |
||
| 34 | * @param array $parameters |
||
| 35 | * |
||
| 36 | * @return Driver |
||
| 37 | */ |
||
| 38 | 2 | public function get(Channel $channel, array $request = [], array $headers = [], array $parameters = []): Driver |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Validate channel parameters with driver requirements. |
||
| 51 | * |
||
| 52 | * @param Channel $channel |
||
| 53 | * @param Driver $driver |
||
| 54 | */ |
||
| 55 | private function validateParameters(Channel $channel, Driver $driver): void |
||
| 63 | } |
||
| 64 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: