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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'

- name: Validate composer.json and composer.lock
run: composer validate --strict
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile.fpm
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ RUN composer install --ignore-platform-reqs --optimize-autoloader \
--no-plugins --no-scripts --prefer-dist \
`if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi`

FROM php:8.0-cli-alpine as final
FROM php:8.2-fpm-alpine as final
LABEL maintainer="team@appwrite.io"

ENV DEBIAN_FRONTEND=noninteractive \
PHP_VERSION=8
PHP_FPM_POOL_CONF=/usr/local/etc/php-fpm.d/www.conf

RUN \
apk add --no-cache --virtual .deps \
supervisor php$PHP_VERSION php$PHP_VERSION-fpm php$PHP_VERSION-mbstring nginx bash
supervisor nginx bash


# Nginx Configuration (with self-signed ssl certificates)
COPY ./tests/docker/nginx.conf /etc/nginx/nginx.conf

# PHP Configuration
RUN mkdir -p /var/run/php
COPY ./tests/docker/www.conf /etc/php/$PHP_VERSION/fpm/pool.d/www.conf
COPY ./tests/docker/www.conf /usr/local/etc/php-fpm.d/www.conf

# Script
COPY ./tests/docker/start /usr/local/bin/start
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.swoole
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN composer install --ignore-platform-reqs --optimize-autoloader \
--no-plugins --no-scripts --prefer-dist \
`if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi`

FROM appwrite/base:0.4.3 as final
FROM appwrite/base:0.5.0 as final
LABEL maintainer="team@appwrite.io"

WORKDIR /usr/src/code
Expand Down
43 changes: 27 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Utopia HTTP 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).

Utopia HTTP is dependency-free. Any extra features, such as authentication or caching are available as standalone models in order to keep the framework core clean, light, and easy to learn.
Utopia HTTP keeps routing and request lifecycle concerns separate from resource wiring by relying on the standalone Utopia DI package for dependency injection.

## Getting Started

Expand All @@ -23,11 +23,14 @@ Init your first application in `src/server.php`:
```php
require_once __DIR__.'/../vendor/autoload.php';

use Utopia\DI\Container;
use Utopia\Http\Http;
use Utopia\Http\Request;
use Utopia\Http\Response;
use Utopia\Http\Adapter\FPM\Server;

$container = new Container();

Http::get('/hello-world') // Define Route
->inject('request')
->inject('response')
Expand All @@ -43,7 +46,7 @@ Http::get('/hello-world') // Define Route

Http::setMode(Http::MODE_TYPE_PRODUCTION);

$http = new Http(new Server(), 'America/New_York');
$http = new Http(new Server(), 'America/New_York', $container);
$http->start();
```

Expand All @@ -66,10 +69,13 @@ The library supports server adapters to be able to run on any PHP setup. You cou
#### Use PHP FPM server

```php
use Utopia\DI\Container;
use Utopia\Http\Http;
use Utopia\Http\Response;
use Utopia\Http\Adapter\FPM\Server;

$container = new Container();

Http::get('/')
->inject('response')
->action(
Expand All @@ -78,7 +84,7 @@ Http::get('/')
}
);

$http = new Http(new Server(), 'America/New_York');
$http = new Http(new Server(), 'America/New_York', $container);
$http->start();
```

Expand All @@ -87,11 +93,14 @@ $http->start();
#### Using Swoole server

```php
use Utopia\DI\Container;
use Utopia\Http\Http;
use Utopia\Http\Request;
use Utopia\Http\Response;
use Utopia\Http\Adapter\Swoole\Server;

$container = new Container();

Http::get('/')
->inject('request')
->inject('response')
Expand All @@ -101,7 +110,7 @@ Http::get('/')
}
);

$http = new Http(new Server('0.0.0.0', '80'), 'America/New_York');
$http = new Http(new Server('0.0.0.0', '80'), 'America/New_York', $container);
$http->start();
```

Expand Down Expand Up @@ -208,35 +217,37 @@ Groups are designed to be actions that run during the lifecycle of requests to e

### Resources

Resources allow you to prepare dependencies for requests such as database connection or the user who sent the request. A new instance of a resource is created for every request.
Resources allow you to prepare dependencies for requests such as database connections or shared services. Register application dependencies on the DI container with `set()`. Runtime values such as `request`, `response`, `route`, `error`, and `context` are scoped by `Http` for each request.

Define a resource:
Define a dependency on the DI container:

```php
Http::setResource('timing', function() {
$container->set('bootTime', function () {
return \microtime(true);
});
}, []);
```

Inject resource into endpoint action:

```php
$http = new Http(new Server(), 'America/New_York', $container);

Http::get('/')
->inject('timing')
->inject('bootTime')
->inject('response')
->action(function(float $timing, Response $response) {
$response->send('Request Unix timestamp: ' . \strval($timing));
->action(function(float $bootTime, Response $response) {
$response->send('Process started at: ' . \strval($bootTime));
});
```

Inject resource into a hook:

```php
Http::shutdown()
->inject('timing')
->action(function(float $timing) {
$difference = \microtime(true) - $timing;
\var_dump("Request took: " . $difference . " seconds");
->inject('bootTime')
->action(function(float $bootTime) {
$uptime = \microtime(true) - $bootTime;
\var_dump("Process uptime: " . $uptime . " seconds");
});
```

Expand All @@ -248,7 +259,7 @@ To learn more about architecture and features for this library, check out more i

## System Requirements

Utopia HTTP requires PHP 8.1 or later. We recommend using the latest PHP version whenever possible.
Utopia HTTP requires PHP 8.2 or later. We recommend using the latest PHP version whenever possible.

## More from Utopia

Expand Down
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@
"bench": "vendor/bin/phpbench run --report=benchmark"
},
"require": {
"php": ">=8.0",
"ext-swoole": "*",
"utopia-php/validators": "0.2.*"
"php": ">=8.2",
"utopia-php/di": "0.3.*",
"utopia-php/validators": "0.2.*",
"ext-swoole": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.5.25",
"doctrine/instantiator": "^1.5",
"laravel/pint": "1.*",
"swoole/ide-helper": "4.8.3",
"phpbench/phpbench": "^1.2",
"phpstan/phpstan": "1.*",
"phpbench/phpbench": "^1.2"
"phpunit/phpunit": "^9.5.25",
"swoole/ide-helper": "4.8.3"
}
}
Loading
Loading