Total Complexity | 7 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | abstract class ALoopFactory extends ADefaultsAwareClass implements ILoopFactory |
||
18 | { |
||
19 | use NoInstanceTrait; |
||
20 | |||
21 | protected static ?ILoopAdapter $loop = null; |
||
22 | |||
23 | final public static function create(): ILoopAdapter |
||
24 | { |
||
25 | if (static::$loop instanceof ILoopAdapter) { |
||
26 | return static::$loop; |
||
27 | } |
||
28 | return static::createLoopAdapter(); |
||
29 | } |
||
30 | |||
31 | protected static function createLoopAdapter(): ILoopAdapter |
||
32 | { |
||
33 | /** @var class-string<IProbe> $probe */ |
||
34 | foreach (static::getProbeClasses() as $probe) { |
||
35 | if (is_subclass_of($probe, ILoopProbe::class) && $probe::isSupported()) { |
||
36 | return $probe::createLoop(); |
||
37 | } |
||
38 | } |
||
39 | throw new DomainException( |
||
40 | 'No supported event loop found.' . |
||
41 | ' Check you have installed one of the supported event loops.' . |
||
42 | ' Check your probes list if you have modified it.' |
||
43 | ); |
||
44 | } |
||
45 | |||
46 | protected static function getProbeClasses(): Traversable |
||
50 | } |
||
51 | } |
||
52 |