Skip to content

Commit 54bd45d

Browse files
Update Tinify client.
1 parent 2aa2ab8 commit 54bd45d

4 files changed

Lines changed: 517 additions & 913 deletions

File tree

composer.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vendor/tinify/Tinify.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
namespace Tinify;
44

5-
const VERSION = "1.3.0";
5+
const VERSION = "1.4.0";
66

77
class Tinify {
88
const AUTHENTICATED = true;
99
const ANONYMOUS = false;
1010

1111
private static $key = NULL;
1212
private static $appIdentifier = NULL;
13+
private static $proxy = NULL;
14+
1315
private static $compressionCount = NULL;
1416

1517
private static $client = NULL;
@@ -34,6 +36,11 @@ public static function setAppIdentifier($appIdentifier) {
3436
self::$client = NULL;
3537
}
3638

39+
public static function setProxy($proxy) {
40+
self::$proxy = $proxy;
41+
self::$client = NULL;
42+
}
43+
3744
public static function getCompressionCount() {
3845
return self::$compressionCount;
3946
}
@@ -48,7 +55,7 @@ public static function getClient($mode = self::AUTHENTICATED) {
4855
}
4956

5057
if (!self::$client) {
51-
self::$client = new Client(self::$key, self::$appIdentifier);
58+
self::$client = new Client(self::$key, self::$appIdentifier, self::$proxy);
5259
}
5360

5461
return self::$client;
@@ -75,6 +82,10 @@ function setAppIdentifier($appIdentifier) {
7582
return Tinify::setAppIdentifier($appIdentifier);
7683
}
7784

85+
function setProxy($proxy) {
86+
return Tinify::setProxy($proxy);
87+
}
88+
7889
function getCompressionCount() {
7990
return Tinify::getCompressionCount();
8091
}

src/vendor/tinify/Tinify/Client.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ private static function caBundle() {
1616
return __DIR__ . "/../data/cacert.pem";
1717
}
1818

19-
function __construct($key, $appIdentifier = NULL) {
19+
function __construct($key, $appIdentifier = NULL, $proxy = NULL) {
2020
$userAgent = join(" ", array_filter(array(self::userAgent(), $appIdentifier)));
21+
2122
$this->options = array(
2223
CURLOPT_BINARYTRANSFER => true,
2324
CURLOPT_RETURNTRANSFER => true,
@@ -27,9 +28,33 @@ function __construct($key, $appIdentifier = NULL) {
2728
CURLOPT_SSL_VERIFYPEER => true,
2829
CURLOPT_USERAGENT => $userAgent,
2930
);
31+
32+
if ($proxy) {
33+
$parts = parse_url($proxy);
34+
if (isset($parts["host"])) {
35+
$this->options[CURLOPT_PROXYTYPE] = CURLPROXY_HTTP;
36+
$this->options[CURLOPT_PROXY] = $parts["host"];
37+
} else {
38+
throw new ConnectionException("Invalid proxy");
39+
}
40+
41+
if (isset($parts["port"])) {
42+
$this->options[CURLOPT_PROXYPORT] = $parts["port"];
43+
}
44+
45+
$creds = "";
46+
if (isset($parts["user"])) $creds .= $parts["user"];
47+
if (isset($parts["pass"])) $creds .= ":" . $parts["pass"];
48+
49+
if ($creds) {
50+
$this->options[CURLOPT_PROXYAUTH] = CURLAUTH_ANY;
51+
$this->options[CURLOPT_PROXYUSERPWD] = $creds;
52+
}
53+
}
3054
}
3155

32-
function request($method, $url, $body = NULL, $header = array()) {
56+
function request($method, $url, $body = NULL) {
57+
$header = array();
3358
if (is_array($body)) {
3459
if (!empty($body)) {
3560
$body = json_encode($body);
@@ -40,6 +65,12 @@ function request($method, $url, $body = NULL, $header = array()) {
4065
}
4166

4267
$request = curl_init();
68+
if ($request === false || $request === null) {
69+
throw new ConnectionException(
70+
"Error while connecting: curl extension is not functional or disabled."
71+
);
72+
}
73+
4374
curl_setopt_array($request, $this->options);
4475

4576
$url = strtolower(substr($url, 0, 6)) == "https:" ? $url : self::API_ENDPOINT . $url;

0 commit comments

Comments
 (0)