Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  mention the async server is optional
  add async server to changelog
  fix link
  add documentation
  ifx blackbox set size
  enable functional test in the CI
  splits tests from coverage
  force the use of async-http-server 1
  use innmind/async-http-server 1
  Revert "fix minimum version of the os"
  disable functional test in the CI
  fix minimum version of the os
  ignore async http from code coverage
  add functional test to make sure the async http server works
  use psalm 5
  add async http server
  • Loading branch information
Baptouuuu committed Feb 26, 2023
2 parents fe40a96 + 74dfc85 commit 7d784de
Show file tree
Hide file tree
Showing 12 changed files with 503 additions and 9 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@ jobs:
php-version: ['8.1', '8.2']
dependencies: ['lowest', 'highest']
name: 'PHPUnit'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: none
- name: Composer
uses: "ramsey/composer-install@v2"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: PHPUnit
run: vendor/bin/phpunit
coverage:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['8.1', '8.2']
dependencies: ['lowest', 'highest']
name: 'Coverage'
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -26,6 +49,8 @@ jobs:
dependency-versions: ${{ matrix.dependencies }}
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover
env:
BLACKBOX_SET_SIZE: 1
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.1.0 - 2023-02-26

### Added

- `Innmind\Framework\Main\Async\Http` as an (optional) experimental feature

## 1.0.0 - 2023-01-01

### Added
Expand Down
4 changes: 4 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ignore:
- src/Application/Async/Http.php
- src/Main/Async/Http.php
- .php-cs-fixer.dist.php
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@
},
"require-dev": {
"phpunit/phpunit": "~9.0",
"vimeo/psalm": "~4.30",
"vimeo/psalm": "~5.6",
"innmind/black-box": "^4.17",
"innmind/coding-standard": "~2.0"
"innmind/coding-standard": "~2.0",
"innmind/async-http-server": "~1.0"
},
"conflict": {
"innmind/black-box": "<4.7|~5.0"
"innmind/black-box": "<4.7|~5.0",
"innmind/async-http-server": "<1.0|~2.0"
},
"suggest": {
"innmind/black-box": "For property based testing"
"innmind/black-box": "For property based testing",
"innmind/async-http-server": "To run a local asynchronous http server"
},
"provide": {
"innmind/framework-middlewares": "1.0"
Expand Down
3 changes: 3 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ These topics will guide you through the simplest cases to more complex ones:
- [Testing](testing.md)
- [Add variables to the environment](environment.md)
- [Decorate the operating system](operating-system.md)

Experimental features:
- [Using an async http server](experimental/async-server.md)
32 changes: 32 additions & 0 deletions docs/experimental/async-server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Async HTTP Server

The framework comes with an HTTP server entirely built in PHP allowing you to serve your app without extra dependencies in ther earlist stages of your project.

**Note**: This feature is optional, to use it you must before run `composer require innmind/async-http-server`.

To use it is similar to the standard [http](../http.md) handler, the first difference is the namespace of the main entrypoint:

```php
<?php
declare(strict_types = 1);

require 'path/to/composer/autoload.php';

use Innmind\Framework\{
Main\Async\Http,
Application,
};

new class extends Http {
protected function configure(Application $app): Application
{
return $app;
}
};
```

Note the namespace is `Main\Async\Http` instead of `Main\Http`. The other difference is instead of pointing your HTTP Server to the folder containing the php file you run the server via `php index.php`.

All the configuration of the `Application` object is identical to the other contexts.

**Note**: The server currently does have limitations, streamed requests (via `Transfer-Encoding`) are not supported and multipart requests are not parsed.
21 changes: 21 additions & 0 deletions fixtures/server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
declare(strict_types = 1);

require __DIR__.'/../vendor/autoload.php';

use Innmind\Framework\{
Application,
Main\Async\Http,
Http\Routes,
};
use Innmind\Router\Route;

new class extends Http
{
protected function configure(Application $app): Application
{
return $app->appendRoutes(static fn($routes) => $routes->add(
Route::literal('GET /hello'),
));
}
};
5 changes: 5 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedCode="false"
findUnusedBaselineEntry="true"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand All @@ -12,4 +14,7 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<disableExtensions>
<extension name="random" />
</disableExtensions>
</psalm>
28 changes: 23 additions & 5 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

final class Application
{
private Application\Cli|Application\Http $app;
private Application\Cli|Application\Http|Application\Async\Http $app;

/**
* @psalm-mutation-free
*/
private function __construct(Application\Cli|Application\Http $app)
private function __construct(Application\Cli|Application\Http|Application\Async\Http $app)
{
$this->app = $app;
}
Expand All @@ -46,6 +46,15 @@ public static function cli(OperatingSystem $os, Environment $env): self
return new self(Application\Cli::of($os, $env));
}

/**
* @psalm-pure
* @experimental
*/
public static function asyncHttp(OperatingSystem $os): self
{
return new self(Application\Async\Http::of($os));
}

/**
* @psalm-mutation-free
*
Expand Down Expand Up @@ -121,7 +130,10 @@ public function mapCommand(callable $map): self
*/
public function appendRoutes(callable $append): self
{
if ($this->app instanceof Application\Http) {
if (
$this->app instanceof Application\Http ||
$this->app instanceof Application\Async\Http
) {
return new self($this->app->appendRoutes($append));
}

Expand All @@ -135,7 +147,10 @@ public function appendRoutes(callable $append): self
*/
public function mapRequestHandler(callable $map): self
{
if ($this->app instanceof Application\Http) {
if (
$this->app instanceof Application\Http ||
$this->app instanceof Application\Async\Http
) {
return new self($this->app->mapRequestHandler($map));
}

Expand All @@ -149,7 +164,10 @@ public function mapRequestHandler(callable $map): self
*/
public function notFoundRequestHandler(callable $handle): self
{
if ($this->app instanceof Application\Http) {
if (
$this->app instanceof Application\Http ||
$this->app instanceof Application\Async\Http
) {
return new self($this->app->notFoundRequestHandler($handle));
}

Expand Down
Loading

0 comments on commit 7d784de

Please sign in to comment.