getResource())["crypto"]`. * @param array $tlsContext Context obtained via `stream_context_get_options($socket->getResource())["ssl"])`. * * @return self */ public static function fromMetaData(array $cryptoInfo, array $tlsContext) : self { if (isset($tlsContext["peer_certificate"])) { $certificates = \array_merge([$tlsContext["peer_certificate"]], $tlsContext["peer_certificate_chain"] ?? []); } else { $certificates = $tlsContext["peer_certificate_chain"] ?? []; } return new self($cryptoInfo["protocol"], $cryptoInfo["cipher_name"], $cryptoInfo["cipher_bits"], $cryptoInfo["cipher_version"], $cryptoInfo["alpn_protocol"] ?? null, empty($certificates) ? null : $certificates); } private function __construct(string $version, string $cipherName, int $cipherBits, string $cipherVersion, ?string $alpnProtocol, ?array $certificates) { $this->version = $version; $this->cipherName = $cipherName; $this->cipherBits = $cipherBits; $this->cipherVersion = $cipherVersion; $this->alpnProtocol = $alpnProtocol; $this->certificates = $certificates; } public function getVersion() : string { return $this->version; } public function getCipherName() : string { return $this->cipherName; } public function getCipherBits() : int { return $this->cipherBits; } public function getCipherVersion() : string { return $this->cipherVersion; } public function getApplicationLayerProtocol() : ?string { return $this->alpnProtocol; } /** * @return Certificate[] * * @throws SocketException If peer certificates were not captured. */ public function getPeerCertificates() : array { if ($this->certificates === null) { throw new SocketException("Peer certificates not captured; use ClientTlsContext::withPeerCapturing() to capture peer certificates"); } if ($this->parsedCertificates === null) { $this->parsedCertificates = \array_map(static function ($resource) { return new Certificate($resource); }, $this->certificates); } return $this->parsedCertificates; } }