From 315a39e6123b432449c3b6662ccc1d48c3ffd91d Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Thu, 30 Sep 2021 22:35:28 -0400 Subject: [PATCH 1/6] PSR-4 autoloading only --- composer.json | 1 - lib/Tinify/AccountException.php | 5 +++++ lib/Tinify/ClientException.php | 5 +++++ lib/Tinify/ConnectionException.php | 5 +++++ lib/Tinify/Exception.php | 5 ----- lib/Tinify/ServerException.php | 5 +++++ 6 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 lib/Tinify/AccountException.php create mode 100644 lib/Tinify/ClientException.php create mode 100644 lib/Tinify/ConnectionException.php create mode 100644 lib/Tinify/ServerException.php diff --git a/composer.json b/composer.json index 067d6e0..d4fc426 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,6 @@ }, "autoload": { - "files": ["lib/Tinify.php", "lib/Tinify/Exception.php"], "psr-4": {"Tinify\\": "lib/Tinify/"} } } diff --git a/lib/Tinify/AccountException.php b/lib/Tinify/AccountException.php new file mode 100644 index 0000000..7d4ec15 --- /dev/null +++ b/lib/Tinify/AccountException.php @@ -0,0 +1,5 @@ + Date: Mon, 20 Feb 2023 09:12:43 -0500 Subject: [PATCH 2/6] Move curl_mock.php after autoloader --- test/helper.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/helper.php b/test/helper.php index a2536ce..1d1b257 100644 --- a/test/helper.php +++ b/test/helper.php @@ -1,16 +1,16 @@ Date: Thu, 2 Mar 2023 09:51:48 -0500 Subject: [PATCH 3/6] Fix case --- test/base/test_case_1.php | 2 +- test/base/test_case_2.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/base/test_case_1.php b/test/base/test_case_1.php index 3a2082b..3755d57 100644 --- a/test/base/test_case_1.php +++ b/test/base/test_case_1.php @@ -3,7 +3,7 @@ abstract class TestCase_1 extends \PHPUnit\Framework\TestCase { protected function setUp() { Tinify\CurlMock::reset(); Tinify\setKey(NULL); - TInify\setProxy(NULL); + Tinify\setProxy(NULL); } protected function tearDown() { diff --git a/test/base/test_case_2.php b/test/base/test_case_2.php index b65bf1b..7c69890 100644 --- a/test/base/test_case_2.php +++ b/test/base/test_case_2.php @@ -3,7 +3,7 @@ abstract class TestCase_2 extends \PHPUnit\Framework\TestCase { protected function setUp(): void { Tinify\CurlMock::reset(); Tinify\setKey(NULL); - TInify\setProxy(NULL); + Tinify\setProxy(NULL); } protected function tearDown(): void { From f8f9caa0d3ae9c336c398f6e998b94cc7373746e Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Thu, 2 Mar 2023 09:52:14 -0500 Subject: [PATCH 4/6] Move curl_mock after autoloader --- test/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bootstrap.php b/test/bootstrap.php index 4877c42..2653d50 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -1,7 +1,7 @@ Date: Thu, 2 Mar 2023 10:05:37 -0500 Subject: [PATCH 5/6] Move Tinify\Tinify for proper autoloading and break out functions.php --- composer.json | 3 ++- lib/{ => Tinify}/Tinify.php | 46 +---------------------------------- lib/functions.php | 48 +++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 46 deletions(-) rename lib/{ => Tinify}/Tinify.php (58%) create mode 100644 lib/functions.php diff --git a/composer.json b/composer.json index e57e0ef..f544fed 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ }, "autoload": { - "psr-4": {"Tinify\\": "lib/Tinify/"} + "psr-4": {"Tinify\\": "lib/Tinify/"}, + "files": ["lib/functions.php"] } } diff --git a/lib/Tinify.php b/lib/Tinify/Tinify.php similarity index 58% rename from lib/Tinify.php rename to lib/Tinify/Tinify.php index 3c258f6..5b675c3 100644 --- a/lib/Tinify.php +++ b/lib/Tinify/Tinify.php @@ -2,9 +2,8 @@ namespace Tinify; -const VERSION = "1.6.1"; - class Tinify { + private static $key = NULL; private static $appIdentifier = NULL; private static $proxy = NULL; @@ -51,46 +50,3 @@ public static function setClient($client) { self::$client = $client; } } - -function setKey($key) { - return Tinify::setKey($key); -} - -function setAppIdentifier($appIdentifier) { - return Tinify::setAppIdentifier($appIdentifier); -} - -function setProxy($proxy) { - return Tinify::setProxy($proxy); -} - -function getCompressionCount() { - return Tinify::getCompressionCount(); -} - -function compressionCount() { - return Tinify::getCompressionCount(); -} - -function fromFile($path) { - return Source::fromFile($path); -} - -function fromBuffer($string) { - return Source::fromBuffer($string); -} - -function fromUrl($string) { - return Source::fromUrl($string); -} - -function validate() { - try { - Tinify::getClient()->request("post", "/shrink"); - } catch (AccountException $err) { - if ($err->status == 429) return true; - throw $err; - } catch (ClientException $err) { - return true; - } -} diff --git a/lib/functions.php b/lib/functions.php new file mode 100644 index 0000000..7db27ba --- /dev/null +++ b/lib/functions.php @@ -0,0 +1,48 @@ +request("post", "/shrink"); + } catch (AccountException $err) { + if ($err->status == 429) return true; + throw $err; + } catch (ClientException $err) { + return true; + } +} From e12d334f8927d0db50cd7ddafd0e1b42c55c896c Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Thu, 2 Mar 2023 10:14:28 -0500 Subject: [PATCH 6/6] Fix curl_mock for PHP 8.2 tests --- test/curl_mock.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/curl_mock.php b/test/curl_mock.php index 9008924..d326d59 100644 --- a/test/curl_mock.php +++ b/test/curl_mock.php @@ -17,6 +17,7 @@ class CurlMock { private static $version = array(); public $options = array(); + public $request; public $response; public $closed = false;