| Current Path : /var/www/www.indacotrentino.com/www/vendor/iubenda/module-cookiesolution/Helper/ |
| Current File : /var/www/www.indacotrentino.com/www/vendor/iubenda/module-cookiesolution/Helper/HttpClientTrait.php |
<?php
namespace Iubenda\CookieSolution\Helper;
use Magento\Framework\HTTP\Client\Curl;
use Magento\Framework\Exception\LocalizedException;
trait HttpClientTrait {
/**
* @var Curl
*/
protected $curlClient;
/**
* Make a GET request to the specified URL.
*
* @param string $url
*
* @return string
* @throws LocalizedException
*/
protected function httpGet( $url ) {
try {
$this->getCurlClient()->get( $url );
return $this->getCurlClient()->getBody();
} catch ( \Exception $e ) {
throw new LocalizedException( __( 'HTTP request failed: %1', $e->getMessage() ) );
}
}
/**
* Lazy load the Curl client.
*
* @return Curl
*/
private function getCurlClient() {
if ( $this->curlClient === null ) {
$this->curlClient = \Magento\Framework\App\ObjectManager::getInstance()->get( Curl::class );
}
return $this->curlClient;
}
}