1 | <?php |
||
14 | final class StreamFactory |
||
15 | { |
||
16 | use CanCopy; |
||
17 | |||
18 | /** @const int */ |
||
19 | private const MIN_PORT = 1; |
||
20 | |||
21 | /** @const int 16bit */ |
||
22 | private const MAX_PORT = 65535; |
||
23 | |||
24 | /** @var string */ |
||
25 | private $protocol; |
||
26 | |||
27 | /** @var string */ |
||
28 | private $spec; |
||
29 | |||
30 | /** @var string */ |
||
31 | private $host; |
||
32 | |||
33 | /** @var int */ |
||
34 | private $port; |
||
35 | |||
36 | /** @var int */ |
||
37 | private $read; |
||
38 | |||
39 | /** @var int */ |
||
40 | private $readAfter; |
||
41 | |||
42 | /** @var int */ |
||
43 | private $readEvery; |
||
44 | |||
45 | /** @var int */ |
||
46 | private $write; |
||
47 | |||
48 | /** @var int */ |
||
49 | private $writeAfter; |
||
50 | |||
51 | /** @var int */ |
||
52 | private $writeEvery; |
||
53 | |||
54 | 21 | public static function make(string $dataSourceName): self |
|
76 | |||
77 | 21 | public function __construct(string $spec) |
|
85 | |||
86 | 10 | public function register(): string |
|
112 | |||
113 | 2 | public function withProtocol(string $protocol): self |
|
117 | |||
118 | 2 | public function withHost(string $host): self |
|
122 | |||
123 | 5 | public function withPort(int $port): self |
|
134 | |||
135 | 2 | public function withRead(int $limit = -1): self |
|
139 | |||
140 | 4 | public function withWrite(int $limit = -1): self |
|
144 | |||
145 | 1 | public function withoutRead(): self |
|
149 | |||
150 | 1 | public function withoutWrite(): self |
|
154 | |||
155 | 1 | public function withReadAfter(int $limit = 0): self |
|
159 | |||
160 | 1 | public function withWriteAfter(int $limit = 0): self |
|
164 | |||
165 | 1 | public function withReadEvery(int $limit = 1): self |
|
169 | |||
170 | 1 | public function withWriteEvery(int $limit = 1): self |
|
174 | } |
||
175 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are 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.php
However, as
OtherDir/Foo.php
does 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: