for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace vfalies\tmdb\lib;
use vfalies\tmdb\Interfaces\HttpRequestInterface;
class CurlRequest implements HttpRequestInterface
{
private $handle = null;
/**
* Set the url to cUrl call
* @param string $url
* @throws Exception
*/
public function setUrl(string $url): void
$this->handle = curl_init($url);
}
* Close cUrl handle
public function close(): void
curl_close($this->handle);
* Execute cUrl call
* @return mixed
* @throws \Exception
public function execute()
$result = curl_exec($this->handle);
if ($result === false)
throw new \Exception('cUrl failed : ' . var_export($this->getInfo(), true), 1004);
return $result;
* Get cUrl infos
* @param string $name
public function getInfo(string $name = '')
if (empty($name))
$info = curl_getinfo($this->handle);
} else
$info = curl_getinfo($this->handle, $name);
return $info;
* Set cUrl option
* @param mixed $value
public function setOption(string $name, $value): HttpRequestInterface
curl_setopt($this->handle, $name, $value);
return $this;
* Magical getter
public function __get(string $name)
$response = '';
switch ($name)
case 'handle':
$response = $this->$name;
break;
return $response;