From b73e9e8500fada78ff4104e9b625be2dbf38c1ca Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 18 Dec 2025 13:39:22 +0530 Subject: [PATCH] feat: remove validators and use utopia validators lib --- composer.json | 3 +- composer.lock | 361 ++++++++++++++----------- docs/Getting-Starting-Guide.md | 2 +- example/src/server.php | 2 +- src/Http/Hook.php | 2 + src/Http/Http.php | 2 + src/Http/Validator.php | 57 ---- src/Http/Validator/AllOf.php | 86 ------ src/Http/Validator/AnyOf.php | 87 ------ src/Http/Validator/ArrayList.php | 116 -------- src/Http/Validator/Assoc.php | 88 ------ src/Http/Validator/Boolean.php | 94 ------- src/Http/Validator/Domain.php | 78 ------ src/Http/Validator/FloatValidator.php | 88 ------ src/Http/Validator/HexColor.php | 53 ---- src/Http/Validator/Host.php | 82 ------ src/Http/Validator/Hostname.php | 114 -------- src/Http/Validator/IP.php | 113 -------- src/Http/Validator/Integer.php | 88 ------ src/Http/Validator/JSON.php | 59 ---- src/Http/Validator/NoneOf.php | 88 ------ src/Http/Validator/Nullable.php | 73 ----- src/Http/Validator/Numeric.php | 66 ----- src/Http/Validator/Range.php | 149 ---------- src/Http/Validator/Text.php | 138 ---------- src/Http/Validator/URL.php | 86 ------ src/Http/Validator/WhiteList.php | 119 -------- src/Http/Validator/Wildcard.php | 62 ----- tests/HookTest.php | 4 +- tests/HttpTest.php | 2 +- tests/RouteTest.php | 2 +- tests/Validator/ArrayListTest.php | 52 ---- tests/Validator/AssocTest.php | 43 --- tests/Validator/BooleanTest.php | 46 ---- tests/Validator/DomainTest.php | 37 --- tests/Validator/FloatValidatorTest.php | 39 --- tests/Validator/HexColorTest.php | 26 -- tests/Validator/HostTest.php | 30 -- tests/Validator/HostnameTest.php | 106 -------- tests/Validator/IPTest.php | 67 ----- tests/Validator/IntegerTest.php | 36 --- tests/Validator/JSONTest.php | 28 -- tests/Validator/MultipleOfTest.php | 61 ----- tests/Validator/NullableTest.php | 22 -- tests/Validator/NumericTest.php | 24 -- tests/Validator/RangeTest.php | 60 ---- tests/Validator/TextTest.php | 88 ------ tests/Validator/URLTest.php | 43 --- tests/Validator/WhiteListTest.php | 58 ---- tests/Validator/WildcardTest.php | 21 -- tests/e2e/init.php | 2 +- 51 files changed, 219 insertions(+), 3034 deletions(-) delete mode 100755 src/Http/Validator.php delete mode 100644 src/Http/Validator/AllOf.php delete mode 100644 src/Http/Validator/AnyOf.php delete mode 100644 src/Http/Validator/ArrayList.php delete mode 100644 src/Http/Validator/Assoc.php delete mode 100644 src/Http/Validator/Boolean.php delete mode 100644 src/Http/Validator/Domain.php delete mode 100755 src/Http/Validator/FloatValidator.php delete mode 100644 src/Http/Validator/HexColor.php delete mode 100755 src/Http/Validator/Host.php delete mode 100644 src/Http/Validator/Hostname.php delete mode 100644 src/Http/Validator/IP.php delete mode 100755 src/Http/Validator/Integer.php delete mode 100644 src/Http/Validator/JSON.php delete mode 100644 src/Http/Validator/NoneOf.php delete mode 100644 src/Http/Validator/Nullable.php delete mode 100755 src/Http/Validator/Numeric.php delete mode 100755 src/Http/Validator/Range.php delete mode 100644 src/Http/Validator/Text.php delete mode 100644 src/Http/Validator/URL.php delete mode 100755 src/Http/Validator/WhiteList.php delete mode 100644 src/Http/Validator/Wildcard.php delete mode 100755 tests/Validator/ArrayListTest.php delete mode 100755 tests/Validator/AssocTest.php delete mode 100755 tests/Validator/BooleanTest.php delete mode 100644 tests/Validator/DomainTest.php delete mode 100755 tests/Validator/FloatValidatorTest.php delete mode 100755 tests/Validator/HexColorTest.php delete mode 100644 tests/Validator/HostTest.php delete mode 100755 tests/Validator/HostnameTest.php delete mode 100644 tests/Validator/IPTest.php delete mode 100755 tests/Validator/IntegerTest.php delete mode 100755 tests/Validator/JSONTest.php delete mode 100644 tests/Validator/MultipleOfTest.php delete mode 100755 tests/Validator/NullableTest.php delete mode 100755 tests/Validator/NumericTest.php delete mode 100755 tests/Validator/RangeTest.php delete mode 100755 tests/Validator/TextTest.php delete mode 100644 tests/Validator/URLTest.php delete mode 100755 tests/Validator/WhiteListTest.php delete mode 100644 tests/Validator/WildcardTest.php diff --git a/composer.json b/composer.json index 377787e6..e5953bc4 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ }, "require": { "php": ">=8.0", - "ext-swoole": "*" + "ext-swoole": "*", + "utopia-php/validators": "0.1.*" }, "require-dev": { "phpunit/phpunit": "^9.5.25", diff --git a/composer.lock b/composer.lock index abee3f7b..b68b4ff5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,54 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "47587a7a55803f5b0fdf225267c03f03", - "packages": [], + "content-hash": "3851bd0696173988209c33d95ad3fd35", + "packages": [ + { + "name": "utopia-php/validators", + "version": "0.1.0", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/validators.git", + "reference": "5c57d5b6cf964f8981807c1d3ea8df620c869080" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/validators/zipball/5c57d5b6cf964f8981807c1d3ea8df620c869080", + "reference": "5c57d5b6cf964f8981807c1d3ea8df620c869080", + "shasum": "" + }, + "require": { + "php": ">=8.0" + }, + "require-dev": { + "laravel/pint": "1.*", + "phpstan/phpstan": "1.*", + "phpunit/phpunit": "11.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A lightweight collection of reusable validators for Utopia projects", + "keywords": [ + "php", + "utopia", + "validation", + "validator" + ], + "support": { + "issues": "https://github.com/utopia-php/validators/issues", + "source": "https://github.com/utopia-php/validators/tree/0.1.0" + }, + "time": "2025-11-18T11:05:46+00:00" + } + ], "packages-dev": [ { "name": "doctrine/annotations", @@ -81,6 +127,7 @@ "issues": "https://github.com/doctrine/annotations/issues", "source": "https://github.com/doctrine/annotations/tree/2.0.2" }, + "abandoned": true, "time": "2024-09-05T10:17:24+00:00" }, { @@ -232,16 +279,16 @@ }, { "name": "laravel/pint", - "version": "v1.24.0", + "version": "v1.26.0", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "0345f3b05f136801af8c339f9d16ef29e6b4df8a" + "reference": "69dcca060ecb15e4b564af63d1f642c81a241d6f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/0345f3b05f136801af8c339f9d16ef29e6b4df8a", - "reference": "0345f3b05f136801af8c339f9d16ef29e6b4df8a", + "url": "https://api.github.com/repos/laravel/pint/zipball/69dcca060ecb15e4b564af63d1f642c81a241d6f", + "reference": "69dcca060ecb15e4b564af63d1f642c81a241d6f", "shasum": "" }, "require": { @@ -252,22 +299,19 @@ "php": "^8.2.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.82.2", - "illuminate/view": "^11.45.1", - "larastan/larastan": "^3.5.0", - "laravel-zero/framework": "^11.45.0", + "friendsofphp/php-cs-fixer": "^3.90.0", + "illuminate/view": "^12.40.1", + "larastan/larastan": "^3.8.0", + "laravel-zero/framework": "^12.0.4", "mockery/mockery": "^1.6.12", - "nunomaduro/termwind": "^2.3.1", - "pestphp/pest": "^2.36.0" + "nunomaduro/termwind": "^2.3.3", + "pestphp/pest": "^3.8.4" }, "bin": [ "builds/pint" ], "type": "project", "autoload": { - "files": [ - "overrides/Runner/Parallel/ProcessFactory.php" - ], "psr-4": { "App\\": "app/", "Database\\Seeders\\": "database/seeders/", @@ -287,6 +331,7 @@ "description": "An opinionated code formatter for PHP.", "homepage": "https://laravel.com", "keywords": [ + "dev", "format", "formatter", "lint", @@ -297,7 +342,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2025-07-10T18:09:32+00:00" + "time": "2025-11-25T21:15:52+00:00" }, { "name": "myclabs/deep-copy", @@ -361,16 +406,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.6.1", + "version": "v5.7.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2" + "reference": "dca41cd15c2ac9d055ad70dbfd011130757d1f82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2", - "reference": "f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/dca41cd15c2ac9d055ad70dbfd011130757d1f82", + "reference": "dca41cd15c2ac9d055ad70dbfd011130757d1f82", "shasum": "" }, "require": { @@ -413,9 +458,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.6.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.7.0" }, - "time": "2025-08-13T20:13:15+00:00" + "time": "2025-12-06T11:56:16+00:00" }, { "name": "phar-io/manifest", @@ -537,24 +582,24 @@ }, { "name": "phpbench/container", - "version": "2.2.2", + "version": "2.2.3", "source": { "type": "git", "url": "https://github.com/phpbench/container.git", - "reference": "a59b929e00b87b532ca6d0edd8eca0967655af33" + "reference": "0c7b2d36c1ea53fe27302fb8873ded7172047196" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpbench/container/zipball/a59b929e00b87b532ca6d0edd8eca0967655af33", - "reference": "a59b929e00b87b532ca6d0edd8eca0967655af33", + "url": "https://api.github.com/repos/phpbench/container/zipball/0c7b2d36c1ea53fe27302fb8873ded7172047196", + "reference": "0c7b2d36c1ea53fe27302fb8873ded7172047196", "shasum": "" }, "require": { "psr/container": "^1.0|^2.0", - "symfony/options-resolver": "^4.2 || ^5.0 || ^6.0 || ^7.0" + "symfony/options-resolver": "^4.2 || ^5.0 || ^6.0 || ^7.0 || ^8.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.16", + "php-cs-fixer/shim": "^3.89", "phpstan/phpstan": "^0.12.52", "phpunit/phpunit": "^8" }, @@ -582,22 +627,22 @@ "description": "Simple, configurable, service container.", "support": { "issues": "https://github.com/phpbench/container/issues", - "source": "https://github.com/phpbench/container/tree/2.2.2" + "source": "https://github.com/phpbench/container/tree/2.2.3" }, - "time": "2023-10-30T13:38:26+00:00" + "time": "2025-11-06T09:05:13+00:00" }, { "name": "phpbench/phpbench", - "version": "1.4.1", + "version": "1.4.3", "source": { "type": "git", "url": "https://github.com/phpbench/phpbench.git", - "reference": "78cd98a9aa34e0f8f80ca01972a8b88d2c30194b" + "reference": "b641dde59d969ea42eed70a39f9b51950bc96878" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpbench/phpbench/zipball/78cd98a9aa34e0f8f80ca01972a8b88d2c30194b", - "reference": "78cd98a9aa34e0f8f80ca01972a8b88d2c30194b", + "url": "https://api.github.com/repos/phpbench/phpbench/zipball/b641dde59d969ea42eed70a39f9b51950bc96878", + "reference": "b641dde59d969ea42eed70a39f9b51950bc96878", "shasum": "" }, "require": { @@ -612,26 +657,26 @@ "phpbench/container": "^2.2", "psr/log": "^1.1 || ^2.0 || ^3.0", "seld/jsonlint": "^1.1", - "symfony/console": "^6.1 || ^7.0", - "symfony/filesystem": "^6.1 || ^7.0", - "symfony/finder": "^6.1 || ^7.0", - "symfony/options-resolver": "^6.1 || ^7.0", - "symfony/process": "^6.1 || ^7.0", + "symfony/console": "^6.1 || ^7.0 || ^8.0", + "symfony/filesystem": "^6.1 || ^7.0 || ^8.0", + "symfony/finder": "^6.1 || ^7.0 || ^8.0", + "symfony/options-resolver": "^6.1 || ^7.0 || ^8.0", + "symfony/process": "^6.1 || ^7.0 || ^8.0", "webmozart/glob": "^4.6" }, "require-dev": { "dantleech/invoke": "^2.0", "ergebnis/composer-normalize": "^2.39", - "friendsofphp/php-cs-fixer": "^3.0", "jangregor/phpstan-prophecy": "^1.0", - "phpspec/prophecy": "dev-master", + "php-cs-fixer/shim": "^3.9", + "phpspec/prophecy": "^1.22", "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.0", "phpstan/phpstan-phpunit": "^1.0", "phpunit/phpunit": "^10.4 || ^11.0", "rector/rector": "^1.2", - "symfony/error-handler": "^6.1 || ^7.0", - "symfony/var-dumper": "^6.1 || ^7.0" + "symfony/error-handler": "^6.1 || ^7.0 || ^8.0", + "symfony/var-dumper": "^6.1 || ^7.0 || ^8.0" }, "suggest": { "ext-xdebug": "For Xdebug profiling extension." @@ -674,7 +719,7 @@ ], "support": { "issues": "https://github.com/phpbench/phpbench/issues", - "source": "https://github.com/phpbench/phpbench/tree/1.4.1" + "source": "https://github.com/phpbench/phpbench/tree/1.4.3" }, "funding": [ { @@ -682,20 +727,15 @@ "type": "github" } ], - "time": "2025-03-12T08:01:40+00:00" + "time": "2025-11-06T19:07:31+00:00" }, { "name": "phpstan/phpstan", - "version": "1.12.28", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpstan.git", - "reference": "fcf8b71aeab4e1a1131d1783cef97b23a51b87a9" - }, + "version": "1.12.32", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/fcf8b71aeab4e1a1131d1783cef97b23a51b87a9", - "reference": "fcf8b71aeab4e1a1131d1783cef97b23a51b87a9", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/2770dcdf5078d0b0d53f94317e06affe88419aa8", + "reference": "2770dcdf5078d0b0d53f94317e06affe88419aa8", "shasum": "" }, "require": { @@ -740,7 +780,7 @@ "type": "github" } ], - "time": "2025-07-17T17:15:39+00:00" + "time": "2025-09-30T10:16:31+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1063,16 +1103,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.25", + "version": "9.6.31", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "049c011e01be805202d8eebedef49f769a8ec7b7" + "reference": "945d0b7f346a084ce5549e95289962972c4272e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/049c011e01be805202d8eebedef49f769a8ec7b7", - "reference": "049c011e01be805202d8eebedef49f769a8ec7b7", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/945d0b7f346a084ce5549e95289962972c4272e5", + "reference": "945d0b7f346a084ce5549e95289962972c4272e5", "shasum": "" }, "require": { @@ -1097,7 +1137,7 @@ "sebastian/comparator": "^4.0.9", "sebastian/diff": "^4.0.6", "sebastian/environment": "^5.1.5", - "sebastian/exporter": "^4.0.6", + "sebastian/exporter": "^4.0.8", "sebastian/global-state": "^5.0.8", "sebastian/object-enumerator": "^4.0.4", "sebastian/resource-operations": "^3.0.4", @@ -1146,7 +1186,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.25" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.31" }, "funding": [ { @@ -1170,7 +1210,7 @@ "type": "tidelift" } ], - "time": "2025-08-20T14:38:31+00:00" + "time": "2025-12-06T07:45:52+00:00" }, { "name": "psr/cache", @@ -1765,16 +1805,16 @@ }, { "name": "sebastian/exporter", - "version": "4.0.6", + "version": "4.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72" + "reference": "14c6ba52f95a36c3d27c835d65efc7123c446e8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/78c00df8f170e02473b682df15bfcdacc3d32d72", - "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/14c6ba52f95a36c3d27c835d65efc7123c446e8c", + "reference": "14c6ba52f95a36c3d27c835d65efc7123c446e8c", "shasum": "" }, "require": { @@ -1830,15 +1870,27 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.6" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.8" }, "funding": [ { "url": "https://github.com/sebastianbergmann", "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/exporter", + "type": "tidelift" } ], - "time": "2024-03-02T06:33:00+00:00" + "time": "2025-09-24T06:03:27+00:00" }, { "name": "sebastian/global-state", @@ -2431,47 +2483,39 @@ }, { "name": "symfony/console", - "version": "v7.3.2", + "version": "v8.0.1", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "5f360ebc65c55265a74d23d7fe27f957870158a1" + "reference": "fcb73f69d655b48fcb894a262f074218df08bd58" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/5f360ebc65c55265a74d23d7fe27f957870158a1", - "reference": "5f360ebc65c55265a74d23d7fe27f957870158a1", + "url": "https://api.github.com/repos/symfony/console/zipball/fcb73f69d655b48fcb894a262f074218df08bd58", + "reference": "fcb73f69d655b48fcb894a262f074218df08bd58", "shasum": "" }, "require": { - "php": ">=8.2", - "symfony/deprecation-contracts": "^2.5|^3", - "symfony/polyfill-mbstring": "~1.0", + "php": ">=8.4", + "symfony/polyfill-mbstring": "^1.0", "symfony/service-contracts": "^2.5|^3", - "symfony/string": "^7.2" - }, - "conflict": { - "symfony/dependency-injection": "<6.4", - "symfony/dotenv": "<6.4", - "symfony/event-dispatcher": "<6.4", - "symfony/lock": "<6.4", - "symfony/process": "<6.4" + "symfony/string": "^7.4|^8.0" }, "provide": { "psr/log-implementation": "1.0|2.0|3.0" }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/config": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/lock": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0", - "symfony/stopwatch": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0" + "symfony/config": "^7.4|^8.0", + "symfony/dependency-injection": "^7.4|^8.0", + "symfony/event-dispatcher": "^7.4|^8.0", + "symfony/http-foundation": "^7.4|^8.0", + "symfony/http-kernel": "^7.4|^8.0", + "symfony/lock": "^7.4|^8.0", + "symfony/messenger": "^7.4|^8.0", + "symfony/process": "^7.4|^8.0", + "symfony/stopwatch": "^7.4|^8.0", + "symfony/var-dumper": "^7.4|^8.0" }, "type": "library", "autoload": { @@ -2505,7 +2549,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.3.2" + "source": "https://github.com/symfony/console/tree/v8.0.1" }, "funding": [ { @@ -2525,7 +2569,7 @@ "type": "tidelift" } ], - "time": "2025-07-30T17:13:41+00:00" + "time": "2025-12-05T15:25:33+00:00" }, { "name": "symfony/deprecation-contracts", @@ -2596,25 +2640,25 @@ }, { "name": "symfony/filesystem", - "version": "v7.3.2", + "version": "v8.0.1", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "edcbb768a186b5c3f25d0643159a787d3e63b7fd" + "reference": "d937d400b980523dc9ee946bb69972b5e619058d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/edcbb768a186b5c3f25d0643159a787d3e63b7fd", - "reference": "edcbb768a186b5c3f25d0643159a787d3e63b7fd", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/d937d400b980523dc9ee946bb69972b5e619058d", + "reference": "d937d400b980523dc9ee946bb69972b5e619058d", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.4", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-mbstring": "~1.8" }, "require-dev": { - "symfony/process": "^6.4|^7.0" + "symfony/process": "^7.4|^8.0" }, "type": "library", "autoload": { @@ -2642,7 +2686,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v7.3.2" + "source": "https://github.com/symfony/filesystem/tree/v8.0.1" }, "funding": [ { @@ -2662,27 +2706,27 @@ "type": "tidelift" } ], - "time": "2025-07-07T08:17:47+00:00" + "time": "2025-12-01T09:13:36+00:00" }, { "name": "symfony/finder", - "version": "v7.3.2", + "version": "v8.0.0", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "2a6614966ba1074fa93dae0bc804227422df4dfe" + "reference": "7598dd5770580fa3517ec83e8da0c9b9e01f4291" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/2a6614966ba1074fa93dae0bc804227422df4dfe", - "reference": "2a6614966ba1074fa93dae0bc804227422df4dfe", + "url": "https://api.github.com/repos/symfony/finder/zipball/7598dd5770580fa3517ec83e8da0c9b9e01f4291", + "reference": "7598dd5770580fa3517ec83e8da0c9b9e01f4291", "shasum": "" }, "require": { - "php": ">=8.2" + "php": ">=8.4" }, "require-dev": { - "symfony/filesystem": "^6.4|^7.0" + "symfony/filesystem": "^7.4|^8.0" }, "type": "library", "autoload": { @@ -2710,7 +2754,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.3.2" + "source": "https://github.com/symfony/finder/tree/v8.0.0" }, "funding": [ { @@ -2730,24 +2774,24 @@ "type": "tidelift" } ], - "time": "2025-07-15T13:41:35+00:00" + "time": "2025-11-05T14:36:47+00:00" }, { "name": "symfony/options-resolver", - "version": "v7.3.2", + "version": "v8.0.0", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "119bcf13e67dbd188e5dbc74228b1686f66acd37" + "reference": "d2b592535ffa6600c265a3893a7f7fd2bad82dd7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/119bcf13e67dbd188e5dbc74228b1686f66acd37", - "reference": "119bcf13e67dbd188e5dbc74228b1686f66acd37", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/d2b592535ffa6600c265a3893a7f7fd2bad82dd7", + "reference": "d2b592535ffa6600c265a3893a7f7fd2bad82dd7", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.4", "symfony/deprecation-contracts": "^2.5|^3" }, "type": "library", @@ -2781,7 +2825,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v7.3.2" + "source": "https://github.com/symfony/options-resolver/tree/v8.0.0" }, "funding": [ { @@ -2801,7 +2845,7 @@ "type": "tidelift" } ], - "time": "2025-07-15T11:36:08+00:00" + "time": "2025-11-12T15:55:31+00:00" }, { "name": "symfony/polyfill-ctype", @@ -3140,20 +3184,20 @@ }, { "name": "symfony/process", - "version": "v7.3.0", + "version": "v8.0.0", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "40c295f2deb408d5e9d2d32b8ba1dd61e36f05af" + "reference": "a0a750500c4ce900d69ba4e9faf16f82c10ee149" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/40c295f2deb408d5e9d2d32b8ba1dd61e36f05af", - "reference": "40c295f2deb408d5e9d2d32b8ba1dd61e36f05af", + "url": "https://api.github.com/repos/symfony/process/zipball/a0a750500c4ce900d69ba4e9faf16f82c10ee149", + "reference": "a0a750500c4ce900d69ba4e9faf16f82c10ee149", "shasum": "" }, "require": { - "php": ">=8.2" + "php": ">=8.4" }, "type": "library", "autoload": { @@ -3181,7 +3225,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.3.0" + "source": "https://github.com/symfony/process/tree/v8.0.0" }, "funding": [ { @@ -3192,25 +3236,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2025-04-17T09:11:12+00:00" + "time": "2025-10-16T16:25:44+00:00" }, { "name": "symfony/service-contracts", - "version": "v3.6.0", + "version": "v3.6.1", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4" + "reference": "45112560a3ba2d715666a509a0bc9521d10b6c43" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f021b05a130d35510bd6b25fe9053c2a8a15d5d4", - "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/45112560a3ba2d715666a509a0bc9521d10b6c43", + "reference": "45112560a3ba2d715666a509a0bc9521d10b6c43", "shasum": "" }, "require": { @@ -3264,7 +3312,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.6.0" + "source": "https://github.com/symfony/service-contracts/tree/v3.6.1" }, "funding": [ { @@ -3275,44 +3323,47 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2025-04-25T09:37:31+00:00" + "time": "2025-07-15T11:30:57+00:00" }, { "name": "symfony/string", - "version": "v7.3.2", + "version": "v8.0.1", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "42f505aff654e62ac7ac2ce21033818297ca89ca" + "reference": "ba65a969ac918ce0cc3edfac6cdde847eba231dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/42f505aff654e62ac7ac2ce21033818297ca89ca", - "reference": "42f505aff654e62ac7ac2ce21033818297ca89ca", + "url": "https://api.github.com/repos/symfony/string/zipball/ba65a969ac918ce0cc3edfac6cdde847eba231dc", + "reference": "ba65a969ac918ce0cc3edfac6cdde847eba231dc", "shasum": "" }, "require": { - "php": ">=8.2", - "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-intl-grapheme": "~1.0", - "symfony/polyfill-intl-normalizer": "~1.0", - "symfony/polyfill-mbstring": "~1.0" + "php": ">=8.4", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-intl-grapheme": "^1.33", + "symfony/polyfill-intl-normalizer": "^1.0", + "symfony/polyfill-mbstring": "^1.0" }, "conflict": { "symfony/translation-contracts": "<2.5" }, "require-dev": { - "symfony/emoji": "^7.1", - "symfony/error-handler": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/intl": "^6.4|^7.0", + "symfony/emoji": "^7.4|^8.0", + "symfony/http-client": "^7.4|^8.0", + "symfony/intl": "^7.4|^8.0", "symfony/translation-contracts": "^2.5|^3.0", - "symfony/var-exporter": "^6.4|^7.0" + "symfony/var-exporter": "^7.4|^8.0" }, "type": "library", "autoload": { @@ -3351,7 +3402,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.3.2" + "source": "https://github.com/symfony/string/tree/v8.0.1" }, "funding": [ { @@ -3371,20 +3422,20 @@ "type": "tidelift" } ], - "time": "2025-07-10T08:47:49+00:00" + "time": "2025-12-01T09:13:36+00:00" }, { "name": "theseer/tokenizer", - "version": "1.2.3", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" + "reference": "b7489ce515e168639d17feec34b8847c326b0b3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", - "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/b7489ce515e168639d17feec34b8847c326b0b3c", + "reference": "b7489ce515e168639d17feec34b8847c326b0b3c", "shasum": "" }, "require": { @@ -3413,7 +3464,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/1.2.3" + "source": "https://github.com/theseer/tokenizer/tree/1.3.1" }, "funding": [ { @@ -3421,7 +3472,7 @@ "type": "github" } ], - "time": "2024-03-03T12:36:25+00:00" + "time": "2025-11-17T20:03:58+00:00" }, { "name": "webmozart/glob", @@ -3475,13 +3526,13 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=8.0", "ext-swoole": "*" }, - "platform-dev": [], - "plugin-api-version": "2.3.0" + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/docs/Getting-Starting-Guide.md b/docs/Getting-Starting-Guide.md index b0f46a4b..831d0687 100644 --- a/docs/Getting-Starting-Guide.md +++ b/docs/Getting-Starting-Guide.md @@ -144,7 +144,7 @@ use Utopia\Http\Swoole\Response; use Swoole\Http\Server; use Swoole\Http\Request as SwooleRequest; use Swoole\Http\Response as SwooleResponse; -use Utopia\Http\Validator\Wildcard; +use Utopia\Validator\Wildcard; $http = new Server("0.0.0.0", 8080); diff --git a/example/src/server.php b/example/src/server.php index 4eb07f71..d05f80f2 100644 --- a/example/src/server.php +++ b/example/src/server.php @@ -5,7 +5,7 @@ use Utopia\Http\Http; use Utopia\Http\Response; use Utopia\Http\Adapter\Swoole\Server; -use Utopia\Http\Validator\Text; +use Utopia\Validator\Text; Http::get('/') ->param('name', 'World', new Text(256), 'Name to greet. Optional, max length 256.', true) diff --git a/src/Http/Hook.php b/src/Http/Hook.php index 2266da26..0f177dc3 100644 --- a/src/Http/Hook.php +++ b/src/Http/Hook.php @@ -2,6 +2,8 @@ namespace Utopia\Http; +use Utopia\Validator; + class Hook { /** diff --git a/src/Http/Http.php b/src/Http/Http.php index 8fe02785..61434842 100755 --- a/src/Http/Http.php +++ b/src/Http/Http.php @@ -2,6 +2,8 @@ namespace Utopia\Http; +use Utopia\Validator; + class Http { /** diff --git a/src/Http/Validator.php b/src/Http/Validator.php deleted file mode 100755 index 6a8304ea..00000000 --- a/src/Http/Validator.php +++ /dev/null @@ -1,57 +0,0 @@ - $validators - */ - public function __construct(protected array $validators, protected string $type = self::TYPE_MIXED) - { - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - if (!(\is_null($this->failedRule))) { - $description = $this->failedRule->getDescription(); - } else { - $description = $this->validators[0]->getDescription(); - } - - return $description; - } - - /** - * Is valid - * - * Validation will pass when all rules are valid if only one of the rules is invalid validation will fail. - * - * @param mixed $value - * @return bool - */ - public function isValid(mixed $value): bool - { - foreach ($this->validators as $rule) { - $valid = $rule->isValid($value); - - if (!$valid) { - $this->failedRule = $rule; - return false; - } - } - - return true; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return $this->type; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return true; - } -} diff --git a/src/Http/Validator/AnyOf.php b/src/Http/Validator/AnyOf.php deleted file mode 100644 index ff96a54c..00000000 --- a/src/Http/Validator/AnyOf.php +++ /dev/null @@ -1,87 +0,0 @@ - $validators - */ - public function __construct(protected array $validators, protected string $type = self::TYPE_MIXED) - { - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - if (!(\is_null($this->failedRule))) { - $description = $this->failedRule->getDescription(); - } else { - $description = $this->validators[0]->getDescription(); - } - - return $description; - } - - /** - * Is valid - * - * Validation will pass when all rules are valid if only one of the rules is invalid validation will fail. - * - * @param mixed $value - * @return bool - */ - public function isValid(mixed $value): bool - { - foreach ($this->validators as $rule) { - $valid = $rule->isValid($value); - - $this->failedRule = $rule; - - if ($valid) { - return true; - } - } - - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return $this->type; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return true; - } -} diff --git a/src/Http/Validator/ArrayList.php b/src/Http/Validator/ArrayList.php deleted file mode 100644 index c2c7e5ab..00000000 --- a/src/Http/Validator/ArrayList.php +++ /dev/null @@ -1,116 +0,0 @@ -validator = $validator; - $this->length = $length; - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - $msg = 'Value must a valid array'; - - if ($this->length > 0) { - $msg .= ' no longer than ' . $this->length . ' items'; - } - - return $msg . ' and ' . $this->validator->getDescription(); - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return true; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return $this->validator->getType(); - } - - /** - * Get Nested Validator - * - * @return Validator - */ - public function getValidator(): Validator - { - return $this->validator; - } - - /** - * Is valid - * - * Validation will pass when $value is valid array and validator is valid. - * - * @param mixed $value - * @return bool - */ - public function isValid(mixed $value): bool - { - if (!\is_array($value)) { - return false; - } - - if ($this->length && \count($value) > $this->length) { - return false; - } - - foreach ($value as $element) { - if (!$this->validator->isValid($element)) { - return false; - } - } - - return true; - } -} diff --git a/src/Http/Validator/Assoc.php b/src/Http/Validator/Assoc.php deleted file mode 100644 index 9b7697e4..00000000 --- a/src/Http/Validator/Assoc.php +++ /dev/null @@ -1,88 +0,0 @@ -length = $length; - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - return 'Value must be a valid object.'; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return true; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return self::TYPE_ARRAY; - } - - /** - * Is valid - * - * Validation will pass when $value is valid assoc array. - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - if (!\is_array($value)) { - return false; - } - - $jsonString = \json_encode($value); - $jsonStringSize = \strlen($jsonString); - - if ($jsonStringSize > $this->length) { - return false; - } - - return \array_keys($value) !== \range(0, \count($value) - 1); - } -} diff --git a/src/Http/Validator/Boolean.php b/src/Http/Validator/Boolean.php deleted file mode 100644 index 38b498ec..00000000 --- a/src/Http/Validator/Boolean.php +++ /dev/null @@ -1,94 +0,0 @@ -loose = $loose; - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - return 'Value must be a valid boolean'; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return self::TYPE_BOOLEAN; - } - - /** - * Is valid - * - * Validation will pass when $value has a boolean value. - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - if ($this->loose && ($value === 'true' || $value === 'false')) { // Accept strings - return true; - } - - if ($this->loose && ($value === '1' || $value === '0')) { // Accept numeric strings - return true; - } - - if ($this->loose && ($value === 1 || $value === 0)) { // Accept integers - return true; - } - - if (\is_bool($value)) { - return true; - } - - return false; - } -} diff --git a/src/Http/Validator/Domain.php b/src/Http/Validator/Domain.php deleted file mode 100644 index dd213191..00000000 --- a/src/Http/Validator/Domain.php +++ /dev/null @@ -1,78 +0,0 @@ -loose = $loose; - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - return 'Value must be a valid float'; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return self::TYPE_FLOAT; - } - - /** - * Is valid - * - * Validation will pass when $value is float. - * - * @param mixed $value - * @return bool - */ - public function isValid(mixed $value): bool - { - if ($this->loose) { - if (!\is_numeric($value)) { - return false; - } - $value = $value + 0; - } - if (!\is_float($value) && !\is_int($value)) { - return false; - } - - return true; - } -} diff --git a/src/Http/Validator/HexColor.php b/src/Http/Validator/HexColor.php deleted file mode 100644 index fe9d5926..00000000 --- a/src/Http/Validator/HexColor.php +++ /dev/null @@ -1,53 +0,0 @@ -whitelist = $whitelist; - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - return 'URL host must be one of: ' . \implode(', ', $this->whitelist); - } - - /** - * Is valid - * - * Validation will pass when $value starts with one of the given hosts - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - $urlValidator = new URL(); - - if (!$urlValidator->isValid($value)) { - return false; - } - - $hostnameValidator = new Hostname($this->whitelist); - - return $hostnameValidator->isValid(\parse_url($value, PHP_URL_HOST)); - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return self::TYPE_STRING; - } -} diff --git a/src/Http/Validator/Hostname.php b/src/Http/Validator/Hostname.php deleted file mode 100644 index d3231f10..00000000 --- a/src/Http/Validator/Hostname.php +++ /dev/null @@ -1,114 +0,0 @@ -allowList = $allowList; - } - - /** - * @return string - */ - public function getDescription(): string - { - return 'Value must be a valid hostname without path, port and protocol.'; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return self::TYPE_STRING; - } - - /** - * @param mixed $value - * @return bool - */ - public function isValid(mixed $value): bool - { - // Validate proper format - if (!\is_string($value) || empty($value)) { - return false; - } - - // Max length 253 chars: https://en.wikipedia.org/wiki/Hostname#:~:text=The%20entire%20hostname%2C%20including%20the,maximum%20of%20253%20ASCII%20characters - if (\mb_strlen($value) > 253) { - return false; - } - - // This tests: 'http://', 'https://', and 'myapp.com/route' - if (\str_contains($value, '/')) { - return false; - } - - // This tests for: 'myapp.com:3000' - if (\str_contains($value, ':')) { - return false; - } - - // Logic #1: Empty allowList means everything is allowed - if (empty($this->allowList)) { - return true; - } - - // Logic #2: Allow List not empty, there are rules to check - // Loop through all allowed hostnames until match is found - foreach ($this->allowList as $allowedHostname) { - // If exact match; allow - // If *, allow everything - if ($value === $allowedHostname || $allowedHostname === '*') { - return true; - } - - // If wildcard symbol used - if (\str_starts_with($allowedHostname, '*')) { - // Remove starting * symbol before comparing - $allowedHostname = substr($allowedHostname, 1); - - // If rest of hostname match; allow - // Notice allowedHostname still includes starting dot. Root domain is NOT allowed by wildcard. - if (\str_ends_with($value, $allowedHostname)) { - return true; - } - } - } - - // If finished loop above without result, match is not found - return false; - } -} diff --git a/src/Http/Validator/IP.php b/src/Http/Validator/IP.php deleted file mode 100644 index e0ffef49..00000000 --- a/src/Http/Validator/IP.php +++ /dev/null @@ -1,113 +0,0 @@ -type = $type; - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - return 'Value must be a valid IP address'; - } - - /** - * Is valid - * - * Validation will pass when $value is valid IP address. - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - switch ($this->type) { - case self::ALL: - if (\filter_var($value, FILTER_VALIDATE_IP)) { - return true; - } - break; - - case self::V4: - if (\filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { - return true; - } - break; - - case self::V6: - if (\filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { - return true; - } - break; - - default: - return false; - } - - return false; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return self::TYPE_STRING; - } -} diff --git a/src/Http/Validator/Integer.php b/src/Http/Validator/Integer.php deleted file mode 100755 index 76af2aa4..00000000 --- a/src/Http/Validator/Integer.php +++ /dev/null @@ -1,88 +0,0 @@ -loose = $loose; - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - return 'Value must be a valid integer'; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return self::TYPE_INTEGER; - } - - /** - * Is valid - * - * Validation will pass when $value is integer. - * - * @param mixed $value - * @return bool - */ - public function isValid(mixed $value): bool - { - if ($this->loose) { - if (!\is_numeric($value)) { - return false; - } - $value = $value + 0; - } - if (!\is_int($value)) { - return false; - } - - return true; - } -} diff --git a/src/Http/Validator/JSON.php b/src/Http/Validator/JSON.php deleted file mode 100644 index 5bb734f6..00000000 --- a/src/Http/Validator/JSON.php +++ /dev/null @@ -1,59 +0,0 @@ - $validators - */ - public function __construct(protected array $validators, protected string $type = self::TYPE_MIXED) - { - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - $description = ''; - - if (!(\is_null($this->failedRule))) { - $description = $this->failedRule->getDescription(); - } else { - $description = $this->validators[0]->getDescription(); - } - - return $description; - } - - /** - * Is valid - * - * Validation will pass when all rules are valid if only one of the rules is invalid validation will fail. - * - * @param mixed $value - * @return bool - */ - public function isValid(mixed $value): bool - { - foreach ($this->validators as $rule) { - $valid = $rule->isValid($value); - - if ($valid) { - $this->failedRule = $rule; - return false; - } - } - - return true; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return $this->type; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return true; - } -} diff --git a/src/Http/Validator/Nullable.php b/src/Http/Validator/Nullable.php deleted file mode 100644 index b6c0007b..00000000 --- a/src/Http/Validator/Nullable.php +++ /dev/null @@ -1,73 +0,0 @@ -validator->getDescription() . ' or null'; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return $this->validator->getType(); - } - - /** - * @return Validator - */ - public function getValidator(): Validator - { - return $this->validator; - } - - /** - * Is valid - * - * Validation will pass when $value is text with valid length. - * - * @param mixed $value - * @return bool - */ - public function isValid(mixed $value): bool - { - if (\is_null($value)) { - return true; - } - - return $this->validator->isValid($value); - } -} diff --git a/src/Http/Validator/Numeric.php b/src/Http/Validator/Numeric.php deleted file mode 100755 index 13c88610..00000000 --- a/src/Http/Validator/Numeric.php +++ /dev/null @@ -1,66 +0,0 @@ -min = $min; - $this->max = $max; - $this->format = $format; - } - - /** - * Get Range Minimum Value - * - * @return int|float - */ - public function getMin(): int|float - { - return $this->min; - } - - /** - * Get Range Maximum Value - * - * @return int|float - */ - public function getMax(): int|float - { - return $this->max; - } - - /** - * Get Range Format - * - * @return string - */ - public function getFormat(): string - { - return $this->format; - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - return 'Value must be a valid range between '.\number_format($this->min).' and '.\number_format($this->max); - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return $this->format; - } - - /** - * Is valid - * - * Validation will pass when $value number is bigger or equal than $min number and lower or equal than $max. - * Not strict, considers any valid integer to be a valid float - * Considers infinity to be a valid integer - * - * @param mixed $value - * @return bool - */ - public function isValid(mixed $value): bool - { - if (!parent::isValid($value)) { - return false; - } - - switch ($this->format) { - case self::TYPE_INTEGER: - // Accept infinity as an integer - // Since gettype(INF) === TYPE_FLOAT - if ($value === INF || $value === -INF) { - break; // move to check if value is within range - } - $value = $value + 0; - if (!is_int($value)) { - return false; - } - break; - case self::TYPE_FLOAT: - if (!is_numeric($value)) { - return false; - } - $value = $value + 0.0; - break; - default: - return false; - } - - if ($this->min <= $value && $this->max >= $value) { - return true; - } - - return false; - } -} diff --git a/src/Http/Validator/Text.php b/src/Http/Validator/Text.php deleted file mode 100644 index 4df5d7e4..00000000 --- a/src/Http/Validator/Text.php +++ /dev/null @@ -1,138 +0,0 @@ -length = $length; - $this->min = $min; - $this->allowList = $allowList; - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - $message = 'Value must be a valid string'; - - if ($this->min === $this->length) { - $message .= ' and exactly '.$this->length.' chars'; - } else { - if ($this->min) { - $message .= ' and at least '.$this->min.' chars'; - } - - if ($this->length) { - $message .= ' and no longer than '.$this->length.' chars'; - } - } - - if ($this->allowList) { - $message .= ' and only consist of \''.\implode(', ', $this->allowList).'\' chars'; - } - - return $message; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return self::TYPE_STRING; - } - - /** - * Is valid - * - * Validation will pass when $value is text with valid length. - * - * @param mixed $value - * @return bool - */ - public function isValid(mixed $value): bool - { - if (!\is_string($value)) { - return false; - } - - if (\mb_strlen($value) < $this->min) { - return false; - } - - if (\mb_strlen($value) > $this->length && $this->length !== 0) { - return false; - } - - if (\count($this->allowList) > 0) { - foreach (\str_split($value) as $char) { - if (!\in_array($char, $this->allowList)) { - return false; - } - } - } - - return true; - } -} diff --git a/src/Http/Validator/URL.php b/src/Http/Validator/URL.php deleted file mode 100644 index f6434e98..00000000 --- a/src/Http/Validator/URL.php +++ /dev/null @@ -1,86 +0,0 @@ -allowedSchemes = $allowedSchemes; - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - if (!empty($this->allowedSchemes)) { - return 'Value must be a valid URL with following schemes (' . \implode(', ', $this->allowedSchemes) . ')'; - } - - return 'Value must be a valid URL'; - } - - /** - * Is valid - * - * Validation will pass when $value is valid URL. - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - if (\filter_var($value, FILTER_VALIDATE_URL) === false) { - return false; - } - - if (!empty($this->allowedSchemes) && !\in_array(\parse_url($value, PHP_URL_SCHEME), $this->allowedSchemes)) { - return false; - } - - return true; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return self::TYPE_STRING; - } -} diff --git a/src/Http/Validator/WhiteList.php b/src/Http/Validator/WhiteList.php deleted file mode 100755 index 53a6bb16..00000000 --- a/src/Http/Validator/WhiteList.php +++ /dev/null @@ -1,119 +0,0 @@ -list = $list; - $this->strict = $strict; - $this->type = $type; - - if (!$this->strict) { - foreach ($this->list as $key => &$value) { - $this->list[$key] = \strtolower($value); - } - } - } - - /** - * Get List of All Allowed Values - * - * @return array - */ - public function getList(): array - { - return $this->list; - } - - /** - * Get Description - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - return 'Value must be one of ('.\implode(', ', $this->list).')'; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return $this->type; - } - - /** - * Is valid - * - * Validation will pass if $value is in the white list array. - * - * @param mixed $value - * @return bool - */ - public function isValid(mixed $value): bool - { - if (\is_array($value)) { - return false; - } - - $value = ($this->strict) ? $value : \strtolower($value); - - if (!\in_array($value, $this->list, $this->strict)) { - return false; - } - - return true; - } -} diff --git a/src/Http/Validator/Wildcard.php b/src/Http/Validator/Wildcard.php deleted file mode 100644 index 1e7314a8..00000000 --- a/src/Http/Validator/Wildcard.php +++ /dev/null @@ -1,62 +0,0 @@ -assertFalse($arrayList->isValid(['text'])); - $this->assertEquals('Value must a valid array and Value must be a valid integer', $arrayList->getDescription()); - - $arrayList = new ArrayList(new Integer(), 3); - $this->assertFalse($arrayList->isValid(['a', 'b', 'c', 'd'])); - $this->assertEquals('Value must a valid array no longer than 3 items and Value must be a valid integer', $arrayList->getDescription()); - } - - public function testCanValidateTextValues(): void - { - $arrayList = new ArrayList(new Text(100)); - $this->assertTrue($arrayList->isArray(), 'true'); - $this->assertTrue($arrayList->isValid([0 => 'string', 1 => 'string'])); - $this->assertTrue($arrayList->isValid(['string', 'string'])); - $this->assertFalse($arrayList->isValid(['string', 'string', 3])); - $this->assertFalse($arrayList->isValid('string')); - $this->assertFalse($arrayList->isValid('string')); - $this->assertEquals(\Utopia\Http\Validator::TYPE_STRING, $arrayList->getType()); - $this->assertInstanceOf(Text::class, $arrayList->getValidator()); - } - - public function testCanValidateNumericValues(): void - { - $arrayList = new ArrayList(new Numeric()); - $this->assertTrue($arrayList->isValid([1, 2, 3])); - $this->assertFalse($arrayList->isValid(1)); - $this->assertFalse($arrayList->isValid('string')); - $this->assertEquals(\Utopia\Http\Validator::TYPE_MIXED, $arrayList->getType()); - $this->assertInstanceOf(Numeric::class, $arrayList->getValidator()); - } - - public function testCanValidateNumericValuesWithBoundaries(): void - { - $arrayList = new ArrayList(new Numeric(), 2); - $this->assertTrue($arrayList->isValid([1])); - $this->assertTrue($arrayList->isValid([1, 2])); - $this->assertFalse($arrayList->isValid([1, 2, 3])); - $this->assertEquals($arrayList->getType(), \Utopia\Http\Validator::TYPE_MIXED); - $this->assertInstanceOf(Numeric::class, $arrayList->getValidator()); - } -} diff --git a/tests/Validator/AssocTest.php b/tests/Validator/AssocTest.php deleted file mode 100755 index 2036998b..00000000 --- a/tests/Validator/AssocTest.php +++ /dev/null @@ -1,43 +0,0 @@ -assoc = new Assoc(); - } - - public function tearDown(): void - { - $this->assoc = null; - } - - public function testCanValidateAssocArray(): void - { - $this->assertTrue($this->assoc->isValid(['1' => 'a', '0' => 'b', '2' => 'c'])); - $this->assertTrue($this->assoc->isValid(['a' => 'a', 'b' => 'b', 'c' => 'c'])); - $this->assertTrue($this->assoc->isValid([])); - $this->assertTrue($this->assoc->isValid(['value' => str_repeat('-', 62000)])); - $this->assertTrue($this->assoc->isArray()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_ARRAY, $this->assoc->getType()); - } - - public function testCantValidateSequentialArray(): void - { - $this->assertFalse($this->assoc->isValid([0 => 'string', 1 => 'string'])); - $this->assertFalse($this->assoc->isValid(['a'])); - $this->assertFalse($this->assoc->isValid(['a', 'b', 'c'])); - $this->assertFalse($this->assoc->isValid(['0' => 'a', '1' => 'b', '2' => 'c'])); - } - - public function testCantValidateAssocArrayWithOver65kCharacters(): void - { - $this->assertFalse($this->assoc->isValid(['value' => str_repeat('-', 66000)])); - } -} diff --git a/tests/Validator/BooleanTest.php b/tests/Validator/BooleanTest.php deleted file mode 100755 index bda71580..00000000 --- a/tests/Validator/BooleanTest.php +++ /dev/null @@ -1,46 +0,0 @@ -assertTrue($boolean->isValid(true)); - $this->assertTrue($boolean->isValid(false)); - $this->assertFalse($boolean->isValid('false')); - $this->assertFalse($boolean->isValid('true')); - $this->assertFalse($boolean->isValid('0')); - $this->assertFalse($boolean->isValid('1')); - $this->assertFalse($boolean->isValid(0)); - $this->assertFalse($boolean->isValid(1)); - $this->assertFalse($boolean->isValid(['string', 'string'])); - $this->assertFalse($boolean->isValid('string')); - $this->assertFalse($boolean->isValid(1.2)); - $this->assertFalse($boolean->isArray()); - $this->assertEquals($boolean->getType(), \Utopia\Http\Validator::TYPE_BOOLEAN); - } - - public function testCanValidateLoosely() - { - $boolean = new Boolean(true); - - $this->assertTrue($boolean->isValid(true)); - $this->assertTrue($boolean->isValid(false)); - $this->assertTrue($boolean->isValid('false')); - $this->assertTrue($boolean->isValid('true')); - $this->assertTrue($boolean->isValid('0')); - $this->assertTrue($boolean->isValid('1')); - $this->assertTrue($boolean->isValid(0)); - $this->assertTrue($boolean->isValid(1)); - $this->assertFalse($boolean->isValid(['string', 'string'])); - $this->assertFalse($boolean->isValid('string')); - $this->assertFalse($boolean->isValid(1.2)); - $this->assertFalse($boolean->isArray()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_BOOLEAN, $boolean->getType()); - } -} diff --git a/tests/Validator/DomainTest.php b/tests/Validator/DomainTest.php deleted file mode 100644 index 85a346e1..00000000 --- a/tests/Validator/DomainTest.php +++ /dev/null @@ -1,37 +0,0 @@ -domain = new Domain(); - } - - public function testIsValid() - { - // Assertions - $this->assertEquals(true, $this->domain->isValid('example.com')); - $this->assertEquals(true, $this->domain->isValid('subdomain.example.com')); - $this->assertEquals(true, $this->domain->isValid('subdomain.example-app.com')); - $this->assertEquals(true, $this->domain->isValid('subdomain.example_app.com')); - $this->assertEquals(true, $this->domain->isValid('subdomain-new.example.com')); - $this->assertEquals(true, $this->domain->isValid('subdomain_new.example.com')); - $this->assertEquals(true, $this->domain->isValid('localhost')); - $this->assertEquals(true, $this->domain->isValid('example.io')); - $this->assertEquals(true, $this->domain->isValid('example.org')); - $this->assertEquals(true, $this->domain->isValid('example.org')); - $this->assertEquals(false, $this->domain->isValid(false)); - $this->assertEquals(false, $this->domain->isValid('.')); - $this->assertEquals(false, $this->domain->isValid('..')); - $this->assertEquals(false, $this->domain->isValid('')); - $this->assertEquals(false, $this->domain->isValid(['string', 'string'])); - $this->assertEquals(false, $this->domain->isValid(1)); - $this->assertEquals(false, $this->domain->isValid(1.2)); - } -} diff --git a/tests/Validator/FloatValidatorTest.php b/tests/Validator/FloatValidatorTest.php deleted file mode 100755 index be905b68..00000000 --- a/tests/Validator/FloatValidatorTest.php +++ /dev/null @@ -1,39 +0,0 @@ -assertTrue($validator->isValid(27.25)); - $this->assertTrue($validator->isValid(23)); - $this->assertTrue($validator->isValid(23.5)); - $this->assertTrue($validator->isValid(1e7)); - $this->assertFalse($validator->isValid('abc')); - $this->assertFalse($validator->isValid(true)); - $this->assertFalse($validator->isValid('23.5')); - $this->assertFalse($validator->isValid('23')); - $this->assertFalse($validator->isArray()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_FLOAT, $validator->getType()); - } - - public function testCanValidateLoosely(): void - { - $validator = new FloatValidator(true); - - $this->assertTrue($validator->isValid(27.25)); - $this->assertTrue($validator->isValid(23)); - $this->assertTrue($validator->isValid(23.5)); - $this->assertTrue($validator->isValid(1e7)); - $this->assertTrue($validator->isValid('23.5')); - $this->assertTrue($validator->isValid('23')); - $this->assertFalse($validator->isValid('abc')); - $this->assertFalse($validator->isValid(true)); - $this->assertFalse($validator->isArray()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_FLOAT, $validator->getType()); - } -} diff --git a/tests/Validator/HexColorTest.php b/tests/Validator/HexColorTest.php deleted file mode 100755 index f90d92fe..00000000 --- a/tests/Validator/HexColorTest.php +++ /dev/null @@ -1,26 +0,0 @@ -assertTrue($hexColor->isValid('000')); - $this->assertTrue($hexColor->isValid('ffffff')); - $this->assertTrue($hexColor->isValid('fff')); - $this->assertTrue($hexColor->isValid('000000')); - - $this->assertFalse($hexColor->isValid('AB10BC99')); - $this->assertFalse($hexColor->isValid('AR1012')); - $this->assertFalse($hexColor->isValid('ab12bc99')); - $this->assertFalse($hexColor->isValid('00')); - $this->assertFalse($hexColor->isValid('ffff')); - $this->assertFalse($hexColor->isArray()); - - $this->assertEquals(\Utopia\Http\Validator::TYPE_STRING, $hexColor->getType()); - } -} diff --git a/tests/Validator/HostTest.php b/tests/Validator/HostTest.php deleted file mode 100644 index 4162a5b3..00000000 --- a/tests/Validator/HostTest.php +++ /dev/null @@ -1,30 +0,0 @@ -host = new Host(['example.io', 'subdomain.example.test', 'localhost', '*.appwrite.io']); - } - - public function testIsValid() - { - // Assertions - $this->assertEquals($this->host->isValid('https://example.io/link'), true); - $this->assertEquals($this->host->isValid('https://localhost'), true); - $this->assertEquals($this->host->isValid('localhost'), false); - $this->assertEquals($this->host->isValid('http://subdomain.example.test/path'), true); - $this->assertEquals($this->host->isValid('http://test.subdomain.example.test/path'), false); - $this->assertEquals($this->host->isValid('http://appwrite.io/path'), false); - $this->assertEquals($this->host->isValid('http://me.appwrite.io/path'), true); - $this->assertEquals($this->host->isValid('http://you.appwrite.io/path'), true); - $this->assertEquals($this->host->isValid('http://us.together.appwrite.io/path'), true); - $this->assertEquals($this->host->getType(), 'string'); - } -} diff --git a/tests/Validator/HostnameTest.php b/tests/Validator/HostnameTest.php deleted file mode 100755 index 2760648d..00000000 --- a/tests/Validator/HostnameTest.php +++ /dev/null @@ -1,106 +0,0 @@ -assertEquals(\Utopia\Http\Validator::TYPE_STRING, $validator->getType()); - $this->assertFalse($validator->isArray()); - - $this->assertTrue($validator->isValid('myweb.com')); - $this->assertTrue($validator->isValid('httpmyweb.com')); - $this->assertTrue($validator->isValid('httpsmyweb.com')); - $this->assertTrue($validator->isValid('wsmyweb.com')); - $this->assertTrue($validator->isValid('wssmyweb.com')); - $this->assertTrue($validator->isValid('vercel.app')); - $this->assertTrue($validator->isValid('web.vercel.app')); - $this->assertTrue($validator->isValid('my-web.vercel.app')); - $this->assertTrue($validator->isValid('my-project.my-web.vercel.app')); - $this->assertTrue($validator->isValid('my-commit.my-project.my-web.vercel.app')); - $this->assertTrue($validator->isValid('myapp.co.uk')); - $this->assertTrue($validator->isValid('*.myapp.com')); - $this->assertTrue($validator->isValid('myapp.*')); - - $this->assertFalse($validator->isValid('https://myweb.com')); - $this->assertFalse($validator->isValid('ws://myweb.com')); - $this->assertFalse($validator->isValid('wss://myweb.com')); - $this->assertFalse($validator->isValid('http://myweb.com')); - $this->assertFalse($validator->isValid('http://myweb.com:3000')); - $this->assertFalse($validator->isValid('http://myweb.com/blog')); - $this->assertFalse($validator->isValid('myweb.com:80')); - $this->assertFalse($validator->isValid('myweb.com:3000')); - $this->assertFalse($validator->isValid('myweb.com/blog')); - $this->assertFalse($validator->isValid('myweb.com/blog/article1')); - - // Max length test - $domain = \str_repeat('bestdomain', 25); // 250 chars total - - $domain .= '.sk'; // Exactly at the limit - $this->assertTrue($validator->isValid($domain)); - - $domain .= 'a'; // Exactly over the limit - $this->assertFalse($validator->isValid($domain)); - } - - public function testCanValidateHostnamesWithAllowList(): void - { - // allowList tests - $validator = new Hostname([ - 'myweb.vercel.app', - 'myweb.com', - '*.myapp.com', - ]); - - $this->assertTrue($validator->isValid('myweb.vercel.app')); - $this->assertFalse($validator->isValid('myweb.vercel.com')); - $this->assertFalse($validator->isValid('myweb2.vercel.app')); - $this->assertFalse($validator->isValid('vercel.app')); - $this->assertFalse($validator->isValid('mycommit.myweb.vercel.app')); - - $this->assertTrue($validator->isValid('myweb.com')); - $this->assertFalse($validator->isValid('myweb.eu')); - $this->assertFalse($validator->isValid('project.myweb.eu')); - $this->assertFalse($validator->isValid('commit.project.myweb.eu')); - - $this->assertTrue($validator->isValid('project1.myapp.com')); - $this->assertTrue($validator->isValid('project2.myapp.com')); - $this->assertTrue($validator->isValid('project-with-dash.myapp.com')); - $this->assertTrue($validator->isValid('anything.myapp.com')); - $this->assertTrue($validator->isValid('commit.anything.myapp.com')); - $this->assertFalse($validator->isValid('anything.myapp.eu')); - $this->assertFalse($validator->isValid('myapp.com')); - - $validator = new Hostname(['localhost']); - $this->assertTrue($validator->isValid('localhost')); - } - - public function testCanValidateHostnamesWithWildcard(): void - { - $validator = new Hostname(); - $this->assertTrue($validator->isValid('*')); - - $validator = new Hostname(['netlify.*']); - $this->assertFalse($validator->isValid('netlify.com')); - $this->assertFalse($validator->isValid('netlify.eu')); - $this->assertFalse($validator->isValid('netlify.app')); - - $validator = new Hostname(['*.*.app.io']); - $this->assertFalse($validator->isValid('app.io')); - $this->assertFalse($validator->isValid('project.app.io')); - $this->assertFalse($validator->isValid('commit.project.app.io')); - $this->assertFalse($validator->isValid('api.commit.project.app.io')); - - $validator = new Hostname(['*']); - $this->assertTrue($validator->isValid('*')); - $this->assertTrue($validator->isValid('localhost')); - $this->assertTrue($validator->isValid('anything')); // Like localhost - $this->assertTrue($validator->isValid('anything.com')); - $this->assertTrue($validator->isValid('anything.with.subdomains.eu')); - } -} diff --git a/tests/Validator/IPTest.php b/tests/Validator/IPTest.php deleted file mode 100644 index 074a8f68..00000000 --- a/tests/Validator/IPTest.php +++ /dev/null @@ -1,67 +0,0 @@ -assertEquals($validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true); - $this->assertEquals($validator->isValid('109.67.204.101'), true); - $this->assertEquals($validator->isValid(23.5), false); - $this->assertEquals($validator->isValid('23.5'), false); - $this->assertEquals($validator->isValid(null), false); - $this->assertEquals($validator->isValid(true), false); - $this->assertEquals($validator->isValid(false), false); - $this->assertEquals($validator->getType(), 'string'); - } - - public function testIsValidIPALL() - { - $validator = new IP(IP::ALL); - - // Assertions - $this->assertEquals($validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true); - $this->assertEquals($validator->isValid('109.67.204.101'), true); - $this->assertEquals($validator->isValid(23.5), false); - $this->assertEquals($validator->isValid('23.5'), false); - $this->assertEquals($validator->isValid(null), false); - $this->assertEquals($validator->isValid(true), false); - $this->assertEquals($validator->isValid(false), false); - } - - public function testIsValidIPV4() - { - $validator = new IP(IP::V4); - - // Assertions - $this->assertEquals($validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), false); - $this->assertEquals($validator->isValid('109.67.204.101'), true); - $this->assertEquals($validator->isValid(23.5), false); - $this->assertEquals($validator->isValid('23.5'), false); - $this->assertEquals($validator->isValid(null), false); - $this->assertEquals($validator->isValid(true), false); - $this->assertEquals($validator->isValid(false), false); - } - - public function testIsValidIPV6() - { - $validator = new IP(IP::V6); - - // Assertions - $this->assertEquals($validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true); - $this->assertEquals($validator->isValid('109.67.204.101'), false); - $this->assertEquals($validator->isValid(23.5), false); - $this->assertEquals($validator->isValid('23.5'), false); - $this->assertEquals($validator->isValid(null), false); - $this->assertEquals($validator->isValid(true), false); - $this->assertEquals($validator->isValid(false), false); - } -} diff --git a/tests/Validator/IntegerTest.php b/tests/Validator/IntegerTest.php deleted file mode 100755 index faddca2c..00000000 --- a/tests/Validator/IntegerTest.php +++ /dev/null @@ -1,36 +0,0 @@ -assertTrue($validator->isValid(23)); - $this->assertFalse($validator->isValid('23')); - $this->assertFalse($validator->isValid(23.5)); - $this->assertFalse($validator->isValid('23.5')); - $this->assertFalse($validator->isValid(null)); - $this->assertFalse($validator->isValid(true)); - $this->assertFalse($validator->isValid(false)); - $this->assertFalse($validator->isArray()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_INTEGER, $validator->getType()); - } - - public function testCanValidateLoosely() - { - $validator = new Integer(true); - $this->assertTrue($validator->isValid(23)); - $this->assertTrue($validator->isValid('23')); - $this->assertFalse($validator->isValid(23.5)); - $this->assertFalse($validator->isValid('23.5')); - $this->assertFalse($validator->isValid(null)); - $this->assertFalse($validator->isValid(true)); - $this->assertFalse($validator->isValid(false)); - $this->assertFalse($validator->isArray()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_INTEGER, $validator->getType()); - } -} diff --git a/tests/Validator/JSONTest.php b/tests/Validator/JSONTest.php deleted file mode 100755 index d4a4e358..00000000 --- a/tests/Validator/JSONTest.php +++ /dev/null @@ -1,28 +0,0 @@ -assertTrue($json->isValid('{}')); - $this->assertTrue($json->isValid([])); - $this->assertTrue($json->isValid(['test'])); - $this->assertTrue($json->isValid(['test' => 'demo'])); - $this->assertTrue($json->isValid('{"test": "demo"}')); - - $this->assertFalse($json->isValid('')); - $this->assertFalse($json->isValid(false)); - $this->assertFalse($json->isValid(null)); - $this->assertFalse($json->isValid('string')); - $this->assertFalse($json->isValid(1)); - $this->assertFalse($json->isValid(1.2)); - $this->assertFalse($json->isValid("{'test': 'demo'}")); - $this->assertFalse($json->isArray()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_OBJECT, $json->getType()); - } -} diff --git a/tests/Validator/MultipleOfTest.php b/tests/Validator/MultipleOfTest.php deleted file mode 100644 index 06435aa8..00000000 --- a/tests/Validator/MultipleOfTest.php +++ /dev/null @@ -1,61 +0,0 @@ -assertEquals('string', $validator->getType()); - $this->assertEquals("Value must be a valid string and at least 1 chars and no longer than 20 chars", $validator->getDescription()); - - // Valid URL but invalid text length - $this->assertFalse($validator->isValid('http://example.com/very-long-url')); - - // Valid text within length, but invalid URL - $this->assertFalse($validator->isValid('hello world')); - - // Both conditions satisfied - $this->assertTrue($validator->isValid('http://example.com')); - $this->assertTrue($validator->isValid('https://google.com')); - - // Neither condition satisfied - $this->assertFalse($validator->isValid('example.com/hello-world')); - $this->assertFalse($validator->isValid('')); - } - - public function testRules() - { - $validTextValidUrl = 'http://example.com'; - $validTextInvalidUrl = 'hello world'; - $invalidTextValidUrl = 'http://example.com/very-long-url'; - $invalidTextInvalidUrl = 'Some very long text that is also not an URL'; - - $vaidator = new AllOf([new Text(20), new URL()], Validator::TYPE_STRING); - $this->assertTrue($vaidator->isValid($validTextValidUrl)); - $this->assertFalse($vaidator->isValid($validTextInvalidUrl)); - $this->assertFalse($vaidator->isValid($invalidTextValidUrl)); - $this->assertFalse($vaidator->isValid($invalidTextInvalidUrl)); - - $vaidator = new AnyOf([new Text(20), new URL()], Validator::TYPE_STRING); - $this->assertTrue($vaidator->isValid($validTextValidUrl)); - $this->assertTrue($vaidator->isValid($validTextInvalidUrl)); - $this->assertTrue($vaidator->isValid($invalidTextValidUrl)); - $this->assertFalse($vaidator->isValid($invalidTextInvalidUrl)); - - $vaidator = new NoneOf([new Text(20), new URL()], Validator::TYPE_STRING); - $this->assertFalse($vaidator->isValid($validTextValidUrl)); - $this->assertFalse($vaidator->isValid($validTextInvalidUrl)); - $this->assertFalse($vaidator->isValid($invalidTextValidUrl)); - $this->assertTrue($vaidator->isValid($invalidTextInvalidUrl)); - } -} diff --git a/tests/Validator/NullableTest.php b/tests/Validator/NullableTest.php deleted file mode 100755 index ebd24834..00000000 --- a/tests/Validator/NullableTest.php +++ /dev/null @@ -1,22 +0,0 @@ -assertTrue($validator->isValid('text')); - $this->assertTrue($validator->isValid(null)); - $this->assertFalse($validator->isValid(123)); - } - - public function testCanReturnValidator(): void - { - $validator = new Nullable(new Text(0)); - $this->assertTrue($validator->getValidator() instanceof Text); - } -} diff --git a/tests/Validator/NumericTest.php b/tests/Validator/NumericTest.php deleted file mode 100755 index 88ea5030..00000000 --- a/tests/Validator/NumericTest.php +++ /dev/null @@ -1,24 +0,0 @@ -assertTrue($numeric->isValid('42')); - $this->assertTrue($numeric->isValid(1337)); - $this->assertTrue($numeric->isValid(0x539)); - $this->assertTrue($numeric->isValid(02471)); - $this->assertTrue($numeric->isValid(1337e0)); - $this->assertTrue($numeric->isValid(9.1)); - $this->assertFalse($numeric->isValid('not numeric')); - $this->assertFalse($numeric->isValid([])); - $this->assertFalse($numeric->isArray()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_MIXED, $numeric->getType()); - } -} diff --git a/tests/Validator/RangeTest.php b/tests/Validator/RangeTest.php deleted file mode 100755 index aafbab4a..00000000 --- a/tests/Validator/RangeTest.php +++ /dev/null @@ -1,60 +0,0 @@ -assertTrue($range->isValid(0)); - $this->assertTrue($range->isValid(1)); - $this->assertTrue($range->isValid(4)); - $this->assertTrue($range->isValid(5)); - $this->assertTrue($range->isValid('5')); - $this->assertFalse($range->isValid('1.5')); - $this->assertFalse($range->isValid(6)); - $this->assertFalse($range->isValid(-1)); - $this->assertEquals(0, $range->getMin()); - $this->assertEquals(5, $range->getMax()); - $this->assertFalse($range->isArray()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_INTEGER, $range->getFormat()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_INTEGER, $range->getType()); - } - - public function testCanValidateFloatRange() - { - $range = new Range(0, 1, \Utopia\Http\Validator::TYPE_FLOAT); - - $this->assertTrue($range->isValid(0.0)); - $this->assertTrue($range->isValid(1.0)); - $this->assertTrue($range->isValid(0.5)); - $this->assertTrue($range->isValid('0.5')); - $this->assertTrue($range->isValid('0.6')); - $this->assertFalse($range->isValid(4)); - $this->assertFalse($range->isValid(1.5)); - $this->assertFalse($range->isValid(-1)); - $this->assertEquals(0, $range->getMin()); - $this->assertEquals(1, $range->getMax()); - $this->assertFalse($range->isArray()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_FLOAT, $range->getFormat()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_FLOAT, $range->getType(), \Utopia\Http\Validator::TYPE_FLOAT); - } - - public function canValidateInfinityRange() - { - $integer = new Range(5, INF, \Utopia\Http\Validator::TYPE_INTEGER); - $float = new Range(-INF, 45.6, \Utopia\Http\Validator::TYPE_FLOAT); - - $this->assertTrue($integer->isValid(25)); - $this->assertFalse($integer->isValid(3)); - $this->assertTrue($integer->isValid(INF)); - $this->assertTrue($float->isValid(32.1)); - $this->assertFalse($float->isValid(97.6)); - $this->assertTrue($float->isValid(-INF)); - } -} diff --git a/tests/Validator/TextTest.php b/tests/Validator/TextTest.php deleted file mode 100755 index 476cfd8a..00000000 --- a/tests/Validator/TextTest.php +++ /dev/null @@ -1,88 +0,0 @@ -assertTrue($validator->isValid('text')); - $this->assertTrue($validator->isValid('7')); - $this->assertTrue($validator->isValid('7.9')); - $this->assertTrue($validator->isValid('["seven"]')); - $this->assertFalse($validator->isValid(['seven'])); - $this->assertFalse($validator->isValid(['seven', 8, 9.0])); - $this->assertFalse($validator->isValid(false)); - $this->assertFalse($validator->isArray()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_STRING, $validator->getType()); - } - - public function testCanValidateBoundaries(): void - { - $validator = new Text(5); - $this->assertTrue($validator->isValid('hell')); - $this->assertTrue($validator->isValid('hello')); - $this->assertFalse($validator->isValid('hellow')); - $this->assertFalse($validator->isValid('')); - - $validator = new Text(5, 3); - $this->assertTrue($validator->isValid('hel')); - $this->assertTrue($validator->isValid('hell')); - $this->assertTrue($validator->isValid('hello')); - $this->assertFalse($validator->isValid('hellow')); - $this->assertFalse($validator->isValid('he')); - $this->assertFalse($validator->isValid('h')); - } - - public function testCanValidateTextWithAllowList(): void - { - // Test lowercase alphabet - $validator = new Text(100, allowList: Text::ALPHABET_LOWER); - $this->assertFalse($validator->isArray()); - $this->assertTrue($validator->isValid('qwertzuiopasdfghjklyxcvbnm')); - $this->assertTrue($validator->isValid('hello')); - $this->assertTrue($validator->isValid('world')); - $this->assertFalse($validator->isValid('hello world')); - $this->assertFalse($validator->isValid('Hello')); - $this->assertFalse($validator->isValid('worlD')); - $this->assertFalse($validator->isValid('hello123')); - - // Test uppercase alphabet - $validator = new Text(100, allowList: Text::ALPHABET_UPPER); - $this->assertFalse($validator->isArray()); - $this->assertTrue($validator->isValid('QWERTZUIOPASDFGHJKLYXCVBNM')); - $this->assertTrue($validator->isValid('HELLO')); - $this->assertTrue($validator->isValid('WORLD')); - $this->assertFalse($validator->isValid('HELLO WORLD')); - $this->assertFalse($validator->isValid('hELLO')); - $this->assertFalse($validator->isValid('WORLd')); - $this->assertFalse($validator->isValid('HELLO123')); - - // Test numbers - $validator = new Text(100, allowList: Text::NUMBERS); - $this->assertFalse($validator->isArray()); - $this->assertTrue($validator->isValid('1234567890')); - $this->assertTrue($validator->isValid('123')); - $this->assertFalse($validator->isValid('123 456')); - $this->assertFalse($validator->isValid('hello123')); - - // Test combination of allowLists - $validator = new Text(100, allowList: [ - ...Text::ALPHABET_LOWER, - ...Text::ALPHABET_UPPER, - ...Text::NUMBERS, - ]); - - $this->assertFalse($validator->isArray()); - $this->assertTrue($validator->isValid('1234567890')); - $this->assertTrue($validator->isValid('qwertzuiopasdfghjklyxcvbnm')); - $this->assertTrue($validator->isValid('QWERTZUIOPASDFGHJKLYXCVBNM')); - $this->assertTrue($validator->isValid('QWERTZUIOPASDFGHJKLYXCVBNMqwertzuiopasdfghjklyxcvbnm1234567890')); - $this->assertFalse($validator->isValid('hello-world')); - $this->assertFalse($validator->isValid('hello_world')); - $this->assertFalse($validator->isValid('hello/world')); - } -} diff --git a/tests/Validator/URLTest.php b/tests/Validator/URLTest.php deleted file mode 100644 index de530cd1..00000000 --- a/tests/Validator/URLTest.php +++ /dev/null @@ -1,43 +0,0 @@ -url = new URL(); - } - - public function tearDown(): void - { - $this->url = null; - } - - public function testIsValid(): void - { - $this->assertEquals('Value must be a valid URL', $this->url->getDescription()); - $this->assertEquals(true, $this->url->isValid('http://example.com')); - $this->assertEquals(true, $this->url->isValid('https://example.com')); - $this->assertEquals(true, $this->url->isValid('htts://example.com')); // does not validate protocol - $this->assertEquals(false, $this->url->isValid('example.com')); // though, requires some kind of protocol - $this->assertEquals(false, $this->url->isValid('http:/example.com')); - $this->assertEquals(true, $this->url->isValid('http://exa-mple.com')); - $this->assertEquals(false, $this->url->isValid('htt@s://example.com')); - $this->assertEquals(true, $this->url->isValid('http://www.example.com/foo%2\u00c2\u00a9zbar')); - $this->assertEquals(true, $this->url->isValid('http://www.example.com/?q=%3Casdf%3E')); - } - - public function testIsValidAllowedSchemes(): void - { - $this->url = new URL(['http', 'https']); - $this->assertEquals('Value must be a valid URL with following schemes (http, https)', $this->url->getDescription()); - $this->assertEquals(true, $this->url->isValid('http://example.com')); - $this->assertEquals(true, $this->url->isValid('https://example.com')); - $this->assertEquals(false, $this->url->isValid('gopher://www.example.com')); - } -} diff --git a/tests/Validator/WhiteListTest.php b/tests/Validator/WhiteListTest.php deleted file mode 100755 index f024908c..00000000 --- a/tests/Validator/WhiteListTest.php +++ /dev/null @@ -1,58 +0,0 @@ -assertTrue($whiteList->isValid(3)); - $this->assertTrue($whiteList->isValid(4)); - $this->assertTrue($whiteList->isValid('string1')); - $this->assertTrue($whiteList->isValid('string2')); - - $this->assertFalse($whiteList->isValid('string3')); - $this->assertFalse($whiteList->isValid('STRING1')); - $this->assertFalse($whiteList->isValid('strIng1')); - $this->assertFalse($whiteList->isValid('3')); - $this->assertFalse($whiteList->isValid(5)); - $this->assertFalse($whiteList->isArray()); - $this->assertEquals($whiteList->getList(), ['string1', 'string2', 3, 4]); - $this->assertEquals(\Utopia\Http\Validator::TYPE_STRING, $whiteList->getType()); - } - - public function testCanValidateLoosely(): void - { - $whiteList = new WhiteList(['string1', 'string2', 3, 4]); - - $this->assertTrue($whiteList->isValid(3)); - $this->assertTrue($whiteList->isValid(4)); - $this->assertTrue($whiteList->isValid('string1')); - $this->assertTrue($whiteList->isValid('string2')); - $this->assertTrue($whiteList->isValid('STRING1')); - $this->assertTrue($whiteList->isValid('strIng1')); - $this->assertTrue($whiteList->isValid('3')); - $this->assertTrue($whiteList->isValid('4')); - $this->assertFalse($whiteList->isValid('string3')); - $this->assertFalse($whiteList->isValid(5)); - $this->assertEquals($whiteList->getList(), ['string1', 'string2', 3, 4]); - - $whiteList = new WhiteList(['STRING1', 'STRING2', 3, 4]); - - $this->assertTrue($whiteList->isValid(3)); - $this->assertTrue($whiteList->isValid(4)); - $this->assertTrue($whiteList->isValid('string1')); - $this->assertTrue($whiteList->isValid('string2')); - $this->assertTrue($whiteList->isValid('STRING1')); - $this->assertTrue($whiteList->isValid('strIng1')); - $this->assertTrue($whiteList->isValid('3')); - $this->assertTrue($whiteList->isValid('4')); - $this->assertFalse($whiteList->isValid('string3')); - $this->assertFalse($whiteList->isValid(5)); - $this->assertEquals($whiteList->getList(), ['string1', 'string2', 3, 4]); - } -} diff --git a/tests/Validator/WildcardTest.php b/tests/Validator/WildcardTest.php deleted file mode 100644 index 4de71475..00000000 --- a/tests/Validator/WildcardTest.php +++ /dev/null @@ -1,21 +0,0 @@ -assertTrue($validator->isValid([0 => 'string', 1 => 'string'])); - $this->assertTrue($validator->isValid('')); - $this->assertTrue($validator->isValid([])); - $this->assertTrue($validator->isValid(1)); - $this->assertTrue($validator->isValid(true)); - $this->assertTrue($validator->isValid(false)); - $this->assertFalse($validator->isArray()); - $this->assertEquals(\Utopia\Http\Validator::TYPE_STRING, $validator->getType()); - } -} diff --git a/tests/e2e/init.php b/tests/e2e/init.php index 54638fd9..fb0d9d59 100644 --- a/tests/e2e/init.php +++ b/tests/e2e/init.php @@ -5,7 +5,7 @@ use Utopia\Http\Http; use Utopia\Http\Request; use Utopia\Http\Response; -use Utopia\Http\Validator\Text; +use Utopia\Validator\Text; ini_set('memory_limit', '1024M'); ini_set('display_errors', '1');