Skip to content

Commit

Permalink
Merge pull request UnDeAdYeTii#6 from pxgamer/feature/phpunit
Browse files Browse the repository at this point in the history
Feature/phpunit
  • Loading branch information
bradietilley authored Oct 17, 2017
2 parents ede02ef + b510b6e commit 9cd205d
Show file tree
Hide file tree
Showing 10 changed files with 2,258 additions and 1,113 deletions.
195 changes: 131 additions & 64 deletions src/YeTii/Applications/Curl.php
Original file line number Diff line number Diff line change
@@ -1,81 +1,148 @@
<?php
namespace YeTii\Applications;

class Curl {
namespace YeTii\Applications;

protected $ch;
protected $responseHeader;
protected $responseBody;
protected $error;
protected $httpCode;
protected $latency;
/**
* Class Curl
*/
class Curl
{
/**
* @var resource
*/
protected $ch;
/**
* @var string
*/
protected $responseHeader;
/**
* @var string
*/
protected $responseBody;
/**
* @var string
*/
protected $error;
/**
* @var int
*/
protected $httpCode;
/**
* @var float
*/
protected $latency;

function __construct($url = null) {
$this->ch = curl_init($url);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 15);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Unknown) Gecko/20100101 Firefox/56.0');
curl_setopt($this->ch, CURLOPT_HEADER, true);
}
/**
* Curl constructor.
* @param string|null $url
*/
public function __construct($url = null)
{
$this->ch = curl_init($url);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 15);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Unknown) Gecko/20100101 Firefox/56.0');
curl_setopt($this->ch, CURLOPT_HEADER, true);
}

public function __call($name, $arguments) {
if (method_exists($this, $name)) {
return call_user_func_array([$this, $name], $arguments);
}elseif(is_array($arguments) && !empty($arguments) && $const = @constant('CURLOPT_'.strtoupper($name))) {
curl_setopt($this->ch, $const, $arguments[0]);
return $this;
}
}
/**
* @param $name
* @param $arguments
* @return $this|mixed
*/
public function __call($name, $arguments)
{
if (method_exists($this, $name)) {
return call_user_func_array([$this, $name], $arguments);
} elseif (is_array($arguments) && !empty($arguments) && $const = @constant('CURLOPT_' . strtoupper($name))) {
curl_setopt($this->ch, $const, $arguments[0]);

public static function __callStatic($name, $arguments) {
$c = new Curl();
return call_user_func_array([$c, $name], $arguments);
}
return $this;
}
}

public function __toString() {
return $this->response();
}
/**
* @param $name
* @param $arguments
* @return mixed
*/
public static function __callStatic($name, $arguments)
{
$c = new Curl();

private function execute() {
$latency = 0;
$response = curl_exec($this->ch);
$error = curl_error($this->ch);
$http_code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
$header_size = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
$time = curl_getinfo($this->ch, CURLINFO_TOTAL_TIME);
curl_close($this->ch);
$this->responseHeader = substr($response, 0, $header_size);
$this->responseBody = substr($response, $header_size);
$this->error = $error;
$this->httpCode = $http_code;
$this->latency = round($time * 1000);
return $this;
}
return call_user_func_array([$c, $name], $arguments);
}

private function response() {
return $this->responseBody;
}
/**
* @return mixed
*/
public function __toString()
{
return $this->response();
}

private function header() {
return $this->responseHeader;
}
/**
* @return $this
*/
private function execute()
{
$latency = 0;
$response = curl_exec($this->ch);
$error = curl_error($this->ch);
$http_code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
$header_size = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
$time = curl_getinfo($this->ch, CURLINFO_TOTAL_TIME);
curl_close($this->ch);
$this->responseHeader = substr($response, 0, $header_size);
$this->responseBody = substr($response, $header_size);
$this->error = $error;
$this->httpCode = $http_code;
$this->latency = round($time * 1000);

private function error() {
return $this->error;
}
return $this;
}

private function httpCode() {
return $this->httpCode;
}
/**
* @return mixed
*/
private function response()
{
return $this->responseBody;
}

private function latency() {
return $this->latency;
}
/**
* @return mixed
*/
private function header()
{
return $this->responseHeader;
}

/**
* @return mixed
*/
private function error()
{
return $this->error;
}

/**
* @return mixed
*/
private function httpCode()
{
return $this->httpCode;
}

/**
* @return mixed
*/
private function latency()
{
return $this->latency;
}
}
Loading

0 comments on commit 9cd205d

Please sign in to comment.