| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | namespace Clansuite\Capture; |
| 14: | |
| 15: | use Clansuite\Capture\Extractor\VersionNormalizer; |
| 16: | use Clansuite\Capture\Protocol\ProtocolResolver; |
| 17: | use Clansuite\Capture\Storage\FixtureStorageInterface; |
| 18: | use Clansuite\Capture\Strategy\CaptureStrategyInterface; |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | final readonly class CaptureService |
| 24: | { |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | public function __construct( |
| 34: | private ProtocolResolver $protocolResolver, |
| 35: | private CaptureStrategyInterface $captureStrategy, |
| 36: | private FixtureStorageInterface $storage, |
| 37: | private VersionNormalizer $normalizer |
| 38: | ) { |
| 39: | } |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | public function capture(string $ip, int $port, string $protocol = 'auto', array $options = []): string |
| 52: | { |
| 53: | $protocolInstance = $this->protocolResolver->resolve($protocol, $ip, $port); |
| 54: | $addr = new ServerAddress($ip, $port); |
| 55: | |
| 56: | $result = $this->captureStrategy->capture($protocolInstance, $addr, $options + ['protocol_name' => $protocol]); |
| 57: | |
| 58: | $version = $this->normalizer->normalize( |
| 59: | $protocolInstance->getVersion($result->serverInfo), |
| 60: | ); |
| 61: | |
| 62: | return $this->storage->save( |
| 63: | $protocolInstance->getProtocolName(), |
| 64: | $version, |
| 65: | $ip, |
| 66: | $port, |
| 67: | $result, |
| 68: | ); |
| 69: | } |
| 70: | } |
| 71: | |