Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  specify next release
  update notes style
  update notes style
  add documentation for grouped routes
  update changelog
  add Routes::append()
  add support for grouped routes
  update actions
  run tests via blackbox
  fix keeping all routes in memory
  use an Implementation interface to better track the expected types
  simplify readme example
  fix documentation
  update dependencies
  • Loading branch information
Baptouuuu committed Nov 26, 2023
2 parents ebbf053 + 18c09b8 commit 7405a65
Show file tree
Hide file tree
Showing 31 changed files with 610 additions and 319 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ name: CI
on: [push]

jobs:
phpunit:
blackbox:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['8.2', '8.3']
dependencies: ['lowest', 'highest']
name: 'PHPUnit'
name: 'BlackBox'
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -24,8 +24,8 @@ jobs:
uses: "ramsey/composer-install@v2"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: PHPUnit
run: vendor/bin/phpunit
- name: BlackBox
run: php blackbox.php
coverage:
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -36,7 +36,7 @@ jobs:
name: 'Coverage'
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -47,11 +47,11 @@ jobs:
uses: "ramsey/composer-install@v2"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover
- name: BlackBox
run: php blackbox.php
env:
BLACKBOX_SET_SIZE: 1
- uses: codecov/codecov-action@v1
ENABLE_COVERAGE: 'true'
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
psalm:
Expand All @@ -63,7 +63,7 @@ jobs:
name: 'Psalm'
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -83,7 +83,7 @@ jobs:
name: 'CS'
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
composer.lock
vendor
.phpunit.result.cache
.phpunit.cache
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## 2.0.0 - 2023-10-26

### Added

- `Innmind\Framework\Http\Routes::append()`
- `Innmind\Framework\Http\Routes::add()` now also accepts `Innmind\Router\Under`

### Changed

- Requires `innmind/operating-system:~4.1`
- Requires `innmind/immutable:~5.2`
- Requires `innmind/filesystem:~7.0`
- Requires `innmind/http-server:~4.0`
- Requires `innmind/router:~4.1`
- Requires `innmind/innmind/async-http-server:~2.0`

### Fixed

- All routes are no longer kept in memory when no longer used

## 1.4.0 - 2023-09-24

### Added
Expand Down
50 changes: 21 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Take a look at the [documentation](docs/) for a more in-depth understanding of t

The first step is to create the index file that will be exposed via a webserver (for example `public/index.php`). Then you need to specify the routes you want to handle.

> **Note** if you don't configure any route it will respond with `404 Not Found` with an empty body.
> [!NOTE]
> if you don't configure any route it will respond with `404 Not Found` with an empty body.
```php
<?php
Expand All @@ -35,41 +36,31 @@ require 'path/to/composer/autoload.php';
use Innmind\Framework\{
Main\Http,
Application,
Http\Routes,
};
use Innmind\Router\{
Route,
Route\Variables,
};
use Innmind\Http\Message\{
use Innmind\Router\Route\Variables;
use Innmind\Http\{
ServerRequest,
Response\Response,
StatusCode,
Response,
Response\StatusCode,
};
use Innmind\Filesystem\File\Content;

new class extends Http {
protected function configure(Application $app): Application
{
return $app->appendRoutes(
static fn(Routes $routes) => $routes
->add(Route::literal('GET /')->handle(
static fn(ServerRequest $request) => new Response(
StatusCode::ok,
$request->protocolVersion(),
null,
Content\Lines::ofContent('Hello world!'),
),
))
->add(Route::literal('GET /{name}')->handle(
static fn(ServerRequest $request, Variables $variables) => new Response(
StatusCode::ok,
$request->protocolVersion(),
null,
Content\Lines::ofContent("Hello {$variables->get('name')}!"),
),
)),
);
return $app
->route('GET /', static fn(ServerRequest $request) => Response::of(
StatusCode::ok,
$request->protocolVersion(),
null,
Content::ofString('Hello world!'),
))
->route('GET /{name}', static fn(ServerRequest $request, Variables $variables) => Response::of(
StatusCode::ok,
$request->protocolVersion(),
null,
Content::ofString("Hello {$variables->get('name')}!"),
));
}
};
```
Expand All @@ -80,7 +71,8 @@ You can run this script via `cd public && php -S localhost:8080`. If you open yo

The entrypoint of your cli tools will look something like this.

> **Note** by default if you don't configure any command it will always display `Hello world`.
> [!NOTE]
> by default if you don't configure any command it will always display `Hello world`.
```php
<?php
Expand Down
27 changes: 27 additions & 0 deletions blackbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types = 1);

require 'vendor/autoload.php';

use Innmind\BlackBox\{
Application,
PHPUnit\Load,
Runner\CodeCoverage,
};

Application::new($argv)
->when(
\getenv('ENABLE_COVERAGE') !== false,
static fn(Application $app) => $app
->codeCoverage(
CodeCoverage::of(
__DIR__.'/src/',
__DIR__.'/tests/',
)
->dumpTo('coverage.clover')
->enableWhen(true),
)
->scenariiPerProof(1),
)
->tryToProve(Load::directory(__DIR__.'/tests/'))
->exit();
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
},
"require": {
"php": "~8.2",
"innmind/operating-system": "^3.2",
"innmind/operating-system": "~4.1",
"innmind/cli": "^3.1",
"innmind/immutable": "^4.9|~5.0",
"innmind/immutable": "~5.2",
"innmind/di": "^2.0",
"ramsey/uuid": "^4.7",
"innmind/url": "^4.1",
"innmind/filesystem": "^6.0",
"innmind/http-server": "^3.0",
"innmind/router": "^3.0"
"innmind/filesystem": "~7.0",
"innmind/http-server": "~4.0",
"innmind/router": "~4.1"
},
"autoload": {
"psr-4": {
Expand All @@ -37,15 +37,14 @@
}
},
"require-dev": {
"phpunit/phpunit": "~10.2",
"vimeo/psalm": "~5.6",
"innmind/black-box": "~5.5",
"innmind/coding-standard": "~2.0",
"innmind/async-http-server": "~1.0"
"innmind/async-http-server": "~2.0"
},
"conflict": {
"innmind/black-box": "<5.0|~6.0",
"innmind/async-http-server": "<1.0|~2.0"
"innmind/async-http-server": "<2.0|~3.0"
},
"suggest": {
"innmind/black-box": "For property based testing",
Expand Down
9 changes: 6 additions & 3 deletions docs/experimental/async-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

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`.
> [!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:

Expand All @@ -29,6 +30,8 @@ Note the namespace is `Main\Async\Http` instead of `Main\Http`. The other differ

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.
> [!NOTE]
>The server currently does have limitations, streamed requests (via `Transfer-Encoding`) are not supported and multipart requests are not parsed.
> **Warning** This server was built to showcase in a conference talk the ability to switch between synchronous code and asynchronous code without changing the app code. Do **NOT** use this server in production.
> [!WARNING]
> This server was built to showcase in a conference talk the ability to switch between synchronous code and asynchronous code without changing the app code. Do **NOT** use this server in production.
Loading

0 comments on commit 7405a65

Please sign in to comment.