config = $config; $this->certificateManager = $certificateManager; $this->dnsPinMiddleware = $dnsPinMiddleware; $this->remoteHostValidator = $remoteHostValidator; $this->eventLogger = $eventLogger; } /** * @return Client */ public function newClient(): IClient { $handler = new CurlHandler(); $stack = HandlerStack::create($handler); if ($this->config->getSystemValueBool('dns_pinning', true)) { $stack->push($this->dnsPinMiddleware->addDnsPinning()); } $stack->push(Middleware::tap(function (RequestInterface $request) { $this->eventLogger->start('http:request', $request->getMethod() . " request to " . $request->getRequestTarget()); }, function () { $this->eventLogger->end('http:request'); }), 'event logger'); $client = new GuzzleClient(['handler' => $stack]); return new Client( $this->config, $this->certificateManager, $client, $this->remoteHostValidator, $this->logger, ); } }