/** * Prepares cUrl to execute the job * * @throws UnsupportedFeatureException * @throws \RuntimeException */ private function prepareCUrl() { $this->cUrl = curl_init((string) $this->fetchRequest->getUri()); if ($this->cUrl === false) { throw new \RuntimeException('Failed to initialize cURL - internal error'); } $schemeType = substr($this->fetchRequest->getUri()->getScheme(), 0, 4); if ($schemeType === 'http') { $this->prepareHttpCUrl(); } elseif ($schemeType !== 'ftp' && $schemeType !== 'ftps') { throw new \RuntimeException('Your request uses unknown scheme ' . $this->fetchRequest->getUri()->getScheme() . ' (available schemes: http/https/ftp/ftps)'); } $acceptUnsafeCertsFlag = $this->appConfig->isAcceptUnsafeCertificates() ? 0 : 2; //I f*****g love curl... curl_setopt_array($this->cUrl, [CURLOPT_RETURNTRANSFER => 1, CURLOPT_FILE => $this->responseStream, CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_SSL_VERIFYPEER => $acceptUnsafeCertsFlag, CURLOPT_SSL_VERIFYHOST => $acceptUnsafeCertsFlag]); $userInfo = $this->fetchRequest->getUri()->getUserInfo(); if (!empty($userInfo)) { curl_setopt_array($this->cUrl, [CURLOPT_HTTPAUTH => CURLAUTH_ANY, CURLOPT_USERPWD => $userInfo]); } }
public function testAcceptingUnsafeCertificatesFlagConvertsNonBoolValuesToBool() { $this->subjectUnderTest->setAcceptUnsafeCertificates(1); $this->assertTrue($this->subjectUnderTest->isAcceptUnsafeCertificates()); }