diff --git a/composer.json b/composer.json index 823856b..6283871 100755 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "ext-pdo": "*", "ext-curl": "*", "ext-redis": "*", - "utopia-php/database": "0.54.*" + "utopia-php/database": "0.53.*" }, "require-dev": { "phpunit/phpunit": "^9.4", diff --git a/composer.lock b/composer.lock index 8ab1de6..1525754 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7601e6576cde00888812fb6e2e732dbe", + "content-hash": "6522b9fb8652f6801bd7c5664430c672", "packages": [ { "name": "jean85/pretty-package-versions", @@ -266,16 +266,16 @@ }, { "name": "utopia-php/database", - "version": "0.54.0", + "version": "0.53.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "1e97fc8b212a8daf9b9a68244677ed34c9db143e" + "reference": "2e116d544b14e8b2edfcb5b793d214136ff64f42" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/1e97fc8b212a8daf9b9a68244677ed34c9db143e", - "reference": "1e97fc8b212a8daf9b9a68244677ed34c9db143e", + "url": "https://api.github.com/repos/utopia-php/database/zipball/2e116d544b14e8b2edfcb5b793d214136ff64f42", + "reference": "2e116d544b14e8b2edfcb5b793d214136ff64f42", "shasum": "" }, "require": { @@ -283,7 +283,7 @@ "ext-pdo": "*", "php": ">=8.0", "utopia-php/cache": "0.10.*", - "utopia-php/framework": "1.0.*", + "utopia-php/framework": "0.33.*", "utopia-php/mongo": "0.3.*" }, "require-dev": { @@ -294,7 +294,7 @@ "phpunit/phpunit": "9.6.*", "rregeer/phpunit-coverage-check": "0.3.*", "swoole/ide-helper": "5.1.3", - "utopia-php/cli": "0.19.*" + "utopia-php/cli": "0.14.*" }, "type": "library", "autoload": { @@ -316,84 +316,32 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.54.0" + "source": "https://github.com/utopia-php/database/tree/0.53.0" }, - "time": "2024-09-05T16:00:42+00:00" - }, - { - "name": "utopia-php/di", - "version": "0.1.0", - "source": { - "type": "git", - "url": "https://github.com/utopia-php/di.git", - "reference": "22490c95f7ac3898ed1c33f1b1b5dd577305ee31" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/utopia-php/di/zipball/22490c95f7ac3898ed1c33f1b1b5dd577305ee31", - "reference": "22490c95f7ac3898ed1c33f1b1b5dd577305ee31", - "shasum": "" - }, - "require": { - "php": ">=8.2" - }, - "require-dev": { - "laravel/pint": "^1.2", - "phpbench/phpbench": "^1.2", - "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.5.25", - "swoole/ide-helper": "4.8.3" - }, - "type": "library", - "autoload": { - "psr-4": { - "Utopia\\": "src/", - "Tests\\E2E\\": "tests/e2e" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "A simple and lite library for managing dependency injections", - "keywords": [ - "framework", - "http", - "php", - "upf" - ], - "support": { - "issues": "https://github.com/utopia-php/di/issues", - "source": "https://github.com/utopia-php/di/tree/0.1.0" - }, - "time": "2024-08-08T14:35:19+00:00" + "time": "2024-08-30T04:32:56+00:00" }, { "name": "utopia-php/framework", - "version": "1.0.0", + "version": "0.33.8", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "cc880ec41f7f163d4f9956fec26cc6be51b412cf" + "reference": "a7f577540a25cb90896fef2b64767bf8d700f3c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/cc880ec41f7f163d4f9956fec26cc6be51b412cf", - "reference": "cc880ec41f7f163d4f9956fec26cc6be51b412cf", + "url": "https://api.github.com/repos/utopia-php/http/zipball/a7f577540a25cb90896fef2b64767bf8d700f3c5", + "reference": "a7f577540a25cb90896fef2b64767bf8d700f3c5", "shasum": "" }, "require": { - "ext-swoole": "*", - "php": ">=8.0", - "utopia-php/servers": "0.1.*" + "php": ">=8.0" }, "require-dev": { - "ext-xdebug": "*", "laravel/pint": "^1.2", "phpbench/phpbench": "^1.2", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.5.25", - "swoole/ide-helper": "4.8.3" + "phpunit/phpunit": "^9.5.25" }, "type": "library", "autoload": { @@ -405,18 +353,17 @@ "license": [ "MIT" ], - "description": "A simple, light and advanced PHP HTTP framework", + "description": "A simple, light and advanced PHP framework", "keywords": [ "framework", - "http", "php", "upf" ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/1.0.0" + "source": "https://github.com/utopia-php/http/tree/0.33.8" }, - "time": "2024-09-05T15:38:08+00:00" + "time": "2024-08-15T14:10:09+00:00" }, { "name": "utopia-php/mongo", @@ -477,74 +424,21 @@ "source": "https://github.com/utopia-php/mongo/tree/0.3.1" }, "time": "2023-09-01T17:25:28+00:00" - }, - { - "name": "utopia-php/servers", - "version": "0.1.0", - "source": { - "type": "git", - "url": "https://github.com/utopia-php/servers.git", - "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", - "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", - "shasum": "" - }, - "require": { - "php": ">=8.0", - "utopia-php/di": "0.1.*" - }, - "require-dev": { - "laravel/pint": "^0.2.3", - "phpstan/phpstan": "^1.8", - "phpunit/phpunit": "^9.5.5" - }, - "type": "library", - "autoload": { - "psr-4": { - "Utopia\\Servers\\": "src/Servers" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Team Appwrite", - "email": "team@appwrite.io" - } - ], - "description": "A base library for building Utopia style servers.", - "keywords": [ - "framework", - "php", - "servers", - "upf", - "utopia" - ], - "support": { - "issues": "https://github.com/utopia-php/servers/issues", - "source": "https://github.com/utopia-php/servers/tree/0.1.0" - }, - "time": "2024-08-08T14:31:39+00:00" } ], "packages-dev": [ { "name": "doctrine/annotations", - "version": "2.0.2", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "901c2ee5d26eb64ff43c47976e114bf00843acf7" + "reference": "e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/901c2ee5d26eb64ff43c47976e114bf00843acf7", - "reference": "901c2ee5d26eb64ff43c47976e114bf00843acf7", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f", + "reference": "e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f", "shasum": "" }, "require": { @@ -556,10 +450,10 @@ "require-dev": { "doctrine/cache": "^2.0", "doctrine/coding-standard": "^10", - "phpstan/phpstan": "^1.10.28", + "phpstan/phpstan": "^1.8.0", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "symfony/cache": "^5.4 || ^6.4 || ^7", - "vimeo/psalm": "^4.30 || ^5.14" + "symfony/cache": "^5.4 || ^6", + "vimeo/psalm": "^4.10" }, "suggest": { "php": "PHP 8.0 or higher comes with attributes, a native replacement for annotations" @@ -605,9 +499,9 @@ ], "support": { "issues": "https://github.com/doctrine/annotations/issues", - "source": "https://github.com/doctrine/annotations/tree/2.0.2" + "source": "https://github.com/doctrine/annotations/tree/2.0.1" }, - "time": "2024-09-05T10:17:24+00:00" + "time": "2023-02-02T22:02:53+00:00" }, { "name": "doctrine/instantiator", @@ -1261,16 +1155,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.1", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2" + "reference": "384af967d35b2162f69526c7276acadce534d0e1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", - "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/384af967d35b2162f69526c7276acadce534d0e1", + "reference": "384af967d35b2162f69526c7276acadce534d0e1", "shasum": "" }, "require": { @@ -1315,7 +1209,7 @@ "type": "github" } ], - "time": "2024-09-03T19:55:22+00:00" + "time": "2024-08-27T09:18:05+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2920,16 +2814,16 @@ }, { "name": "symfony/console", - "version": "v7.1.4", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111" + "reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/1eed7af6961d763e7832e874d7f9b21c3ea9c111", - "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111", + "url": "https://api.github.com/repos/symfony/console/zipball/cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9", + "reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9", "shasum": "" }, "require": { @@ -2993,7 +2887,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.1.4" + "source": "https://github.com/symfony/console/tree/v7.1.3" }, "funding": [ { @@ -3009,7 +2903,7 @@ "type": "tidelift" } ], - "time": "2024-08-15T22:48:53+00:00" + "time": "2024-07-26T12:41:01+00:00" }, { "name": "symfony/deprecation-contracts", @@ -3146,16 +3040,16 @@ }, { "name": "symfony/finder", - "version": "v7.1.4", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "d95bbf319f7d052082fb7af147e0f835a695e823" + "reference": "717c6329886f32dc65e27461f80f2a465412fdca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/d95bbf319f7d052082fb7af147e0f835a695e823", - "reference": "d95bbf319f7d052082fb7af147e0f835a695e823", + "url": "https://api.github.com/repos/symfony/finder/zipball/717c6329886f32dc65e27461f80f2a465412fdca", + "reference": "717c6329886f32dc65e27461f80f2a465412fdca", "shasum": "" }, "require": { @@ -3190,7 +3084,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.1.4" + "source": "https://github.com/symfony/finder/tree/v7.1.3" }, "funding": [ { @@ -3206,7 +3100,7 @@ "type": "tidelift" } ], - "time": "2024-08-13T14:28:19+00:00" + "time": "2024-07-24T07:08:44+00:00" }, { "name": "symfony/options-resolver", @@ -3739,16 +3633,16 @@ }, { "name": "symfony/string", - "version": "v7.1.4", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b" + "reference": "ea272a882be7f20cad58d5d78c215001617b7f07" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/6cd670a6d968eaeb1c77c2e76091c45c56bc367b", - "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b", + "url": "https://api.github.com/repos/symfony/string/zipball/ea272a882be7f20cad58d5d78c215001617b7f07", + "reference": "ea272a882be7f20cad58d5d78c215001617b7f07", "shasum": "" }, "require": { @@ -3806,7 +3700,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.1.4" + "source": "https://github.com/symfony/string/tree/v7.1.3" }, "funding": [ { @@ -3822,7 +3716,7 @@ "type": "tidelift" } ], - "time": "2024-08-12T09:59:40+00:00" + "time": "2024-07-22T10:25:37+00:00" }, { "name": "theseer/tokenizer", @@ -3925,7 +3819,7 @@ } ], "aliases": [], - "minimum-stability": "RC", + "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, diff --git a/src/Abuse/Adapters/Database/TimeLimit.php b/src/Abuse/Adapters/Database/TimeLimit.php index 2527442..0d40829 100644 --- a/src/Abuse/Adapters/Database/TimeLimit.php +++ b/src/Abuse/Adapters/Database/TimeLimit.php @@ -10,7 +10,8 @@ use Utopia\Database\Exception\Duplicate; use Utopia\Database\Exception\Structure; use Utopia\Database\Query; -use Utopia\Http\Exception; +use Utopia\Database\Validator\Authorization; +use Utopia\Exception; class TimeLimit extends TimeLimitAdapter { @@ -127,7 +128,7 @@ protected function count(string $key, string $datetime): int } /** @var array $result */ - $result = $this->db->getAuthorization()->skip(function () use ($key, $datetime) { + $result = Authorization::skip(function () use ($key, $datetime) { return $this->db->find(TimeLimit::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), @@ -159,7 +160,7 @@ protected function hit(string $key, string $datetime): void return; } - $this->db->getAuthorization()->skip(function () use ($datetime, $key) { + Authorization::skip(function () use ($datetime, $key) { $data = $this->db->findOne(TimeLimit::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), @@ -216,7 +217,7 @@ protected function hit(string $key, string $datetime): void public function getLogs(?int $offset = null, ?int $limit = 25): array { /** @var array $results */ - $results = $this->db->getAuthorization()->skip(function () use ($offset, $limit) { + $results = Authorization::skip(function () use ($offset, $limit) { $queries = []; $queries[] = Query::orderDesc(''); @@ -243,7 +244,7 @@ public function getLogs(?int $offset = null, ?int $limit = 25): array */ public function cleanup(string $datetime): bool { - $this->db->getAuthorization()->skip(function () use ($datetime) { + Authorization::skip(function () use ($datetime) { do { $documents = $this->db->find(TimeLimit::COLLECTION, [ Query::lessThan('time', $datetime), @@ -257,70 +258,4 @@ public function cleanup(string $datetime): bool return true; } - - /** - * Check - * - * Checks if number of counts is bigger or smaller than current limit. limit 0 is equal to unlimited - * - * @return bool - * - * @throws \Throwable - */ - public function check(): bool - { - if (0 == $this->limit) { - return false; - } - - $key = $this->parseKey(); - - if ($this->limit > $this->count($key, $this->time)) { - $this->hit($key, $this->time); - - return false; - } - - return true; - } - - /** - * Remaining - * - * Returns the number of current remaining counts - * - * @return int - * - * @throws \Exception - */ - public function remaining(): int - { - $left = $this->limit - ($this->count($this->parseKey(), $this->time) + 1); // Add one because we need to say how many left not how many done - - return (0 > $left) ? 0 : $left; - } - - /** - * Limit - * - * Return the limit integer - * - * @return int - */ - public function limit(): int - { - return $this->limit; - } - - /** - * Time - * - * Return the Datetime - * - * @return string - */ - public function time(): string - { - return $this->time; - } } diff --git a/tests/Abuse/Base.php b/tests/Abuse/Base.php old mode 100755 new mode 100644 diff --git a/tests/Abuse/Bench/Database/TimeLimitBench.php b/tests/Abuse/Bench/Database/TimeLimitBench.php index 8f2a5be..e2a110c 100644 --- a/tests/Abuse/Bench/Database/TimeLimitBench.php +++ b/tests/Abuse/Bench/Database/TimeLimitBench.php @@ -10,8 +10,8 @@ use Utopia\Database\Adapter\MariaDB; use Utopia\Database\Adapter\MySQL; use Utopia\Database\Database; +use Utopia\Exception; use Utopia\Tests\Bench\Base; -use Utopia\Http\Exception; class TimeLimitBench extends Base { diff --git a/tests/Abuse/DatabaseTest.php b/tests/Abuse/DatabaseTest.php index fc6c1ed..b3820e6 100755 --- a/tests/Abuse/DatabaseTest.php +++ b/tests/Abuse/DatabaseTest.php @@ -12,7 +12,7 @@ use Utopia\Database\Adapter\MySQL; use Utopia\Database\Database; use Utopia\Database\DateTime; -use Utopia\Http\Exception; +use Utopia\Exception; class DatabaseTest extends Base { diff --git a/tests/Abuse/RedisTest.php b/tests/Abuse/RedisTest.php index 4ecd92d..517ee94 100644 --- a/tests/Abuse/RedisTest.php +++ b/tests/Abuse/RedisTest.php @@ -7,7 +7,7 @@ use Utopia\Abuse\Abuse; use Utopia\Abuse\Adapter; use Utopia\Abuse\Adapters\Redis\TimeLimit; -use Utopia\Http\Exception; +use Utopia\Exception; class RedisTest extends Base {