Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},

"autoload": {
"files": ["lib/Tinify.php", "lib/Tinify/Exception.php"],
"psr-4": {"Tinify\\": "lib/Tinify/"}
"psr-4": {"Tinify\\": "lib/Tinify/"},
"files": ["lib/functions.php"]
}
}
5 changes: 5 additions & 0 deletions lib/Tinify/AccountException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace Tinify;

class AccountException extends Exception {}
5 changes: 5 additions & 0 deletions lib/Tinify/ClientException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace Tinify;

class ClientException extends Exception {}
5 changes: 5 additions & 0 deletions lib/Tinify/ConnectionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace Tinify;

class ConnectionException extends Exception {}
5 changes: 0 additions & 5 deletions lib/Tinify/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,3 @@ function __construct($message, $type = NULL, $status = NULL) {
}
}
}

class AccountException extends Exception {}
class ClientException extends Exception {}
class ServerException extends Exception {}
class ConnectionException extends Exception {}
5 changes: 5 additions & 0 deletions lib/Tinify/ServerException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace Tinify;

class ServerException extends Exception {}
46 changes: 1 addition & 45 deletions lib/Tinify.php → lib/Tinify/Tinify.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
48 changes: 48 additions & 0 deletions lib/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Tinify;

const VERSION = "1.6.1";

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;
}
}
2 changes: 1 addition & 1 deletion test/base/test_case_1.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion test/base/test_case_2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

require_once("curl_mock.php");
require_once("vendor" . DIRECTORY_SEPARATOR . "autoload.php");
require_once("curl_mock.php");


# Some PHPUnit glue to support testing PHP 5.4 and onwards together
Expand Down
1 change: 1 addition & 0 deletions test/curl_mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CurlMock {
private static $version = array();

public $options = array();
public $request;
public $response;
public $closed = false;

Expand Down