Skip to content

Commit

Permalink
Removed deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Sneppy committed Jul 4, 2018
1 parent ed99c59 commit eb81f05
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 86 deletions.
14 changes: 7 additions & 7 deletions Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Curl
* @param array $headers list of http headers
* @param bool $initOnly if true the session won't be executed
*/
public function __construct($url = null, array $options = [], array $headers = [], $initOnly = true)
public function __construct($url, array $options = [], array $headers = [], $initOnly = true)
{
// Init curl session
$this->curl = curl_init($this->url = $url);
Expand Down Expand Up @@ -230,39 +230,39 @@ protected function parseHeader($curl, $header)
* Create appropriate session
*
* @param string $method method string
* @param string $uri resource uri
* @param string $url transfer url
* @param string|array $data data to post [default: ""]
* @param array $headers set of additional headers [default: []]
* @param array $options set of additional options [default: []]
* @param bool $initOnly if true don't send request on creation [default: false]
*
* @return Get|Post|Put|Delete|null null if $method doesn't match any available method
*/
public static function create($method, $uri, $data = "", array $headers = [], array $options = [], $initOnly = false)
public static function create($method, $url, $data = "", array $headers = [], array $options = [], $initOnly = false)
{
// Null if method is not valid
$curl = null;

// Compare method
if (!strcasecmp($method, "GET"))
$curl = new static($uri, $options + [
$curl = new static($url, $options + [
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_RETURNTRANSFER => true
], $headers, $initOnly);
else if (!strcasecmp($method, "POST"))
$curl = new static($uri, $options + [
$curl = new static($url, $options + [
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true
], $headers, $initOnly);
else if (!strcasecmp($method, "PUT"))
$curl = new static($uri, $options + [
$curl = new static($url, $options + [
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true
], $headers, $initOnly);
else if (!strcasecmp($method, "DELETE"))
$curl = new static($uri, $options + [
$curl = new static($url, $options + [
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_RETURNTRANSFER => true
], $headers, $initOnly);
Expand Down
17 changes: 0 additions & 17 deletions Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,4 @@ public function __construct($url, array $headers = [], $initOnly = false)
CURLOPT_RETURNTRANSFER => true
], $headers, $initOnly);
}

/**
* Create a new session with an authorization header
*
* @deprecated v0.2.4
*
* @param string $url request url
* @param string $authKey authorization key
* @param array $headers list of additional http headers
* @param bool $initOnly if true the session won't be executed
*
* @return Delete
*/
public static function withAuth($url, $authKey = "", array $headers = [], $initOnly = false)
{
return new Delete($url, array_merge(["Authorization" => $authKey], $headers), $initOnly);
}
}
17 changes: 0 additions & 17 deletions Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,4 @@ public function __construct($url, array $headers = [], $initOnly = false)
CURLOPT_RETURNTRANSFER => true
], $headers, $initOnly);
}

/**
* Create a new session with an authorization header
*
* @deprecated v0.2.4
*
* @param string $url request url
* @param string $authKey authorization key
* @param array $headers list of additional http headers
* @param bool $initOnly if true the session won't be executed
*
* @return Get
*/
public static function withAuth($url, $authKey = "", array $headers = [], $initOnly = false)
{
return new Get($url, array_merge(["Authorization" => $authKey], $headers), $initOnly);
}
}
26 changes: 4 additions & 22 deletions Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,19 @@ class Post extends Curl
* Create a new POST request
*
* @param string $url requested url
* @param string|array $post post data as an associative array or url encoded string
* @param string|array $data post data as an associative array or url encoded string
* @param array $headers list of http headers
* @param bool $initOnly if true the session won't be executed
*/
public function __construct($url, $post = "", array $headers = [], $initOnly = false)
public function __construct($url, $data = "", array $headers = [], $initOnly = false)
{
// If string, set x-www-form-urlencoded header
if (is_string($post)) $headers["Content-Type"] = "application/x-www-form-urlencoded";
if (is_string($data)) $headers["Content-Type"] = "application/x-www-form-urlencoded";

parent::__construct($url, [
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $post,
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true
], $headers, $initOnly);
}

/**
* Create a new session with an authorization header
*
* @deprecated v0.2.4
*
* @param string $url request url
* @param string $authKey authorization key
* @param string|array $post post data as an associative array or urlencoded string
* @param array $headers list of additional http headers
* @param bool $initOnly if true the session won't be executed
*
* @return Post
*/
public static function withAuth($url, $authKey = "", $post = "", array $headers = [], $initOnly = false)
{
return new Post($url, $post, array_merge(["Authorization" => $authKey], $headers), $initOnly);
}
}
25 changes: 3 additions & 22 deletions Put.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,16 @@ class Put extends Curl
* Create a new PUT request
*
* @param string $url requested url
* @param string|array $put data as an associative array or urlencoded string
* @param string|array $data data as an associative array or urlencoded string
* @param array $headers list of http headers
* @param bool $initOnly if true the session won't be executed
*/
public function __construct($url, $put = "", array $headers = [], $initOnly = false)
public function __construct($url, $data = "", array $headers = [], $initOnly = false)
{
if (is_string($put)) $headers["Content-Type"] = "application/x-www-form-urlencoded";
parent::__construct($url, [
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => http_build_query($put),
CURLOPT_POSTFIELDS => is_string($data) ? $data : http_build_query($data),
CURLOPT_RETURNTRANSFER => true
], $headers, false);
}

/**
* Create a new session with an authorization header
*
* @deprecated v0.2.4
*
* @param string $url request url
* @param string $authKey authorization key
* @param string|array $put data as an associative array or urlencoded string
* @param array $headers list of additional http headers
* @param bool $initOnly if true the session won't be executed
*
* @return Put
*/
public static function withAuth($url, $authKey = "", $put = "", array $headers = [], $initOnly = false)
{
return new Put($url, $put, array_merge(["Authorization" => $authKey], $headers), $initOnly);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
}
],
"require": {
"php": ">7.0"
"php": ">=7.0",
"ext-curl": "*"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit eb81f05

Please sign in to comment.