diff --git a/README.md b/README.md
index 8aac0ffb..c097ba6e 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,8 @@
-[](https://travis-ci.org/utopia-php/framework)
-
+[](https://travis-ci.org/utopia-php/http)
+
[](https://discord.gg/GSeTUeA)
Utopia Framework is a PHP MVC based framework with minimal must-have features for professional, simple, advanced and secure web development. This library is maintained by the [Appwrite team](https://appwrite.io).
@@ -14,16 +14,16 @@ Utopia Framework is dependency free. Any extra features such as authentication,
Install using composer:
```bash
-composer require utopia-php/framework
+composer require utopia-php/http
```
Init your first application:
```php
require_once __DIR__ . '/../../vendor/autoload.php';
-use Utopia\App;
-use Utopia\Request;
-use Utopia\Response;
+use Utopia\HTTP\App;
+use Utopia\HTTP\Request;
+use Utopia\HTTP\Response;
App::get('/hello-world') // Define Route
->inject('request')
@@ -88,7 +88,7 @@ All code contributions - including those of people having commit access - must g
Fork the project, create a feature branch, and send us a pull request.
-You can refer to the [Contributing Guide](https://github.com/utopia-php/framework/blob/master/CONTRIBUTING.md) for more info.
+You can refer to the [Contributing Guide](https://github.com/utopia-php/http/blob/master/CONTRIBUTING.md) for more info.
For security issues, please email security@appwrite.io instead of posting a public issue in GitHub.
diff --git a/composer.json b/composer.json
index 567eaffb..002cf7da 100755
--- a/composer.json
+++ b/composer.json
@@ -1,8 +1,8 @@
{
- "name": "utopia-php/framework",
- "description": "A simple, light and advanced PHP framework",
+ "name": "utopia-php/http",
+ "description": "A simple, light and advanced PHP framework for building HTTP servers",
"type": "library",
- "keywords": ["php","framework", "upf"],
+ "keywords": ["php","framework", "upf", "http"],
"license": "MIT",
"minimum-stability": "stable",
"authors": [
@@ -12,12 +12,13 @@
}
],
"autoload": {
- "psr-4": {"Utopia\\": "src/"}
+ "psr-4": {"Utopia\\HTTP\\": "src/"}
},
"require": {
"php": ">=8.0.0"
},
"require-dev": {
+ "swoole/ide-helper": "4.8.5",
"phpunit/phpunit": "^9.5.10",
"vimeo/psalm": "4.13.1"
}
diff --git a/composer.lock b/composer.lock
index 6294b236..5a4bdfde 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,21 +4,21 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "5f1f57c1444e5e8c3956b48c3698769f",
+ "content-hash": "32adca63b220fdaa63164dcd749d66af",
"packages": [],
"packages-dev": [
{
"name": "amphp/amp",
- "version": "v2.6.1",
+ "version": "v2.6.2",
"source": {
"type": "git",
"url": "https://github.com/amphp/amp.git",
- "reference": "c5fc66a78ee38d7ac9195a37bacaf940eb3f65ae"
+ "reference": "9d5100cebffa729aaffecd3ad25dc5aeea4f13bb"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/amphp/amp/zipball/c5fc66a78ee38d7ac9195a37bacaf940eb3f65ae",
- "reference": "c5fc66a78ee38d7ac9195a37bacaf940eb3f65ae",
+ "url": "https://api.github.com/repos/amphp/amp/zipball/9d5100cebffa729aaffecd3ad25dc5aeea4f13bb",
+ "reference": "9d5100cebffa729aaffecd3ad25dc5aeea4f13bb",
"shasum": ""
},
"require": {
@@ -40,13 +40,13 @@
}
},
"autoload": {
- "psr-4": {
- "Amp\\": "lib"
- },
"files": [
"lib/functions.php",
"lib/Internal/functions.php"
- ]
+ ],
+ "psr-4": {
+ "Amp\\": "lib"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -71,7 +71,7 @@
}
],
"description": "A non-blocking concurrency framework for PHP applications.",
- "homepage": "http://amphp.org/amp",
+ "homepage": "https://amphp.org/amp",
"keywords": [
"async",
"asynchronous",
@@ -86,7 +86,7 @@
"support": {
"irc": "irc://irc.freenode.org/amphp",
"issues": "https://github.com/amphp/amp/issues",
- "source": "https://github.com/amphp/amp/tree/v2.6.1"
+ "source": "https://github.com/amphp/amp/tree/v2.6.2"
},
"funding": [
{
@@ -94,7 +94,7 @@
"type": "github"
}
],
- "time": "2021-09-23T18:43:08+00:00"
+ "time": "2022-02-20T17:52:18+00:00"
},
{
"name": "amphp/byte-stream",
@@ -129,12 +129,12 @@
}
},
"autoload": {
- "psr-4": {
- "Amp\\ByteStream\\": "lib"
- },
"files": [
"lib/functions.php"
- ]
+ ],
+ "psr-4": {
+ "Amp\\ByteStream\\": "lib"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -175,16 +175,16 @@
},
{
"name": "composer/package-versions-deprecated",
- "version": "1.11.99.4",
+ "version": "1.11.99.5",
"source": {
"type": "git",
"url": "https://github.com/composer/package-versions-deprecated.git",
- "reference": "b174585d1fe49ceed21928a945138948cb394600"
+ "reference": "b4f54f74ef3453349c24a845d22392cd31e65f1d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/b174585d1fe49ceed21928a945138948cb394600",
- "reference": "b174585d1fe49ceed21928a945138948cb394600",
+ "url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/b4f54f74ef3453349c24a845d22392cd31e65f1d",
+ "reference": "b4f54f74ef3453349c24a845d22392cd31e65f1d",
"shasum": ""
},
"require": {
@@ -228,7 +228,78 @@
"description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
"support": {
"issues": "https://github.com/composer/package-versions-deprecated/issues",
- "source": "https://github.com/composer/package-versions-deprecated/tree/1.11.99.4"
+ "source": "https://github.com/composer/package-versions-deprecated/tree/1.11.99.5"
+ },
+ "funding": [
+ {
+ "url": "https://packagist.com",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/composer",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/composer/composer",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2022-01-17T14:14:24+00:00"
+ },
+ {
+ "name": "composer/pcre",
+ "version": "1.0.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/composer/pcre.git",
+ "reference": "67a32d7d6f9f560b726ab25a061b38ff3a80c560"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/composer/pcre/zipball/67a32d7d6f9f560b726ab25a061b38ff3a80c560",
+ "reference": "67a32d7d6f9f560b726ab25a061b38ff3a80c560",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^5.3.2 || ^7.0 || ^8.0"
+ },
+ "require-dev": {
+ "phpstan/phpstan": "^1.3",
+ "phpstan/phpstan-strict-rules": "^1.1",
+ "symfony/phpunit-bridge": "^4.2 || ^5"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-main": "1.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Composer\\Pcre\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Jordi Boggiano",
+ "email": "j.boggiano@seld.be",
+ "homepage": "http://seld.be"
+ }
+ ],
+ "description": "PCRE wrapping library that offers type-safe preg_* replacements.",
+ "keywords": [
+ "PCRE",
+ "preg",
+ "regex",
+ "regular expression"
+ ],
+ "support": {
+ "issues": "https://github.com/composer/pcre/issues",
+ "source": "https://github.com/composer/pcre/tree/1.0.1"
},
"funding": [
{
@@ -244,27 +315,27 @@
"type": "tidelift"
}
],
- "time": "2021-09-13T08:41:34+00:00"
+ "time": "2022-01-21T20:24:37+00:00"
},
{
"name": "composer/semver",
- "version": "3.2.6",
+ "version": "3.2.9",
"source": {
"type": "git",
"url": "https://github.com/composer/semver.git",
- "reference": "83e511e247de329283478496f7a1e114c9517506"
+ "reference": "a951f614bd64dcd26137bc9b7b2637ddcfc57649"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/composer/semver/zipball/83e511e247de329283478496f7a1e114c9517506",
- "reference": "83e511e247de329283478496f7a1e114c9517506",
+ "url": "https://api.github.com/repos/composer/semver/zipball/a951f614bd64dcd26137bc9b7b2637ddcfc57649",
+ "reference": "a951f614bd64dcd26137bc9b7b2637ddcfc57649",
"shasum": ""
},
"require": {
"php": "^5.3.2 || ^7.0 || ^8.0"
},
"require-dev": {
- "phpstan/phpstan": "^0.12.54",
+ "phpstan/phpstan": "^1.4",
"symfony/phpunit-bridge": "^4.2 || ^5"
},
"type": "library",
@@ -309,7 +380,7 @@
"support": {
"irc": "irc://irc.freenode.org/composer",
"issues": "https://github.com/composer/semver/issues",
- "source": "https://github.com/composer/semver/tree/3.2.6"
+ "source": "https://github.com/composer/semver/tree/3.2.9"
},
"funding": [
{
@@ -325,29 +396,31 @@
"type": "tidelift"
}
],
- "time": "2021-10-25T11:34:17+00:00"
+ "time": "2022-02-04T13:58:43+00:00"
},
{
"name": "composer/xdebug-handler",
- "version": "2.0.2",
+ "version": "2.0.5",
"source": {
"type": "git",
"url": "https://github.com/composer/xdebug-handler.git",
- "reference": "84674dd3a7575ba617f5a76d7e9e29a7d3891339"
+ "reference": "9e36aeed4616366d2b690bdce11f71e9178c579a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/84674dd3a7575ba617f5a76d7e9e29a7d3891339",
- "reference": "84674dd3a7575ba617f5a76d7e9e29a7d3891339",
+ "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/9e36aeed4616366d2b690bdce11f71e9178c579a",
+ "reference": "9e36aeed4616366d2b690bdce11f71e9178c579a",
"shasum": ""
},
"require": {
+ "composer/pcre": "^1",
"php": "^5.3.2 || ^7.0 || ^8.0",
"psr/log": "^1 || ^2 || ^3"
},
"require-dev": {
- "phpstan/phpstan": "^0.12.55",
- "symfony/phpunit-bridge": "^4.2 || ^5"
+ "phpstan/phpstan": "^1.0",
+ "phpstan/phpstan-strict-rules": "^1.1",
+ "symfony/phpunit-bridge": "^4.2 || ^5.0 || ^6.0"
},
"type": "library",
"autoload": {
@@ -373,7 +446,7 @@
"support": {
"irc": "irc://irc.freenode.org/composer",
"issues": "https://github.com/composer/xdebug-handler/issues",
- "source": "https://github.com/composer/xdebug-handler/tree/2.0.2"
+ "source": "https://github.com/composer/xdebug-handler/tree/2.0.5"
},
"funding": [
{
@@ -389,7 +462,7 @@
"type": "tidelift"
}
],
- "time": "2021-07-31T17:03:58+00:00"
+ "time": "2022-02-24T20:20:32+00:00"
},
{
"name": "dnoegel/php-xdg-base-dir",
@@ -430,29 +503,30 @@
},
{
"name": "doctrine/instantiator",
- "version": "1.4.0",
+ "version": "1.4.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
- "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b"
+ "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/instantiator/zipball/d56bf6102915de5702778fe20f2de3b2fe570b5b",
- "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b",
+ "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc",
+ "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"require-dev": {
- "doctrine/coding-standard": "^8.0",
+ "doctrine/coding-standard": "^9",
"ext-pdo": "*",
"ext-phar": "*",
- "phpbench/phpbench": "^0.13 || 1.0.0-alpha2",
- "phpstan/phpstan": "^0.12",
- "phpstan/phpstan-phpunit": "^0.12",
- "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"
+ "phpbench/phpbench": "^0.16 || ^1",
+ "phpstan/phpstan": "^1.4",
+ "phpstan/phpstan-phpunit": "^1",
+ "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
+ "vimeo/psalm": "^4.22"
},
"type": "library",
"autoload": {
@@ -479,7 +553,7 @@
],
"support": {
"issues": "https://github.com/doctrine/instantiator/issues",
- "source": "https://github.com/doctrine/instantiator/tree/1.4.0"
+ "source": "https://github.com/doctrine/instantiator/tree/1.4.1"
},
"funding": [
{
@@ -495,7 +569,7 @@
"type": "tidelift"
}
],
- "time": "2020-11-10T18:47:58+00:00"
+ "time": "2022-03-03T08:28:38+00:00"
},
{
"name": "felixfbecker/advanced-json-rpc",
@@ -600,37 +674,38 @@
},
{
"name": "myclabs/deep-copy",
- "version": "1.10.2",
+ "version": "1.11.0",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
- "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220"
+ "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/776f831124e9c62e1a2c601ecc52e776d8bb7220",
- "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220",
+ "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614",
+ "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
- "replace": {
- "myclabs/deep-copy": "self.version"
+ "conflict": {
+ "doctrine/collections": "<1.6.8",
+ "doctrine/common": "<2.13.3 || >=3,<3.2.2"
},
"require-dev": {
- "doctrine/collections": "^1.0",
- "doctrine/common": "^2.6",
- "phpunit/phpunit": "^7.1"
+ "doctrine/collections": "^1.6.8",
+ "doctrine/common": "^2.13.3 || ^3.2.2",
+ "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13"
},
"type": "library",
"autoload": {
- "psr-4": {
- "DeepCopy\\": "src/DeepCopy/"
- },
"files": [
"src/DeepCopy/deep_copy.php"
- ]
+ ],
+ "psr-4": {
+ "DeepCopy\\": "src/DeepCopy/"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -646,7 +721,7 @@
],
"support": {
"issues": "https://github.com/myclabs/DeepCopy/issues",
- "source": "https://github.com/myclabs/DeepCopy/tree/1.10.2"
+ "source": "https://github.com/myclabs/DeepCopy/tree/1.11.0"
},
"funding": [
{
@@ -654,7 +729,7 @@
"type": "tidelift"
}
],
- "time": "2020-11-13T09:40:50+00:00"
+ "time": "2022-03-03T13:19:32+00:00"
},
{
"name": "netresearch/jsonmapper",
@@ -709,16 +784,16 @@
},
{
"name": "nikic/php-parser",
- "version": "v4.13.1",
+ "version": "v4.13.2",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
- "reference": "63a79e8daa781cac14e5195e63ed8ae231dd10fd"
+ "reference": "210577fe3cf7badcc5814d99455df46564f3c077"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/63a79e8daa781cac14e5195e63ed8ae231dd10fd",
- "reference": "63a79e8daa781cac14e5195e63ed8ae231dd10fd",
+ "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/210577fe3cf7badcc5814d99455df46564f3c077",
+ "reference": "210577fe3cf7badcc5814d99455df46564f3c077",
"shasum": ""
},
"require": {
@@ -759,9 +834,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
- "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.1"
+ "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.2"
},
- "time": "2021-11-03T20:52:16+00:00"
+ "time": "2021-11-30T19:35:32+00:00"
},
{
"name": "openlss/lib-array2xml",
@@ -878,16 +953,16 @@
},
{
"name": "phar-io/version",
- "version": "3.1.0",
+ "version": "3.2.1",
"source": {
"type": "git",
"url": "https://github.com/phar-io/version.git",
- "reference": "bae7c545bef187884426f042434e561ab1ddb182"
+ "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phar-io/version/zipball/bae7c545bef187884426f042434e561ab1ddb182",
- "reference": "bae7c545bef187884426f042434e561ab1ddb182",
+ "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74",
+ "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74",
"shasum": ""
},
"require": {
@@ -923,9 +998,9 @@
"description": "Library for handling version information and constraints",
"support": {
"issues": "https://github.com/phar-io/version/issues",
- "source": "https://github.com/phar-io/version/tree/3.1.0"
+ "source": "https://github.com/phar-io/version/tree/3.2.1"
},
- "time": "2021-02-23T14:00:09+00:00"
+ "time": "2022-02-21T01:04:05+00:00"
},
{
"name": "phpdocumentor/reflection-common",
@@ -1039,16 +1114,16 @@
},
{
"name": "phpdocumentor/type-resolver",
- "version": "1.5.1",
+ "version": "1.6.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
- "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae"
+ "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/a12f7e301eb7258bb68acd89d4aefa05c2906cae",
- "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae",
+ "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706",
+ "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706",
"shasum": ""
},
"require": {
@@ -1083,22 +1158,22 @@
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
"support": {
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
- "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.5.1"
+ "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0"
},
- "time": "2021-10-02T14:08:47+00:00"
+ "time": "2022-01-04T19:58:01+00:00"
},
{
"name": "phpspec/prophecy",
- "version": "1.14.0",
+ "version": "v1.15.0",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
- "reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e"
+ "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpspec/prophecy/zipball/d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e",
- "reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e",
+ "url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13",
+ "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13",
"shasum": ""
},
"require": {
@@ -1150,22 +1225,22 @@
],
"support": {
"issues": "https://github.com/phpspec/prophecy/issues",
- "source": "https://github.com/phpspec/prophecy/tree/1.14.0"
+ "source": "https://github.com/phpspec/prophecy/tree/v1.15.0"
},
- "time": "2021-09-10T09:02:12+00:00"
+ "time": "2021-12-08T12:19:24+00:00"
},
{
"name": "phpunit/php-code-coverage",
- "version": "9.2.9",
+ "version": "9.2.15",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "f301eb1453c9e7a1bc912ee8b0ea9db22c60223b"
+ "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f301eb1453c9e7a1bc912ee8b0ea9db22c60223b",
- "reference": "f301eb1453c9e7a1bc912ee8b0ea9db22c60223b",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2e9da11878c4202f97915c1cb4bb1ca318a63f5f",
+ "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f",
"shasum": ""
},
"require": {
@@ -1221,7 +1296,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
- "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.9"
+ "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.15"
},
"funding": [
{
@@ -1229,20 +1304,20 @@
"type": "github"
}
],
- "time": "2021-11-19T15:21:02+00:00"
+ "time": "2022-03-07T09:28:20+00:00"
},
{
"name": "phpunit/php-file-iterator",
- "version": "3.0.5",
+ "version": "3.0.6",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git",
- "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8"
+ "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/aa4be8575f26070b100fccb67faabb28f21f66f8",
- "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf",
+ "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf",
"shasum": ""
},
"require": {
@@ -1281,7 +1356,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
- "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.5"
+ "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6"
},
"funding": [
{
@@ -1289,7 +1364,7 @@
"type": "github"
}
],
- "time": "2020-09-28T05:57:25+00:00"
+ "time": "2021-12-02T12:48:52+00:00"
},
{
"name": "phpunit/php-invoker",
@@ -1474,16 +1549,16 @@
},
{
"name": "phpunit/phpunit",
- "version": "9.5.10",
+ "version": "9.5.18",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a"
+ "reference": "1b5856028273bfd855e60a887278857d872ec67a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c814a05837f2edb0d1471d6e3f4ab3501ca3899a",
- "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1b5856028273bfd855e60a887278857d872ec67a",
+ "reference": "1b5856028273bfd855e60a887278857d872ec67a",
"shasum": ""
},
"require": {
@@ -1499,7 +1574,7 @@
"phar-io/version": "^3.0.2",
"php": ">=7.3",
"phpspec/prophecy": "^1.12.1",
- "phpunit/php-code-coverage": "^9.2.7",
+ "phpunit/php-code-coverage": "^9.2.13",
"phpunit/php-file-iterator": "^3.0.5",
"phpunit/php-invoker": "^3.1.1",
"phpunit/php-text-template": "^2.0.3",
@@ -1534,11 +1609,11 @@
}
},
"autoload": {
- "classmap": [
- "src/"
- ],
"files": [
"src/Framework/Assert/Functions.php"
+ ],
+ "classmap": [
+ "src/"
]
},
"notification-url": "https://packagist.org/downloads/",
@@ -1561,11 +1636,11 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
- "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.10"
+ "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.18"
},
"funding": [
{
- "url": "https://phpunit.de/donate.html",
+ "url": "https://phpunit.de/sponsors.html",
"type": "custom"
},
{
@@ -1573,7 +1648,7 @@
"type": "github"
}
],
- "time": "2021-09-25T07:38:51+00:00"
+ "time": "2022-03-08T06:52:28+00:00"
},
{
"name": "psr/container",
@@ -2184,16 +2259,16 @@
},
{
"name": "sebastian/global-state",
- "version": "5.0.3",
+ "version": "5.0.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/global-state.git",
- "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49"
+ "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/23bd5951f7ff26f12d4e3242864df3e08dec4e49",
- "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49",
+ "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2",
+ "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2",
"shasum": ""
},
"require": {
@@ -2236,7 +2311,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/global-state/issues",
- "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.3"
+ "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5"
},
"funding": [
{
@@ -2244,7 +2319,7 @@
"type": "github"
}
],
- "time": "2021-06-11T13:31:12+00:00"
+ "time": "2022-02-14T08:28:10+00:00"
},
{
"name": "sebastian/lines-of-code",
@@ -2642,18 +2717,60 @@
],
"time": "2020-09-28T06:39:44+00:00"
},
+ {
+ "name": "swoole/ide-helper",
+ "version": "4.8.5",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/swoole/ide-helper.git",
+ "reference": "d03c707d4dc803228e93b4884c72949c4d28e8b8"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/swoole/ide-helper/zipball/d03c707d4dc803228e93b4884c72949c4d28e8b8",
+ "reference": "d03c707d4dc803228e93b4884c72949c4d28e8b8",
+ "shasum": ""
+ },
+ "type": "library",
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "Apache-2.0"
+ ],
+ "authors": [
+ {
+ "name": "Team Swoole",
+ "email": "team@swoole.com"
+ }
+ ],
+ "description": "IDE help files for Swoole.",
+ "support": {
+ "issues": "https://github.com/swoole/ide-helper/issues",
+ "source": "https://github.com/swoole/ide-helper/tree/4.8.5"
+ },
+ "funding": [
+ {
+ "url": "https://gitee.com/swoole/swoole?donate=true",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/swoole",
+ "type": "github"
+ }
+ ],
+ "time": "2021-12-24T22:44:20+00:00"
+ },
{
"name": "symfony/console",
- "version": "v6.0.0",
+ "version": "v6.0.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
- "reference": "675a4e6b05029a02ac43d3daf5aa73f039e876ea"
+ "reference": "3bebf4108b9e07492a2a4057d207aa5a77d146b1"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/console/zipball/675a4e6b05029a02ac43d3daf5aa73f039e876ea",
- "reference": "675a4e6b05029a02ac43d3daf5aa73f039e876ea",
+ "url": "https://api.github.com/repos/symfony/console/zipball/3bebf4108b9e07492a2a4057d207aa5a77d146b1",
+ "reference": "3bebf4108b9e07492a2a4057d207aa5a77d146b1",
"shasum": ""
},
"require": {
@@ -2719,7 +2836,7 @@
"terminal"
],
"support": {
- "source": "https://github.com/symfony/console/tree/v6.0.0"
+ "source": "https://github.com/symfony/console/tree/v6.0.5"
},
"funding": [
{
@@ -2735,25 +2852,28 @@
"type": "tidelift"
}
],
- "time": "2021-11-29T15:32:57+00:00"
+ "time": "2022-02-25T10:48:52+00:00"
},
{
"name": "symfony/polyfill-ctype",
- "version": "v1.23.0",
+ "version": "v1.25.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
- "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce"
+ "reference": "30885182c981ab175d4d034db0f6f469898070ab"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce",
- "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce",
+ "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab",
+ "reference": "30885182c981ab175d4d034db0f6f469898070ab",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
+ "provide": {
+ "ext-ctype": "*"
+ },
"suggest": {
"ext-ctype": "For best performance"
},
@@ -2768,12 +2888,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Ctype\\": ""
- },
"files": [
"bootstrap.php"
- ]
+ ],
+ "psr-4": {
+ "Symfony\\Polyfill\\Ctype\\": ""
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -2798,7 +2918,7 @@
"portable"
],
"support": {
- "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0"
+ "source": "https://github.com/symfony/polyfill-ctype/tree/v1.25.0"
},
"funding": [
{
@@ -2814,20 +2934,20 @@
"type": "tidelift"
}
],
- "time": "2021-02-19T12:13:01+00:00"
+ "time": "2021-10-20T20:35:02+00:00"
},
{
"name": "symfony/polyfill-intl-grapheme",
- "version": "v1.23.1",
+ "version": "v1.25.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-grapheme.git",
- "reference": "16880ba9c5ebe3642d1995ab866db29270b36535"
+ "reference": "81b86b50cf841a64252b439e738e97f4a34e2783"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/16880ba9c5ebe3642d1995ab866db29270b36535",
- "reference": "16880ba9c5ebe3642d1995ab866db29270b36535",
+ "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/81b86b50cf841a64252b439e738e97f4a34e2783",
+ "reference": "81b86b50cf841a64252b439e738e97f4a34e2783",
"shasum": ""
},
"require": {
@@ -2847,12 +2967,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Intl\\Grapheme\\": ""
- },
"files": [
"bootstrap.php"
- ]
+ ],
+ "psr-4": {
+ "Symfony\\Polyfill\\Intl\\Grapheme\\": ""
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -2879,7 +2999,7 @@
"shim"
],
"support": {
- "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.23.1"
+ "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.25.0"
},
"funding": [
{
@@ -2895,11 +3015,11 @@
"type": "tidelift"
}
],
- "time": "2021-05-27T12:26:48+00:00"
+ "time": "2021-11-23T21:10:46+00:00"
},
{
"name": "symfony/polyfill-intl-normalizer",
- "version": "v1.23.0",
+ "version": "v1.25.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git",
@@ -2928,12 +3048,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Intl\\Normalizer\\": ""
- },
"files": [
"bootstrap.php"
],
+ "psr-4": {
+ "Symfony\\Polyfill\\Intl\\Normalizer\\": ""
+ },
"classmap": [
"Resources/stubs"
]
@@ -2963,7 +3083,7 @@
"shim"
],
"support": {
- "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.23.0"
+ "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.25.0"
},
"funding": [
{
@@ -2983,21 +3103,24 @@
},
{
"name": "symfony/polyfill-mbstring",
- "version": "v1.23.1",
+ "version": "v1.25.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
- "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6"
+ "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9174a3d80210dca8daa7f31fec659150bbeabfc6",
- "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6",
+ "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825",
+ "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
+ "provide": {
+ "ext-mbstring": "*"
+ },
"suggest": {
"ext-mbstring": "For best performance"
},
@@ -3012,12 +3135,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Mbstring\\": ""
- },
"files": [
"bootstrap.php"
- ]
+ ],
+ "psr-4": {
+ "Symfony\\Polyfill\\Mbstring\\": ""
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -3043,7 +3166,7 @@
"shim"
],
"support": {
- "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.1"
+ "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.25.0"
},
"funding": [
{
@@ -3059,7 +3182,7 @@
"type": "tidelift"
}
],
- "time": "2021-05-27T12:26:48+00:00"
+ "time": "2021-11-30T18:21:41+00:00"
},
{
"name": "symfony/service-contracts",
@@ -3145,16 +3268,16 @@
},
{
"name": "symfony/string",
- "version": "v6.0.0",
+ "version": "v6.0.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/string.git",
- "reference": "ba727797426af0f587f4800566300bdc0cda0777"
+ "reference": "522144f0c4c004c80d56fa47e40e17028e2eefc2"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/string/zipball/ba727797426af0f587f4800566300bdc0cda0777",
- "reference": "ba727797426af0f587f4800566300bdc0cda0777",
+ "url": "https://api.github.com/repos/symfony/string/zipball/522144f0c4c004c80d56fa47e40e17028e2eefc2",
+ "reference": "522144f0c4c004c80d56fa47e40e17028e2eefc2",
"shasum": ""
},
"require": {
@@ -3175,12 +3298,12 @@
},
"type": "library",
"autoload": {
- "psr-4": {
- "Symfony\\Component\\String\\": ""
- },
"files": [
"Resources/functions.php"
],
+ "psr-4": {
+ "Symfony\\Component\\String\\": ""
+ },
"exclude-from-classmap": [
"/Tests/"
]
@@ -3210,7 +3333,7 @@
"utf8"
],
"support": {
- "source": "https://github.com/symfony/string/tree/v6.0.0"
+ "source": "https://github.com/symfony/string/tree/v6.0.3"
},
"funding": [
{
@@ -3226,7 +3349,7 @@
"type": "tidelift"
}
],
- "time": "2021-10-29T07:35:21+00:00"
+ "time": "2022-01-02T09:55:41+00:00"
},
{
"name": "theseer/tokenizer",
@@ -3355,13 +3478,13 @@
}
},
"autoload": {
- "psr-4": {
- "Psalm\\": "src/Psalm/"
- },
"files": [
"src/functions.php",
"src/spl_object_id.php"
- ]
+ ],
+ "psr-4": {
+ "Psalm\\": "src/Psalm/"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -3503,5 +3626,5 @@
"php": ">=8.0.0"
},
"platform-dev": [],
- "plugin-api-version": "2.1.0"
+ "plugin-api-version": "2.0.0"
}
diff --git a/docker-compose.yml b/docker-compose.yml
index 55ad1dfc..f05d4d6b 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -6,4 +6,5 @@ services:
ports:
- "9020:80"
volumes:
+ - .:/usr/share/nginx/html
- ./tests:/usr/share/nginx/html/tests
\ No newline at end of file
diff --git a/docs/Getting-Starting-Guide.md b/docs/Getting-Starting-Guide.md
index 4a350d15..b87be2aa 100644
--- a/docs/Getting-Starting-Guide.md
+++ b/docs/Getting-Starting-Guide.md
@@ -9,9 +9,9 @@ If you’re new to Utopia, let’s get started by looking at an example of a bas
## Basic GET Route
```php
-use Utopia\App;
-use Utopia\Swoole\Request;
-use Utopia\Swoole\Response;
+use Utopia\HTTP\App;
+use Utopia\HTTP\Swoole\Request;
+use Utopia\HTTP\Swoole\Response;
use Swoole\Http\Server;
use Swoole\Http\Request as SwooleRequest;
use Swoole\Http\Response as SwooleResponse;
@@ -130,7 +130,7 @@ $response
->send('')
```
-You can find the details of other status codes by visiting our [GitHub repository](https://github.com/utopia-php/framework/blob/master/src/Response.php).
+You can find the details of other status codes by visiting our [GitHub repository](https://github.com/utopia-php/http/blob/master/src/Response.php).
# Advanced Utopia
@@ -138,13 +138,13 @@ You can find the details of other status codes by visiting our [GitHub repositor
Let's make the above example slightly advanced by adding more properties.
```php
-use Utopia\App;
-use Utopia\Swoole\Request;
-use Utopia\Swoole\Response;
+use Utopia\HTTP\App;
+use Utopia\HTTP\Swoole\Request;
+use Utopia\HTTP\Swoole\Response;
use Swoole\Http\Server;
use Swoole\Http\Request as SwooleRequest;
use Swoole\Http\Response as SwooleResponse;
-use Utopia\Validator\Wildcard;
+use Utopia\HTTP\Validator\Wildcard;
$http = new Server("0.0.0.0", 8080);
@@ -280,7 +280,7 @@ App::shutdown(function($request) {
An example of the shutdown method is shown above. The shutdown method uses the Utopia CLI lib to log api to the console; this is done for routes in the `api` group in the current example.
# Running Locally
-If you have PHP and Composer installed on your device, you can run Utopia apps locally by downloading the Utopia-PHP/framework dependency using `composer require utopia-php/framework` command.
+If you have PHP and Composer installed on your device, you can run Utopia apps locally by downloading the utopia-php/http dependency using `composer require utopia-php/http` command.
> Utopia Framework requires PHP 7.3 or later. We recommend using the latest PHP version whenever possible.
diff --git a/src/Adapter.php b/src/Adapter.php
new file mode 100644
index 00000000..0081f19c
--- /dev/null
+++ b/src/Adapter.php
@@ -0,0 +1,35 @@
+
+ */
+abstract class Adapter
+{
+ protected string $host;
+ protected int $port;
+
+ function __construct(string $host = '0.0.0.0', int $port = 80) {
+ $this->host = $host;
+ $this->port = $port;
+ }
+
+ /**
+ * Starts the Server.
+ * @return void
+ */
+ public abstract function start(): void;
+
+ /**
+ * Shuts down the Server.
+ * @return void
+ */
+ public abstract function end(): void;
+}
\ No newline at end of file
diff --git a/src/Adapter/FPM/Request.php b/src/Adapter/FPM/Request.php
new file mode 100755
index 00000000..e883338e
--- /dev/null
+++ b/src/Adapter/FPM/Request.php
@@ -0,0 +1,361 @@
+
+ * @license The MIT License (MIT)
+ */
+
+namespace Utopia\HTTP\Adapter\FPM;
+
+use Utopia\HTTP\Request as HTTPRequest;
+
+class Request extends HTTPRequest
+{
+ /**
+ * Get Param
+ *
+ * Get param by current method name
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function getParam(string $key, mixed $default = null): mixed
+ {
+ switch ($this->getServer('REQUEST_METHOD', '')) {
+ case self::METHOD_GET:
+ return $this->getQuery($key, $default);
+ break;
+ case self::METHOD_POST:
+ case self::METHOD_PUT:
+ case self::METHOD_PATCH:
+ case self::METHOD_DELETE:
+ return $this->getPayload($key, $default);
+ break;
+ default:
+ return $this->getQuery($key, $default);
+ }
+ }
+
+ /**
+ * Get Params
+ *
+ * Get all params of current method
+ *
+ * @return array
+ */
+ public function getParams(): array
+ {
+ switch ($this->getServer('REQUEST_METHOD', '')) {
+ case self::METHOD_GET:
+ return $_GET;
+ break;
+ case self::METHOD_POST:
+ case self::METHOD_PUT:
+ case self::METHOD_PATCH:
+ case self::METHOD_DELETE:
+ return $this->generateInput();
+ break;
+ default:
+ return $_GET;
+ }
+ }
+
+ /**
+ * Get Query
+ *
+ * Method for querying HTTP GET request parameters. If $key is not found $default value will be returned.
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function getQuery(string $key, mixed $default = null): mixed
+ {
+ return (isset($_GET[$key])) ? $_GET[$key] : $default;
+ }
+
+ /**
+ * Get payload
+ *
+ * Method for querying HTTP request payload parameters. If $key is not found $default value will be returned.
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function getPayload(string $key, mixed $default = null): mixed
+ {
+ $payload = $this->generateInput();
+
+ return (isset($payload[$key])) ? $payload[$key] : $default;
+ }
+
+ /**
+ * Get server
+ *
+ * Method for querying server parameters. If $key is not found $default value will be returned.
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function getServer(string $key, mixed $default = null): mixed
+ {
+ return (isset($_SERVER[$key])) ? $_SERVER[$key] : $default;
+ }
+
+ /**
+ * Get IP
+ *
+ * Returns users IP address.
+ * Support HTTP_X_FORWARDED_FOR header usually return
+ * from different proxy servers or PHP default REMOTE_ADDR
+ *
+ * @return string
+ */
+ public function getIP(): string
+ {
+ $ips = explode(',',$this->getHeader('HTTP_X_FORWARDED_FOR', $this->getServer('REMOTE_ADDR', '0.0.0.0')));
+ return trim($ips[0] ?? '');
+ }
+
+ /**
+ * Get Protocol
+ *
+ * Returns request protocol.
+ * Support HTTP_X_FORWARDED_PROTO header usually return
+ * from different proxy servers or PHP default REQUEST_SCHEME
+ *
+ * @return string
+ */
+ public function getProtocol(): string
+ {
+ return $this->getServer('HTTP_X_FORWARDED_PROTO', $this->getServer('REQUEST_SCHEME', 'https'));
+ }
+
+ /**
+ * Get Port
+ *
+ * Returns request port.
+ *
+ * @return string
+ */
+ public function getPort(): string
+ {
+ return (string) \parse_url($this->getProtocol().'://'.$this->getServer('HTTP_HOST', ''), PHP_URL_PORT);
+ }
+
+ /**
+ * Get Hostname
+ *
+ * Returns request hostname.
+ *
+ * @return string
+ */
+ public function getHostname(): string
+ {
+ return (string) \parse_url($this->getProtocol().'://'.$this->getServer('HTTP_HOST', ''), PHP_URL_HOST);
+ }
+
+ /**
+ * Get Method
+ *
+ * Return HTTP request method
+ *
+ * @return string
+ */
+ public function getMethod(): string
+ {
+ return $this->getServer('REQUEST_METHOD', 'UNKNOWN');
+ }
+
+ /**
+ * Get URI
+ *
+ * Return HTTP request URI
+ *
+ * @return string
+ */
+ public function getURI(): string
+ {
+ return $this->getServer('REQUEST_URI', '');
+ }
+
+ /**
+ * Get files
+ *
+ * Method for querying upload files data. If $key is not found empty array will be returned.
+ *
+ * @param string $key
+ * @return array
+ */
+ public function getFiles(string $key): array
+ {
+ return (isset($_FILES[$key])) ? $_FILES[$key] : [];
+ }
+
+ /**
+ * Get Referer
+ *
+ * Return HTTP referer header
+ *
+ * @return string
+ */
+ public function getReferer(string $default = ''): string
+ {
+ return (string) $this->getServer('HTTP_REFERER', $default);
+ }
+
+ /**
+ * Get Origin
+ *
+ * Return HTTP origin header
+ *
+ * @return string
+ */
+ public function getOrigin(string $default = ''): string
+ {
+ return (string) $this->getServer('HTTP_ORIGIN', $default);
+ }
+
+ /**
+ * Get User Agent
+ *
+ * Return HTTP user agent header
+ *
+ * @return string
+ */
+ public function getUserAgent(string $default = ''): string
+ {
+ return (string) $this->getServer('HTTP_USER_AGENT', $default);
+ }
+
+ /**
+ * Get Accept
+ *
+ * Return HTTP accept header
+ *
+ * @return string
+ */
+ public function getAccept(string $default = ''): string
+ {
+ return (string) $this->getServer('HTTP_ACCEPT', $default);
+ }
+
+ /**
+ * Get cookie
+ *
+ * Method for querying HTTP cookie parameters. If $key is not found $default value will be returned.
+ *
+ * @param string $key
+ * @param string $default
+ * @return string
+ */
+ public function getCookie(string $key, string $default = ''): string
+ {
+ return (isset($_COOKIE[$key])) ? $_COOKIE[$key] : $default;
+ }
+
+ /**
+ * Get header
+ *
+ * Method for querying HTTP header parameters. If $key is not found $default value will be returned.
+ *
+ * @param string $key
+ * @param string $default
+ * @return string
+ */
+ public function getHeader(string $key, string $default = ''): string
+ {
+ $headers = $this->generateHeaders();
+
+ return (isset($headers[$key])) ? $headers[$key] : $default;
+ }
+
+ /**
+ * Get Request Size
+ *
+ * Returns request size in bytes
+ *
+ * @return int
+ */
+ public function getSize(): int
+ {
+ return \mb_strlen(\implode("\n", $this->generateHeaders()), '8bit') + \mb_strlen(\file_get_contents('php://input'), '8bit');
+ }
+
+ /**
+ * Generate input
+ *
+ * Generate PHP input stream and parse it as an array in order to handle different content type of requests
+ *
+ * @return array
+ */
+ protected function generateInput(): array
+ {
+ if (null === $this->payload) {
+ $contentType = $this->getHeader('content-type');
+
+ // Get content-type without the charset
+ $length = \strpos($contentType, ';');
+ $length = (empty($length)) ? \strlen($contentType) : $length;
+ $contentType = \substr($contentType, 0, $length);
+
+ switch ($contentType) {
+ case 'application/json':
+ $this->payload = \json_decode(\file_get_contents('php://input'), true);
+ break;
+
+ default:
+ $this->payload = $_POST;
+ break;
+ }
+
+ if (empty($this->payload)) { // Make sure we return same data type even if json payload is empty or failed
+ $this->payload = [];
+ }
+ }
+
+ return $this->payload;
+ }
+
+ /**
+ * Generate headers
+ *
+ * Parse request headers as an array for easy querying using the getHeader method
+ *
+ * @return array
+ */
+ protected function generateHeaders(): array
+ {
+ if (null === $this->headers) {
+ /**
+ * Fallback for older PHP versions
+ * that do not support generateHeaders
+ */
+ if (!\function_exists('getallheaders')) {
+ $headers = [];
+
+ foreach ($_SERVER as $name => $value) {
+ if (\substr($name, 0, 5) == 'HTTP_') {
+ $headers[\str_replace(' ', '-', \strtolower(\str_replace('_', ' ', \substr($name, 5))))] = $value;
+ }
+ }
+
+ $this->headers = $headers;
+
+ return $this->headers;
+ }
+
+ $this->headers = array_change_key_case(getallheaders());
+ }
+
+ return $this->headers;
+ }
+}
diff --git a/src/Adapter/FPM/Response.php b/src/Adapter/FPM/Response.php
new file mode 100755
index 00000000..6ac6caef
--- /dev/null
+++ b/src/Adapter/FPM/Response.php
@@ -0,0 +1,91 @@
+
+ * @license The MIT License (MIT)
+ */
+
+namespace Utopia\HTTP\Adapter\FPM;
+
+use Utopia\HTTP\Response as HTTPResponse;
+
+class Response extends HTTPResponse
+{
+ /**
+ * Send Status Code
+ *
+ * @param int $statusCode
+ *
+ * @return void
+ */
+ protected function sendStatus(int $statusCode): void
+ {
+ http_response_code($statusCode);
+ }
+
+ /**
+ * Send Header
+ *
+ * Output Header
+ *
+ * @param string $key
+ * @param string $value
+ *
+ * @return void
+ */
+ protected function sendHeader(string $key, string $value): void
+ {
+ \header($key . ': ' . $value);
+ }
+
+ /**
+ * Send Cookie
+ *
+ * Output Cookie
+ *
+ * @param string $name
+ * @param string $value
+ * @param array $options
+ *
+ * @return void
+ */
+ protected function sendCookie(string $name, string $value, array $options): void
+ {
+ \setcookie($name, $value, $options);
+ }
+
+ /**
+ * Write
+ *
+ * Send output
+ *
+ * @param string $content
+ *
+ * @return void
+ */
+ protected function write(string $content): void
+ {
+ echo $content;
+ }
+
+ /**
+ * End
+ *
+ * Send optional content and end
+ *
+ * @param string $content
+ *
+ * @return void
+ */
+ protected function end(string $content = null): void
+ {
+ if(!is_null($content)) {
+ echo $content;
+ }
+ }
+}
diff --git a/src/Adapter/Swoole/Files.php b/src/Adapter/Swoole/Files.php
new file mode 100644
index 00000000..7b042e49
--- /dev/null
+++ b/src/Adapter/Swoole/Files.php
@@ -0,0 +1,176 @@
+ 'text/css',
+ 'js' => 'text/javascript',
+ 'svg' => 'image/svg+xml',
+ ];
+
+ /**
+ * Add MimeType
+ *
+ * @param string $mimeType
+ *
+ * @return void
+ */
+ public static function addMimeType(string $mimeType): void
+ {
+ self::$mimeTypes[$mimeType] = true;
+ }
+
+ /**
+ * Remove MimeType
+ *
+ * @param string $mimeType
+ *
+ * @return void
+ */
+ public static function removeMimeType(string $mimeType): void
+ {
+ if(isset(self::$mimeTypes[$mimeType])) {
+ unset(self::$mimeTypes[$mimeType]);
+ }
+ }
+
+ /**
+ * Get MimeType List
+ *
+ * @return array
+ */
+ public static function getMimeTypes(): array
+ {
+ return self::$mimeTypes;
+ }
+
+ /**
+ * Get Files Loaded Count
+ *
+ * @return int
+ */
+ public static function getCount(): int
+ {
+ return self::$count;
+ }
+
+ /**
+ * Load
+ *
+ * @param string $path
+ *
+ * @return void
+ */
+ public static function load(string $directory, string $root = null): void
+ {
+ if(!is_readable($directory)) {
+ throw new Exception('Failed to load directory: '.$directory);
+ }
+
+ $directory = realpath($directory);
+
+ $root = ($root) ? $root : $directory;
+
+ $handle = opendir($directory);
+
+ while ($path = readdir($handle)) {
+ $extension = pathinfo($path, PATHINFO_EXTENSION);
+
+ if (in_array($path, ['.', '..'])) {
+ continue;
+ }
+
+ if (in_array($extension, ['php', 'phtml'])) {
+ continue;
+ }
+
+ if(substr($path, 0, 1) === '.') {
+ continue;
+ }
+
+ if (is_dir($directory.'/'.$path)) {
+ self::load($directory.'/'.$path, $root);
+ continue;
+ }
+
+ self::$count++;
+
+ self::$loaded[substr($directory.'/'.$path , strlen($root))] = [
+ 'contents' => file_get_contents($directory.'/'.$path),
+ 'mimeType' => (array_key_exists($extension, self::$extensions))
+ ? self::$extensions[$extension]
+ : mime_content_type($directory.'/'.$path)
+ ];
+ }
+
+ closedir($handle);
+
+ if($directory === $root) {
+ echo '[Static Files] Loadded '.self::$count.' files'.PHP_EOL;
+ }
+ }
+
+ /**
+ * Is File Loaded
+ *
+ * @param string $uri
+ */
+ public static function isFileLoaded(string $uri): bool
+ {
+ if(!array_key_exists($uri, self::$loaded)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Get File Contants
+ *
+ * @param string $uri
+ */
+ public static function getFileContents(string $uri): string
+ {
+ if(!array_key_exists($uri, self::$loaded)) {
+ throw new Exception('File not found or not loaded: '.$uri);
+ }
+
+ return self::$loaded[$uri]['contents'];
+ }
+
+ /**
+ * Get File MimeType
+ *
+ * @param string $uri
+ */
+ public static function getFileMimeType(string $uri): string
+ {
+ if(!array_key_exists($uri, self::$loaded)) {
+ throw new Exception('File not found or not loaded: '.$uri);
+ }
+
+ return self::$loaded[$uri]['mimeType'];
+ }
+}
diff --git a/src/Adapter/Swoole/Request.php b/src/Adapter/Swoole/Request.php
new file mode 100644
index 00000000..4017d157
--- /dev/null
+++ b/src/Adapter/Swoole/Request.php
@@ -0,0 +1,352 @@
+swoole = $request;
+ }
+
+ /**
+ * Get Param
+ *
+ * Get param by current method name
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function getParam(string $key, $default = null): mixed
+ {
+ switch($this->getMethod()) {
+ case self::METHOD_GET:
+ return $this->getQuery($key, $default);
+ break;
+ case self::METHOD_POST:
+ case self::METHOD_PUT:
+ case self::METHOD_PATCH:
+ case self::METHOD_DELETE:
+ return $this->getPayload($key, $default);
+ break;
+ default:
+ return $this->getQuery($key, $default);
+ }
+ }
+
+ /**
+ * Get Params
+ *
+ * Get all params of current method
+ *
+ * @return array
+ */
+ public function getParams(): array
+ {
+ switch($this->getMethod()) {
+ case self::METHOD_GET:
+ return (!empty($this->swoole->get)) ? $this->swoole->get : [];
+ break;
+ case self::METHOD_POST:
+ case self::METHOD_PUT:
+ case self::METHOD_PATCH:
+ case self::METHOD_DELETE:
+ return $this->generateInput();
+ break;
+ default:
+ return (!empty($this->swoole->get)) ? $this->swoole->get : [];
+ }
+
+ return [];
+ }
+
+ /**
+ * Get Query
+ *
+ * Method for querying HTTP GET request parameters. If $key is not found $default value will be returned.
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function getQuery(string $key, $default = null): mixed
+ {
+ return (isset($this->swoole->get[$key])) ? $this->swoole->get[$key] : $default;
+ }
+
+ /**
+ * Get payload
+ *
+ * Method for querying HTTP request payload parameters. If $key is not found $default value will be returned.
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function getPayload(string $key, $default = null): mixed
+ {
+ $payload = $this->generateInput();
+
+ return (isset($payload[$key])) ? $payload[$key] : $default;
+ }
+
+ /**
+ * Get server
+ *
+ * Method for querying server parameters. If $key is not found $default value will be returned.
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function getServer(string $key, $default = null): mixed
+ {
+ return (isset($this->swoole->server) && isset($this->swoole->server[$key])) ? $this->swoole->server[$key] : $default;
+ }
+
+ /**
+ * Get IP
+ *
+ * Returns users IP address.
+ * Support HTTP_X_FORWARDED_FOR header usually return
+ * from different proxy servers or PHP default REMOTE_ADDR
+ */
+ public function getIP(): string
+ {
+ $ips = explode(',',$this->getHeader('x-forwarded-for', $this->getServer('remote_addr', '0.0.0.0')));
+ return trim($ips[0] ?? '');
+ }
+
+ /**
+ * Get Protocol
+ *
+ * Returns request protocol.
+ * Support HTTP_X_FORWARDED_PROTO header usually return
+ * from different proxy servers or PHP default REQUEST_SCHEME
+ *
+ * @return string
+ */
+ public function getProtocol(): string
+ {
+ $protocol = $this->getHeader('x-forwarded-proto', $this->getServer('server_protocol', 'https'));
+
+ if($protocol === 'HTTP/1.1') {
+ return 'http';
+ }
+
+ return $protocol;
+ }
+
+ /**
+ * Get Port
+ *
+ * Returns request port.
+ *
+ * @return string
+ */
+ public function getPort(): string
+ {
+ return $this->getHeader('x-forwarded-port', (string)\parse_url($this->getProtocol().'://'.$this->getHeader('x-forwarded-host', $this->getHeader('host')), PHP_URL_PORT));
+ }
+
+ /**
+ * Get Hostname
+ *
+ * Returns request hostname.
+ *
+ * @return string
+ */
+ public function getHostname(): string
+ {
+ return \parse_url($this->getProtocol().'://'.$this->getHeader('x-forwarded-host', $this->getHeader('host')), PHP_URL_HOST);
+ }
+
+ /**
+ * Get Method
+ *
+ * Return HTTP request method
+ *
+ * @return string
+ */
+ public function getMethod(): string
+ {
+ return $this->getServer('request_method', 'UNKNOWN');
+ }
+
+ /**
+ * Get URI
+ *
+ * Return HTTP request URI
+ *
+ * @return string
+ */
+ public function getURI(): string
+ {
+ return $this->getServer('request_uri', '');
+ }
+
+ /**
+ * Get Referer
+ *
+ * Return HTTP referer header
+ *
+ * @return string
+ */
+ public function getReferer(string $default = ''): string
+ {
+ return $this->getHeader('referer', '');
+ }
+
+ /**
+ * Get Origin
+ *
+ * Return HTTP origin header
+ *
+ * @return string
+ */
+ public function getOrigin(string $default = ''): string
+ {
+ return $this->getHeader('origin', $default);
+ }
+
+ /**
+ * Get User Agent
+ *
+ * Return HTTP user agent header
+ *
+ * @return string
+ */
+ public function getUserAgent(string $default = ''): string
+ {
+ return $this->getHeader('user-agent', $default);
+ }
+
+ /**
+ * Get Accept
+ *
+ * Return HTTP accept header
+ *
+ * @return string
+ */
+ public function getAccept(string $default = ''): string
+ {
+ return $this->getHeader('accept', $default);
+ }
+
+ /**
+ * Get files
+ *
+ * Method for querying upload files data. If $key is not found empty array will be returned.
+ *
+ * @param string $key
+ * @return array
+ */
+ public function getFiles($key): array
+ {
+ $key = strtolower($key);
+ return (isset($this->swoole->files[$key])) ? $this->swoole->files[$key] : [];
+ }
+
+ /**
+ * Get cookie
+ *
+ * Method for querying HTTP cookie parameters. If $key is not found $default value will be returned.
+ *
+ * @param string $key
+ * @param string $default
+ * @return string
+ */
+ public function getCookie(string $key, string $default = ''): string
+ {
+ $key = strtolower($key);
+ return (isset($this->swoole->cookie[$key])) ? $this->swoole->cookie[$key] : $default;
+ }
+
+ /**
+ * Get header
+ *
+ * Method for querying HTTP header parameters. If $key is not found $default value will be returned.
+ *
+ * @param string $key
+ * @param string $default
+ * @return string
+ */
+ public function getHeader(string $key, string $default = ''): string
+ {
+ return (isset($this->swoole->header[$key])) ? $this->swoole->header[$key] : $default;
+ }
+
+ /**
+ * Generate input
+ *
+ * Generate PHP input stream and parse it as an array in order to handle different content type of requests
+ *
+ * @return array
+ */
+ protected function generateInput(): array
+ {
+ if (null === $this->payload) {
+ $contentType = $this->getHeader('content-type');
+
+ // Get content-type without the charset
+ $length = strpos($contentType, ';');
+ $length = (empty($length)) ? strlen($contentType) : $length;
+ $contentType = substr($contentType, 0, $length);
+
+ switch ($contentType) {
+ case 'application/json':
+ $this->payload = json_decode($this->swoole->rawContent(), true);
+ break;
+
+ default:
+ $this->payload = $this->swoole->post;
+ break;
+ }
+
+ if(empty($this->payload)) { // Make sure we return same data type even if json payload is empty or failed
+ $this->payload = [];
+ }
+ }
+
+ return $this->payload;
+ }
+
+ /**
+ * Generate headers
+ *
+ * Parse request headers as an array for easy querying using the getHeader method
+ *
+ * @return array
+ */
+ protected function generateHeaders(): array
+ {
+ return $this->swoole->header;
+ }
+
+ /**
+ * Get Request Size
+ *
+ * Returns request size in bytes
+ *
+ * @return int
+ */
+ public function getSize(): int
+ {
+ throw new Exception('not implemented');
+ }
+}
\ No newline at end of file
diff --git a/src/Adapter/Swoole/Response.php b/src/Adapter/Swoole/Response.php
new file mode 100644
index 00000000..a6676d1d
--- /dev/null
+++ b/src/Adapter/Swoole/Response.php
@@ -0,0 +1,120 @@
+ true,
+ 'text/css' => true,
+ 'text/javascript' => true,
+ 'application/javascript' => true,
+ 'text/html' => true,
+ 'text/html; charset=UTF-8' => true,
+ 'application/json' => true,
+ 'application/json; charset=UTF-8' => true,
+ 'image/svg+xml' => true,
+ 'application/xml+rss' => true,
+ ];
+
+ /**
+ * Response constructor.
+ *
+ * @param SwooleResponse $response
+ */
+ public function __construct(SwooleResponse $response)
+ {
+ $this->swoole = $response;
+ parent::__construct(\microtime(true));
+ }
+
+ /**
+ * Write
+ *
+ * @param string $content
+ *
+ * @return void
+ */
+ protected function write(string $content): void
+ {
+ $this->swoole->write($content);
+ }
+
+ /**
+ * End
+ *
+ * @param string $content
+ *
+ * @return void
+ */
+ protected function end(string $content=null): void
+ {
+ $this->swoole->end($content);
+ }
+
+ /**
+ * Send Status Code
+ *
+ * @param int $statusCode
+ *
+ * @return void
+ */
+ protected function sendStatus(int $statusCode): void
+ {
+ $this->swoole->status($statusCode);
+ }
+
+ /**
+ * Send Header
+ *
+ * @param string $key
+ * @param string $value
+ *
+ * @return void
+ */
+ protected function sendHeader(string $key, string $value): void
+ {
+ $this->swoole->header($key, $value);
+ }
+
+ /**
+ * Send Cookie
+ *
+ * Send a cookie
+ *
+ * @param string $name
+ * @param string $value
+ * @param array $options
+ *
+ * @return void
+ */
+ protected function sendCookie(string $name, string $value, array $options): void
+ {
+ $this->swoole->cookie(
+ $name,
+ $value,
+ $options['expire'] ?? 0,
+ $options['path'] ?? "",
+ $options['domain'] ?? "",
+ $options['secure'] ?? false,
+ $options['httponly'] ?? false,
+ $options['samesite'] ?? false,
+ );
+ }
+}
\ No newline at end of file
diff --git a/src/Adapter/Swoole/Server.php b/src/Adapter/Swoole/Server.php
new file mode 100644
index 00000000..213dab8f
--- /dev/null
+++ b/src/Adapter/Swoole/Server.php
@@ -0,0 +1,73 @@
+
+ */
+class Server
+{
+ protected SwooleServer $server;
+ protected string $host;
+ protected int $port;
+
+ function __construct(string $host = '0.0.0.0', int $port = 80) {
+ $this->host = $host;
+ $this->port = $port;
+ $this->server = new SwooleServer($host, $port);
+ }
+
+ /**
+ * Starts the Server.
+ * @return void
+ */
+ public function start(): void
+ {
+ Files::load(__DIR__ . '/../public');
+
+ $this->server->on('start', function (Server $http) {
+ // $app = new App('UTC');
+ });
+
+ $this->server->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swooleResponse) {
+ $request = new Request($swooleRequest);
+ $response = new Response($swooleResponse);
+
+ if(Files::isFileLoaded($request->getURI())) {
+ $time = (60 * 60 * 24 * 365 * 2); // 45 days cache
+
+ return $response
+ ->setContentType(Files::getFileMimeType($request->getURI()))
+ ->addHeader('Cache-Control', 'public, max-age='.$time)
+ ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time).' GMT') // 45 days cache
+ ->send(Files::getFileContents($request->getURI()))
+ ;
+ }
+
+ $app = new App('UTC');
+
+ $app
+ ->run($request, $response);
+ });
+ }
+
+ /**
+ * Shuts down the Server.
+ * @return void
+ */
+ public function end(): void
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/src/App.php b/src/App.php
index 6bacb570..59e74929 100755
--- a/src/App.php
+++ b/src/App.php
@@ -1,15 +1,15 @@
*/
-namespace Utopia;
+namespace Utopia\HTTP;
class App
{
@@ -781,5 +781,4 @@ public static function reset(): void
];
self::$sorted = false;
}
-
-}
+}
\ No newline at end of file
diff --git a/src/Exception.php b/src/Exception.php
index 88118f0f..87692e79 100644
--- a/src/Exception.php
+++ b/src/Exception.php
@@ -1,16 +1,16 @@
* @license The MIT License (MIT)
*/
-namespace Utopia;
+namespace Utopia\HTTP;
class Exception extends \Exception
{
diff --git a/src/Request.php b/src/Request.php
index 60692d7f..7aef5685 100755
--- a/src/Request.php
+++ b/src/Request.php
@@ -1,18 +1,18 @@
* @license The MIT License (MIT)
*/
-namespace Utopia;
+namespace Utopia\HTTP;
-class Request
+abstract class Request
{
/**
* HTTP methods
@@ -50,22 +50,7 @@ class Request
* @param mixed $default
* @return mixed
*/
- public function getParam(string $key, mixed $default = null)
- {
- switch ($this->getServer('REQUEST_METHOD', '')) {
- case self::METHOD_GET:
- return $this->getQuery($key, $default);
- break;
- case self::METHOD_POST:
- case self::METHOD_PUT:
- case self::METHOD_PATCH:
- case self::METHOD_DELETE:
- return $this->getPayload($key, $default);
- break;
- default:
- return $this->getQuery($key, $default);
- }
- }
+ abstract public function getParam(string $key, mixed $default = null): mixed;
/**
* Get Params
@@ -74,22 +59,7 @@ public function getParam(string $key, mixed $default = null)
*
* @return array
*/
- public function getParams(): array
- {
- switch ($this->getServer('REQUEST_METHOD', '')) {
- case self::METHOD_GET:
- return $_GET;
- break;
- case self::METHOD_POST:
- case self::METHOD_PUT:
- case self::METHOD_PATCH:
- case self::METHOD_DELETE:
- return $this->generateInput();
- break;
- default:
- return $_GET;
- }
- }
+ abstract public function getParams(): array;
/**
* Get Query
@@ -100,10 +70,7 @@ public function getParams(): array
* @param mixed $default
* @return mixed
*/
- public function getQuery(string $key, mixed $default = null): mixed
- {
- return (isset($_GET[$key])) ? $_GET[$key] : $default;
- }
+ abstract public function getQuery(string $key, mixed $default = null): mixed;
/**
* Get payload
@@ -114,12 +81,7 @@ public function getQuery(string $key, mixed $default = null): mixed
* @param mixed $default
* @return mixed
*/
- public function getPayload(string $key, mixed $default = null): mixed
- {
- $payload = $this->generateInput();
-
- return (isset($payload[$key])) ? $payload[$key] : $default;
- }
+ abstract public function getPayload(string $key, mixed $default = null): mixed;
/**
* Get server
@@ -130,10 +92,7 @@ public function getPayload(string $key, mixed $default = null): mixed
* @param mixed $default
* @return mixed
*/
- public function getServer(string $key, mixed $default = null): mixed
- {
- return (isset($_SERVER[$key])) ? $_SERVER[$key] : $default;
- }
+ abstract public function getServer(string $key, mixed $default = null): mixed;
/**
* Get IP
@@ -144,11 +103,7 @@ public function getServer(string $key, mixed $default = null): mixed
*
* @return string
*/
- public function getIP(): string
- {
- $ips = explode(',',$this->getHeader('HTTP_X_FORWARDED_FOR', $this->getServer('REMOTE_ADDR', '0.0.0.0')));
- return trim($ips[0] ?? '');
- }
+ abstract public function getIP(): string;
/**
* Get Protocol
@@ -159,10 +114,7 @@ public function getIP(): string
*
* @return string
*/
- public function getProtocol(): string
- {
- return $this->getServer('HTTP_X_FORWARDED_PROTO', $this->getServer('REQUEST_SCHEME', 'https'));
- }
+ abstract public function getProtocol(): string;
/**
* Get Port
@@ -171,10 +123,7 @@ public function getProtocol(): string
*
* @return string
*/
- public function getPort(): string
- {
- return (string) \parse_url($this->getProtocol().'://'.$this->getServer('HTTP_HOST', ''), PHP_URL_PORT);
- }
+ abstract public function getPort(): string;
/**
* Get Hostname
@@ -183,10 +132,7 @@ public function getPort(): string
*
* @return string
*/
- public function getHostname(): string
- {
- return (string) \parse_url($this->getProtocol().'://'.$this->getServer('HTTP_HOST', ''), PHP_URL_HOST);
- }
+ abstract public function getHostname(): string;
/**
* Get Method
@@ -195,10 +141,7 @@ public function getHostname(): string
*
* @return string
*/
- public function getMethod(): string
- {
- return $this->getServer('REQUEST_METHOD', 'UNKNOWN');
- }
+ abstract public function getMethod(): string;
/**
* Get URI
@@ -207,10 +150,7 @@ public function getMethod(): string
*
* @return string
*/
- public function getURI(): string
- {
- return $this->getServer('REQUEST_URI', '');
- }
+ abstract public function getURI(): string;
/**
* Get files
@@ -220,10 +160,7 @@ public function getURI(): string
* @param string $key
* @return array
*/
- public function getFiles(string $key): array
- {
- return (isset($_FILES[$key])) ? $_FILES[$key] : [];
- }
+ abstract public function getFiles(string $key): array;
/**
* Get Referer
@@ -234,10 +171,7 @@ public function getFiles(string $key): array
*
* @return string
*/
- public function getReferer(string $default = ''): string
- {
- return (string) $this->getServer('HTTP_REFERER', $default);
- }
+ abstract public function getReferer(string $default = ''): string;
/**
* Get Origin
@@ -248,10 +182,7 @@ public function getReferer(string $default = ''): string
*
* @return string
*/
- public function getOrigin(string $default = ''): string
- {
- return (string) $this->getServer('HTTP_ORIGIN', $default);
- }
+ abstract public function getOrigin(string $default = ''): string;
/**
* Get User Agent
@@ -262,10 +193,7 @@ public function getOrigin(string $default = ''): string
*
* @return string
*/
- public function getUserAgent(string $default = ''): string
- {
- return (string) $this->getServer('HTTP_USER_AGENT', $default);
- }
+ abstract public function getUserAgent(string $default = ''): string;
/**
* Get Accept
@@ -276,10 +204,7 @@ public function getUserAgent(string $default = ''): string
*
* @return string
*/
- public function getAccept(string $default = ''): string
- {
- return (string) $this->getServer('HTTP_ACCEPT', $default);
- }
+ abstract public function getAccept(string $default = ''): string;
/**
* Get cookie
@@ -290,10 +215,7 @@ public function getAccept(string $default = ''): string
* @param string $default
* @return string
*/
- public function getCookie(string $key, string $default = ''): string
- {
- return (isset($_COOKIE[$key])) ? $_COOKIE[$key] : $default;
- }
+ abstract public function getCookie(string $key, string $default = ''): string;
/**
* Get header
@@ -304,12 +226,7 @@ public function getCookie(string $key, string $default = ''): string
* @param string $default
* @return string
*/
- public function getHeader(string $key, string $default = ''): string
- {
- $headers = $this->generateHeaders();
-
- return (isset($headers[$key])) ? $headers[$key] : $default;
- }
+ abstract public function getHeader(string $key, string $default = ''): string;
/**
* Get Request Size
@@ -318,10 +235,16 @@ public function getHeader(string $key, string $default = ''): string
*
* @return int
*/
- public function getSize(): int
- {
- return \mb_strlen(\implode("\n", $this->generateHeaders()), '8bit') + \mb_strlen(\file_get_contents('php://input'), '8bit');
- }
+ abstract public function getSize(): int;
+
+ /**
+ * Generate headers
+ *
+ * Parse request headers as an array for easy querying using the getHeader method
+ *
+ * @return array
+ */
+ abstract protected function generateHeaders(): array;
/**
* Get Content Range Start
@@ -438,75 +361,6 @@ public function getRangeUnit(): ?string
return null;
}
- /**
- * Generate input
- *
- * Generate PHP input stream and parse it as an array in order to handle different content type of requests
- *
- * @return array
- */
- protected function generateInput(): array
- {
- if (null === $this->payload) {
- $contentType = $this->getHeader('content-type');
-
- // Get content-type without the charset
- $length = \strpos($contentType, ';');
- $length = (empty($length)) ? \strlen($contentType) : $length;
- $contentType = \substr($contentType, 0, $length);
-
- switch ($contentType) {
- case 'application/json':
- $this->payload = \json_decode(\file_get_contents('php://input'), true);
- break;
-
- default:
- $this->payload = $_POST;
- break;
- }
-
- if (empty($this->payload)) { // Make sure we return same data type even if json payload is empty or failed
- $this->payload = [];
- }
- }
-
- return $this->payload;
- }
-
- /**
- * Generate headers
- *
- * Parse request headers as an array for easy querying using the getHeader method
- *
- * @return array
- */
- protected function generateHeaders(): array
- {
- if (null === $this->headers) {
- /**
- * Fallback for older PHP versions
- * that do not support generateHeaders
- */
- if (!\function_exists('getallheaders')) {
- $headers = [];
-
- foreach ($_SERVER as $name => $value) {
- if (\substr($name, 0, 5) == 'HTTP_') {
- $headers[\str_replace(' ', '-', \strtolower(\str_replace('_', ' ', \substr($name, 5))))] = $value;
- }
- }
-
- $this->headers = $headers;
-
- return $this->headers;
- }
-
- $this->headers = array_change_key_case(getallheaders());
- }
-
- return $this->headers;
- }
-
/**
* Content Range Parser
*
@@ -556,6 +410,7 @@ protected function parseContentRange(): ?array
}
return $data;
}
+
return null;
}
diff --git a/src/Response.php b/src/Response.php
index b863c2c5..7150cc58 100755
--- a/src/Response.php
+++ b/src/Response.php
@@ -1,18 +1,18 @@
* @license The MIT License (MIT)
*/
-namespace Utopia;
+namespace Utopia\HTTP;
-class Response
+abstract class Response
{
/**
* HTTP content types
@@ -396,6 +396,7 @@ public function getCookies(): array
* Generate HTTP response output including the response header (+cookies) and body and prints them.
*
* @param string $body
+ * @param int $exit exit code or don't exit if code is null
*
* @return void
*/
@@ -437,74 +438,6 @@ public function send(string $body = ''): void
}
}
- /**
- * Write
- *
- * Send output
- *
- * @param string $content
- *
- * @return void
- */
- protected function write(string $content): void
- {
- echo $content;
- }
-
- /**
- * End
- *
- * Send optional content and end
- *
- * @param string $content
- *
- * @return void
- */
- protected function end(string $content = null): void
- {
- if(!is_null($content)) {
- echo $content;
- }
- }
-
- /**
- * Output response
- *
- * Generate HTTP response output including the response header (+cookies) and body and prints them.
- *
- * @param string $body
- * @param bool $last
- *
- * @return void
- */
- public function chunk(string $body = '', bool $end = false): void
- {
- if ($this->sent) {
- return;
- }
-
- if ($end) {
- $this->sent = true;
- }
-
- $this->addHeader('X-Debug-Speed', (string) (microtime(true) - $this->startTime));
-
- $this
- ->appendCookies()
- ->appendHeaders()
- ;
-
- if (!$this->disablePayload) {
- $this->write($body);
- if ($end) {
- $this->disablePayload();
- $this->end();
- }
- } else {
- $this->end();
- }
- }
-
/**
* Append headers
*
@@ -532,69 +465,114 @@ protected function appendHeaders(): self
}
/**
- * Send Status Code
+ * Append cookies
*
- * @param int $statusCode
+ * Iterating over response cookies to generate them using native PHP cookie function.
*
- * @return void
+ * @return self
*/
- protected function sendStatus(int $statusCode): void
+ protected function appendCookies(): self
{
- http_response_code($statusCode);
+ foreach ($this->cookies as $cookie) {
+ $this->sendCookie($cookie['name'], $cookie['value'], [
+ 'expires' => $cookie['expire'],
+ 'path' => $cookie['path'],
+ 'domain' => $cookie['domain'],
+ 'secure' => $cookie['secure'],
+ 'httponly' => $cookie['httponly'],
+ 'samesite' => $cookie['samesite'],
+ ]);
+ }
+
+ return $this;
}
+ /**
+ * Write
+ *
+ * @param string $content
+ *
+ * @return void
+ */
+ abstract protected function write(string $content): void;
+
+ /**
+ * End
+ *
+ * @param string $content
+ *
+ * @return void
+ */
+ abstract protected function end(string $content=null): void;
+
+ /**
+ * Send Status Code
+ *
+ * @param int $statusCode
+ *
+ * @return void
+ */
+ abstract protected function sendStatus(int $statusCode): void;
+
/**
* Send Header
- *
- * Output Header
- *
+ *
* @param string $key
* @param string $value
- *
+ *
* @return void
*/
- protected function sendHeader(string $key, string $value): void
- {
- \header($key . ': ' . $value);
- }
+ abstract protected function sendHeader(string $key, string $value): void;
/**
* Send Cookie
*
- * Output Cookie
- *
+ * Send a cookie
+ *
* @param string $name
* @param string $value
* @param array $options
*
* @return void
*/
- protected function sendCookie(string $name, string $value, array $options): void
- {
- \setcookie($name, $value, $options);
- }
+ abstract protected function sendCookie(string $name, string $value, array $options): void;
/**
- * Append cookies
+ * Output response
*
- * Iterating over response cookies to generate them using native PHP cookie function.
+ * Generate HTTP response output including the response header (+cookies) and body and prints them.
*
- * @return self
+ * @param string $body
+ * @param bool $last
+ *
+ * @return void
*/
- protected function appendCookies(): self
+ public function chunk(string $body = '', bool $end = false): void
{
- foreach ($this->cookies as $cookie) {
- $this->sendCookie($cookie['name'], $cookie['value'], [
- 'expires' => $cookie['expire'],
- 'path' => $cookie['path'],
- 'domain' => $cookie['domain'],
- 'secure' => $cookie['secure'],
- 'httponly' => $cookie['httponly'],
- 'samesite' => $cookie['samesite'],
- ]);
+ if ($this->sent) {
+ return;
}
- return $this;
+ if ($end) {
+ $this->sent = true;
+ }
+
+ $this->addHeader('X-Debug-Speed', (string) (microtime(true) - $this->startTime));
+
+ $this
+ ->appendCookies()
+ ->appendHeaders()
+ ;
+
+ if (!$this->disablePayload) {
+ $this->write($body);
+ if ($end) {
+ $this->disablePayload();
+ $this->end();
+ }
+ } else {
+ $this->end();
+ }
}
/**
diff --git a/src/Route.php b/src/Route.php
index 7e4a0f21..febf35e6 100755
--- a/src/Route.php
+++ b/src/Route.php
@@ -1,16 +1,16 @@
* @license The MIT License (MIT)
*/
-namespace Utopia;
+namespace Utopia\HTTP;
use Exception;
diff --git a/src/Server.php b/src/Server.php
new file mode 100644
index 00000000..ef73c27e
--- /dev/null
+++ b/src/Server.php
@@ -0,0 +1,46 @@
+
+ */
+class Server
+{
+ protected Adapter $adapter;
+
+ /**
+ * Creates an instance of a HTTP server.
+ * @param Adapter $adapter
+ */
+ public function __construct(Adapter $adapter)
+ {
+ $this->adapter = $adapter;
+ }
+
+ /**
+ * Start the HTTP server
+ *
+ * @return void
+ */
+ public function start(): void
+ {
+ }
+
+ /**
+ * Shuts down the WebSocket server.
+ * @return void
+ */
+ public function end(): void
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/src/Validator.php b/src/Validator.php
index 29cdd541..47408879 100755
--- a/src/Validator.php
+++ b/src/Validator.php
@@ -1,16 +1,16 @@
* @license The MIT License (MIT)
*/
-namespace Utopia;
+namespace Utopia\HTTP;
abstract class Validator
{
diff --git a/src/Validator/ArrayList.php b/src/Validator/ArrayList.php
index a7af583b..7a1ac795 100644
--- a/src/Validator/ArrayList.php
+++ b/src/Validator/ArrayList.php
@@ -1,25 +1,25 @@
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
-use Utopia\Validator;
+use Utopia\HTTP\Validator;
/**
* ArrayList
*
* Validate that an variable is a valid array value and each element passes given validation
*
- * @package Utopia\Validator
+ * @package Utopia\HTTP\Validator
*/
class ArrayList extends Validator
{
diff --git a/src/Validator/Assoc.php b/src/Validator/Assoc.php
index a69b7d70..a2b814cb 100644
--- a/src/Validator/Assoc.php
+++ b/src/Validator/Assoc.php
@@ -1,25 +1,25 @@
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
-use Utopia\Validator;
+use Utopia\HTTP\Validator;
/**
* ArrayList
*
* Validate that an variable is a valid array value and each element passes given validation
*
- * @package Utopia\Validator
+ * @package Utopia\HTTP\Validator
*/
class Assoc extends Validator
{
diff --git a/src/Validator/Boolean.php b/src/Validator/Boolean.php
index c2df6cf9..97d0a68c 100644
--- a/src/Validator/Boolean.php
+++ b/src/Validator/Boolean.php
@@ -1,25 +1,25 @@
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
-use Utopia\Validator;
+use Utopia\HTTP\Validator;
/**
* Bool
*
* Validate that an variable is a boolean value
*
- * @package Utopia\Validator
+ * @package Utopia\HTTP\Validator
*/
class Boolean extends Validator
{
diff --git a/src/Validator/FloatValidator.php b/src/Validator/FloatValidator.php
index e2307897..ba64207b 100755
--- a/src/Validator/FloatValidator.php
+++ b/src/Validator/FloatValidator.php
@@ -1,25 +1,25 @@
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
-use Utopia\Validator;
+use Utopia\HTTP\Validator;
/**
* Float
*
* Validate that an variable is a float
*
- * @package Utopia\Validator
+ * @package Utopia\HTTP\Validator
*/
class FloatValidator extends Validator
{
diff --git a/src/Validator/HexColor.php b/src/Validator/HexColor.php
index 85da3cd1..5ad4d1fb 100644
--- a/src/Validator/HexColor.php
+++ b/src/Validator/HexColor.php
@@ -1,18 +1,18 @@
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
-use Utopia\Validator;
+use Utopia\HTTP\Validator;
class HexColor extends Validator
{
diff --git a/src/Validator/Integer.php b/src/Validator/Integer.php
index 8fd15275..f727dedb 100755
--- a/src/Validator/Integer.php
+++ b/src/Validator/Integer.php
@@ -1,24 +1,24 @@
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
-use Utopia\Validator;
+use Utopia\HTTP\Validator;
/**
* Integer
*
* Validate that an variable is an integer
*
- * @package Utopia\Validator
+ * @package Utopia\HTTP\Validator
*/
class Integer extends Validator
{
diff --git a/src/Validator/JSON.php b/src/Validator/JSON.php
index b70c0588..eef7385d 100644
--- a/src/Validator/JSON.php
+++ b/src/Validator/JSON.php
@@ -1,18 +1,18 @@
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
-use Utopia\Validator;
+use Utopia\HTTP\Validator;
class JSON extends Validator
{
diff --git a/src/Validator/Numeric.php b/src/Validator/Numeric.php
index 99dd7cda..9e6efe4c 100755
--- a/src/Validator/Numeric.php
+++ b/src/Validator/Numeric.php
@@ -1,25 +1,25 @@
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
-use Utopia\Validator;
+use Utopia\HTTP\Validator;
/**
* Numeric
*
* Validate that an variable is numeric
*
- * @package Utopia\Validator
+ * @package Utopia\HTTP\Validator
*/
class Numeric extends Validator
{
diff --git a/src/Validator/Range.php b/src/Validator/Range.php
index 80148e12..11c34baa 100755
--- a/src/Validator/Range.php
+++ b/src/Validator/Range.php
@@ -1,23 +1,23 @@
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
/**
* Range
*
* Validates that an number is in range.
*
- * @package Utopia\Validator
+ * @package Utopia\HTTP\Validator
*/
class Range extends Numeric
{
diff --git a/src/Validator/Text.php b/src/Validator/Text.php
index b27c79d5..dc0d763a 100644
--- a/src/Validator/Text.php
+++ b/src/Validator/Text.php
@@ -1,25 +1,25 @@
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
-use Utopia\Validator;
+use Utopia\HTTP\Validator;
/**
* Text
*
* Validate that an variable is a valid text value
*
- * @package Utopia\Validator
+ * @package Utopia\HTTP\Validator
*/
class Text extends Validator
{
diff --git a/src/Validator/WhiteList.php b/src/Validator/WhiteList.php
index 1e918c84..328d6598 100755
--- a/src/Validator/WhiteList.php
+++ b/src/Validator/WhiteList.php
@@ -1,25 +1,25 @@
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
-use Utopia\Validator;
+use Utopia\HTTP\Validator;
/**
* WhiteList
*
* Checks if a variable is inside predefined white list.
*
- * @package Utopia\Validator
+ * @package Utopia\HTTP\Validator
*/
class WhiteList extends Validator
{
diff --git a/src/Validator/Wildcard.php b/src/Validator/Wildcard.php
index c00102ff..34608ceb 100644
--- a/src/Validator/Wildcard.php
+++ b/src/Validator/Wildcard.php
@@ -1,25 +1,25 @@
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
-use Utopia\Validator;
+use Utopia\HTTP\Validator;
/**
* Wildcard
*
* Does not perform any validation. Always returns valid
*
- * @package Utopia\Validator
+ * @package Utopia\HTTP\Validator
*/
class Wildcard extends Validator
{
diff --git a/src/View.php b/src/View.php
index bfcae05f..abdda585 100755
--- a/src/View.php
+++ b/src/View.php
@@ -1,16 +1,16 @@
* @license The MIT License (MIT)
*/
-namespace Utopia;
+namespace Utopia\HTTP;
use Exception;
diff --git a/tests/AppTest.php b/tests/AppTest.php
index 1eb2cab4..af51f5f2 100755
--- a/tests/AppTest.php
+++ b/tests/AppTest.php
@@ -1,21 +1,23 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia;
+namespace Utopia\HTTP;
use PHPUnit\Framework\TestCase;
+use Utopia\HTTP\Adapter\FPM\Request;
+use Utopia\HTTP\Adapter\FPM\Response;
+use Utopia\HTTP\Validator\Text;
use Utopia\Tests\UtopiaRequestTest;
-use Utopia\Validator\Text;
App::setResource('rand', function () {return rand();});
App::setResource('first', function ($second) {return 'first-'.$second;}, ['second']);
diff --git a/tests/RequestTest.php b/tests/RequestTest.php
index a467cab6..45d75d9a 100755
--- a/tests/RequestTest.php
+++ b/tests/RequestTest.php
@@ -1,20 +1,20 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Tests;
+namespace Utopia\HTTP\Tests;
use PHPUnit\Framework\TestCase;
-use Utopia\Request;
+use Utopia\HTTP\Adapter\FPM\Request;
class RequestTest extends TestCase
{
diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php
index d77a2649..b38bec69 100755
--- a/tests/ResponseTest.php
+++ b/tests/ResponseTest.php
@@ -1,19 +1,20 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia;
+namespace Utopia\HTTP;
use PHPUnit\Framework\TestCase;
+use Utopia\HTTP\Adapter\FPM\Response;
class ResponseTest extends TestCase
{
@@ -37,7 +38,7 @@ public function testSetContentType()
$contentType = $this->response->setContentType(Response::CONTENT_TYPE_HTML, Response::CHARSET_UTF8);
// Assertions
- $this->assertInstanceOf('Utopia\Response', $contentType);
+ $this->assertInstanceOf('Utopia\HTTP\Response', $contentType);
}
public function testSetStatus()
@@ -45,7 +46,7 @@ public function testSetStatus()
$status = $this->response->setStatusCode(Response::STATUS_CODE_OK);
// Assertions
- $this->assertInstanceOf('Utopia\Response', $status);
+ $this->assertInstanceOf('Utopia\HTTP\Response', $status);
try{
$this->response->setStatusCode(0); // Unknown status code
diff --git a/tests/RouteTest.php b/tests/RouteTest.php
index 32c3e483..3851196a 100755
--- a/tests/RouteTest.php
+++ b/tests/RouteTest.php
@@ -1,20 +1,20 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia;
+namespace Utopia\HTTP;
use PHPUnit\Framework\TestCase;
-use Utopia\Validator\Text;
+use Utopia\HTTP\Validator\Text;
class RouteTest extends TestCase
{
diff --git a/tests/UtopiaRequestTest.php b/tests/UtopiaRequestTest.php
index 33363ede..4611aa5f 100644
--- a/tests/UtopiaRequestTest.php
+++ b/tests/UtopiaRequestTest.php
@@ -2,9 +2,9 @@
namespace Utopia\Tests;
-use Utopia\Request as UtopiaRequest;
+use Utopia\HTTP\Adapter\FPM\Request;
-class UtopiaRequestTest extends UtopiaRequest
+class UtopiaRequestTest extends Request
{
/**
* @var array
diff --git a/tests/Validator/ArrayListTest.php b/tests/Validator/ArrayListTest.php
index 08971818..87f258c4 100755
--- a/tests/Validator/ArrayListTest.php
+++ b/tests/Validator/ArrayListTest.php
@@ -1,17 +1,17 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
use PHPUnit\Framework\TestCase;
@@ -57,8 +57,8 @@ public function testIsValid()
$this->assertEquals(false, $this->arrayList2->isValid('string'));
$this->assertEquals(true, $this->arrayList2->isValid([1, 2, 3]));
$this->assertEquals(false, $this->arrayList2->isValid(1, '2', 3));
- $this->assertEquals($this->arrayList1->getType(), \Utopia\Validator::TYPE_STRING);
- $this->assertEquals($this->arrayList2->getType(), \Utopia\Validator::TYPE_MIXED);
+ $this->assertEquals($this->arrayList1->getType(), \Utopia\HTTP\Validator::TYPE_STRING);
+ $this->assertEquals($this->arrayList2->getType(), \Utopia\HTTP\Validator::TYPE_MIXED);
$this->assertEquals($this->arrayList1->isArray(), true);
$this->assertEquals(true, $this->arrayList3->isValid([1]));
diff --git a/tests/Validator/AssocTest.php b/tests/Validator/AssocTest.php
index 65787145..0330ce11 100755
--- a/tests/Validator/AssocTest.php
+++ b/tests/Validator/AssocTest.php
@@ -1,17 +1,17 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
use PHPUnit\Framework\TestCase;
@@ -44,7 +44,7 @@ public function testIsValid()
$this->assertEquals(true, $this->assoc->isValid([]));
$this->assertEquals(true, $this->assoc->isValid(['value' => str_repeat("-", 62000)]));
$this->assertEquals(false, $this->assoc->isValid(['value' => str_repeat("-", 66000)]));
- $this->assertEquals($this->assoc->getType(), \Utopia\Validator::TYPE_ARRAY);
+ $this->assertEquals($this->assoc->getType(), \Utopia\HTTP\Validator::TYPE_ARRAY);
$this->assertEquals($this->assoc->isArray(), true);
}
}
diff --git a/tests/Validator/BooleanTest.php b/tests/Validator/BooleanTest.php
index ed2a1027..47850ebc 100755
--- a/tests/Validator/BooleanTest.php
+++ b/tests/Validator/BooleanTest.php
@@ -1,17 +1,17 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
use PHPUnit\Framework\TestCase;
@@ -60,7 +60,7 @@ public function testIsValid()
$this->assertEquals(false, $this->boolean->isValid(['string', 'string']));
$this->assertEquals(false, $this->boolean->isValid('string'));
$this->assertEquals(false, $this->boolean->isValid(1.2));
- $this->assertEquals($this->boolean->getType(), \Utopia\Validator::TYPE_BOOLEAN);
+ $this->assertEquals($this->boolean->getType(), \Utopia\HTTP\Validator::TYPE_BOOLEAN);
$this->assertEquals($this->boolean->isArray(), false);
}
}
diff --git a/tests/Validator/FloatValidatorTest.php b/tests/Validator/FloatValidatorTest.php
index 4a209586..7f4ae0dd 100755
--- a/tests/Validator/FloatValidatorTest.php
+++ b/tests/Validator/FloatValidatorTest.php
@@ -1,17 +1,17 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
use PHPUnit\Framework\TestCase;
@@ -50,7 +50,7 @@ public function testIsValid()
$this->assertEquals($this->validator->isValid(true), false);
$this->assertEquals($this->validator->isValid('23.5'), false);
$this->assertEquals($this->validator->isValid('23'), false);
- $this->assertEquals($this->validator->getType(), \Utopia\Validator::TYPE_FLOAT);
+ $this->assertEquals($this->validator->getType(), \Utopia\HTTP\Validator::TYPE_FLOAT);
$this->assertEquals($this->validator->isArray(), false);
// Assertions Loose
@@ -62,7 +62,7 @@ public function testIsValid()
$this->assertEquals($this->looseValidator->isValid(true), false);
$this->assertEquals($this->looseValidator->isValid('23.5'), true);
$this->assertEquals($this->looseValidator->isValid('23'), true);
- $this->assertEquals($this->looseValidator->getType(), \Utopia\Validator::TYPE_FLOAT);
+ $this->assertEquals($this->looseValidator->getType(), \Utopia\HTTP\Validator::TYPE_FLOAT);
$this->assertEquals($this->looseValidator->isArray(), false);
}
}
diff --git a/tests/Validator/HexColorTest.php b/tests/Validator/HexColorTest.php
index 3a65e59a..310bbbdd 100755
--- a/tests/Validator/HexColorTest.php
+++ b/tests/Validator/HexColorTest.php
@@ -1,17 +1,17 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
use PHPUnit\Framework\TestCase;
@@ -44,7 +44,7 @@ public function testIsValid()
$this->assertEquals($this->hexColor->isValid('ffffff'), true);
$this->assertEquals($this->hexColor->isValid('fff'), true);
$this->assertEquals($this->hexColor->isValid('000000'), true);
- $this->assertEquals($this->hexColor->getType(), \Utopia\Validator::TYPE_STRING);
+ $this->assertEquals($this->hexColor->getType(), \Utopia\HTTP\Validator::TYPE_STRING);
$this->assertEquals($this->hexColor->isArray(), false);
}
}
diff --git a/tests/Validator/IntegerTest.php b/tests/Validator/IntegerTest.php
index 01e1f32e..9ebbb8eb 100755
--- a/tests/Validator/IntegerTest.php
+++ b/tests/Validator/IntegerTest.php
@@ -1,29 +1,29 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
use PHPUnit\Framework\TestCase;
class IntegerTest extends TestCase
{
/**
- * @var \Utopia\Validator\Integer
+ * @var \Utopia\HTTP\Validator\Integer
*/
protected $validator = null;
/**
- * @var \Utopia\Validator\Integer
+ * @var \Utopia\HTTP\Validator\Integer
*/
protected $looseValidator = null;
@@ -49,7 +49,7 @@ public function testIsValid()
$this->assertEquals($this->validator->isValid(null), false);
$this->assertEquals($this->validator->isValid(true), false);
$this->assertEquals($this->validator->isValid(false), false);
- $this->assertEquals($this->validator->getType(), \Utopia\Validator::TYPE_INTEGER);
+ $this->assertEquals($this->validator->getType(), \Utopia\HTTP\Validator::TYPE_INTEGER);
$this->assertEquals($this->validator->isArray(), false);
// Assertions loose
@@ -60,7 +60,7 @@ public function testIsValid()
$this->assertEquals($this->looseValidator->isValid(null), false);
$this->assertEquals($this->looseValidator->isValid(true), false);
$this->assertEquals($this->looseValidator->isValid(false), false);
- $this->assertEquals($this->looseValidator->getType(), \Utopia\Validator::TYPE_INTEGER);
+ $this->assertEquals($this->looseValidator->getType(), \Utopia\HTTP\Validator::TYPE_INTEGER);
$this->assertEquals($this->looseValidator->isArray(), false);
}
}
diff --git a/tests/Validator/JSONTest.php b/tests/Validator/JSONTest.php
index 695bdf79..a97fe9e9 100755
--- a/tests/Validator/JSONTest.php
+++ b/tests/Validator/JSONTest.php
@@ -1,17 +1,17 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
use PHPUnit\Framework\TestCase;
@@ -47,7 +47,7 @@ public function testIsValid()
$this->assertEquals(true, $this->json->isValid(['test']));
$this->assertEquals(true, $this->json->isValid(['test' => 'demo']));
$this->assertEquals(true, $this->json->isValid('{"test": "demo"}'));
- $this->assertEquals($this->json->getType(), \Utopia\Validator::TYPE_OBJECT);
+ $this->assertEquals($this->json->getType(), \Utopia\HTTP\Validator::TYPE_OBJECT);
$this->assertEquals($this->json->isArray(), false);
}
}
diff --git a/tests/Validator/NumericTest.php b/tests/Validator/NumericTest.php
index 948b0aff..eea8738c 100755
--- a/tests/Validator/NumericTest.php
+++ b/tests/Validator/NumericTest.php
@@ -1,17 +1,17 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
use PHPUnit\Framework\TestCase;
@@ -43,7 +43,7 @@ public function testIsValid()
$this->assertEquals($this->numeric->isValid(9.1), true);
$this->assertEquals($this->numeric->isValid('not numeric'), false);
$this->assertEquals($this->numeric->isValid([]), false);
- $this->assertEquals($this->numeric->getType(), \Utopia\Validator::TYPE_MIXED);
+ $this->assertEquals($this->numeric->getType(), \Utopia\HTTP\Validator::TYPE_MIXED);
$this->assertEquals($this->numeric->isArray(), false);
}
}
diff --git a/tests/Validator/RangeTest.php b/tests/Validator/RangeTest.php
index efa4abec..cfad1f4b 100755
--- a/tests/Validator/RangeTest.php
+++ b/tests/Validator/RangeTest.php
@@ -1,17 +1,17 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
use PHPUnit\Framework\TestCase;
@@ -25,8 +25,8 @@ class RangeTest extends TestCase
public function setUp():void
{
- $this->rangeFloat = new Range(0, 1, \Utopia\Validator::TYPE_FLOAT);
- $this->rangeInt = new Range(0, 5, \Utopia\Validator::TYPE_INTEGER);
+ $this->rangeFloat = new Range(0, 1, \Utopia\HTTP\Validator::TYPE_FLOAT);
+ $this->rangeInt = new Range(0, 5, \Utopia\HTTP\Validator::TYPE_INTEGER);
}
public function tearDown():void
@@ -47,9 +47,9 @@ public function testIsValid()
$this->assertEquals($this->rangeInt->isValid(-1), false);
$this->assertEquals($this->rangeInt->getMin(), 0);
$this->assertEquals($this->rangeInt->getMax(), 5);
- $this->assertEquals($this->rangeInt->getFormat(), \Utopia\Validator::TYPE_INTEGER);
+ $this->assertEquals($this->rangeInt->getFormat(), \Utopia\HTTP\Validator::TYPE_INTEGER);
$this->assertEquals($this->rangeInt->isArray(), false);
- $this->assertEquals($this->rangeInt->getType(), \Utopia\Validator::TYPE_INTEGER);
+ $this->assertEquals($this->rangeInt->getType(), \Utopia\HTTP\Validator::TYPE_INTEGER);
// Assertions for float
$this->assertEquals($this->rangeFloat->isValid(0.0), true);
@@ -62,15 +62,15 @@ public function testIsValid()
$this->assertEquals($this->rangeFloat->isValid(-1), false);
$this->assertEquals($this->rangeFloat->getMin(), 0);
$this->assertEquals($this->rangeFloat->getMax(), 1);
- $this->assertEquals($this->rangeFloat->getFormat(), \Utopia\Validator::TYPE_FLOAT);
+ $this->assertEquals($this->rangeFloat->getFormat(), \Utopia\HTTP\Validator::TYPE_FLOAT);
$this->assertEquals($this->rangeFloat->isArray(), false);
- $this->assertEquals($this->rangeFloat->getType(), \Utopia\Validator::TYPE_FLOAT);
+ $this->assertEquals($this->rangeFloat->getType(), \Utopia\HTTP\Validator::TYPE_FLOAT);
}
public function testInfinity()
{
- $integer = new Range(5, INF, \Utopia\Validator::TYPE_INTEGER);
- $float = new Range(-INF, 45.6, \Utopia\Validator::TYPE_FLOAT);
+ $integer = new Range(5, INF, \Utopia\HTTP\Validator::TYPE_INTEGER);
+ $float = new Range(-INF, 45.6, \Utopia\HTTP\Validator::TYPE_FLOAT);
$this->assertEquals(true, $integer->isValid(25));
$this->assertEquals(false, $integer->isValid(3));
diff --git a/tests/Validator/TextTest.php b/tests/Validator/TextTest.php
index f99dbaa8..fbef1acf 100755
--- a/tests/Validator/TextTest.php
+++ b/tests/Validator/TextTest.php
@@ -1,17 +1,17 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
use PHPUnit\Framework\TestCase;
@@ -43,6 +43,6 @@ public function testIsValid()
$this->assertEquals(false, $this->text->isValid(["seven", 8, 9.0]));
$this->assertEquals(false, $this->text->isValid(false));
$this->assertEquals(false, $this->text->isArray());
- $this->assertEquals(\Utopia\Validator::TYPE_STRING, $this->text->getType());
+ $this->assertEquals(\Utopia\HTTP\Validator::TYPE_STRING, $this->text->getType());
}
}
diff --git a/tests/Validator/WhiteListTest.php b/tests/Validator/WhiteListTest.php
index dc9424f2..dd3a48ef 100755
--- a/tests/Validator/WhiteListTest.php
+++ b/tests/Validator/WhiteListTest.php
@@ -1,17 +1,17 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
use PHPUnit\Framework\TestCase;
@@ -29,7 +29,7 @@ public function testIsValid()
$this->assertEquals($whiteList->isValid(3), true);
$this->assertEquals($whiteList->isValid(5), false);
$this->assertEquals($whiteList->getList(), ['string1', 'string2', 3, 4]);
- $this->assertEquals($whiteList->getType(), \Utopia\Validator::TYPE_STRING); //string by default
+ $this->assertEquals($whiteList->getType(), \Utopia\HTTP\Validator::TYPE_STRING); //string by default
$this->assertEquals($whiteList->isArray(), false);
$whiteList = new WhiteList(['string1', 'string2', 3, 4], false);
diff --git a/tests/Validator/WildcardTest.php b/tests/Validator/WildcardTest.php
index fb6c66f1..804a0f02 100644
--- a/tests/Validator/WildcardTest.php
+++ b/tests/Validator/WildcardTest.php
@@ -1,17 +1,17 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia\Validator;
+namespace Utopia\HTTP\Validator;
use PHPUnit\Framework\TestCase;
@@ -39,7 +39,7 @@ public function testIsValid()
$this->assertEquals(true, $this->wildcard->isValid(1));
$this->assertEquals(true, $this->wildcard->isValid(true));
$this->assertEquals(true, $this->wildcard->isValid(false));
- $this->assertEquals($this->wildcard->getType(), \Utopia\Validator::TYPE_STRING);
+ $this->assertEquals($this->wildcard->getType(), \Utopia\HTTP\Validator::TYPE_STRING);
$this->assertEquals($this->wildcard->isArray(), false);
}
}
diff --git a/tests/ViewTest.php b/tests/ViewTest.php
index 15203889..c9b66aad 100755
--- a/tests/ViewTest.php
+++ b/tests/ViewTest.php
@@ -1,17 +1,17 @@
* @version 1.0 RC4
* @license The MIT License (MIT)
*/
-namespace Utopia;
+namespace Utopia\HTTP;
use PHPUnit\Framework\TestCase;
@@ -37,7 +37,7 @@ public function testSetParam()
$value = $this->view->setParam('key', 'value');
// Assertions
- $this->assertInstanceOf('Utopia\View', $value);
+ $this->assertInstanceOf('Utopia\HTTP\View', $value);
}
public function testGetParam()
@@ -54,7 +54,7 @@ public function testSetPath()
$value = $this->view->setPath('mocks/View/fake.phtml');
// Assertions
- $this->assertInstanceOf('Utopia\View', $value);
+ $this->assertInstanceOf('Utopia\HTTP\View', $value);
}
public function testSetRendered()
diff --git a/tests/e2e/server.php b/tests/e2e/server.php
index e9d900b8..e591f501 100644
--- a/tests/e2e/server.php
+++ b/tests/e2e/server.php
@@ -2,9 +2,9 @@
require_once __DIR__ . '/../../vendor/autoload.php';
-use Utopia\App;
-use Utopia\Request;
-use Utopia\Response;
+use Utopia\HTTP\Adapter\FPM\Request;
+use Utopia\HTTP\Adapter\FPM\Response;
+use Utopia\HTTP\App;
ini_set('memory_limit', '512M');
ini_set('display_errors', 1);