diff --git a/composer.json b/composer.json index 5c0a3af..1b3101d 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,9 @@ "phpunit/phpunit": "~4.4", "squizlabs/php_codesniffer": "~2.0" }, + "suggest": { + "composer/ca-bundle": "Including this library will ensure that a valid CA bundle is available for secure connections" + }, "autoload": { "psr-4": { "SendGrid\\": "lib/" diff --git a/lib/Client.php b/lib/Client.php index ec732b9..4480d92 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -367,6 +367,15 @@ private function createCurlOptions($method, $body = null, $headers = null) } $options[CURLOPT_HTTPHEADER] = $headers; + if (class_exists('\\Composer\\CaBundle\\CaBundle') && method_exists('\\Composer\\CaBundle\\CaBundle', 'getSystemCaRootBundlePath')) { + $caPathOrFile = \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath(); + if (is_dir($caPathOrFile) || (is_link($caPathOrFile) && is_dir(readlink($caPathOrFile)))) { + $options[CURLOPT_CAPATH] = $caPathOrFile; + } else { + $options[CURLOPT_CAINFO] = $caPathOrFile; + } + } + return $options; }