You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* develop:
specify next release
mention the async server is not meant to be used in production
highlight notes
add shortcut to reference a service to handle a route
add short syntax to declare routes
Copy file name to clipboardExpand all lines: README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ Take a look at the [documentation](docs/) for a more in-depth understanding of t
24
24
25
25
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.
26
26
27
-
**Note**: if you don't configure any route it will respond with `404 Not Found` with an empty body.
27
+
> **Note** if you don't configure any route it will respond with `404 Not Found` with an empty body.
28
28
29
29
```php
30
30
<?php
@@ -80,7 +80,7 @@ You can run this script via `cd public && php -S localhost:8080`. If you open yo
80
80
81
81
The entrypoint of your cli tools will look something like this.
82
82
83
-
**Note**: by default if you don't configure any command it will always display `Hello world`.
83
+
> **Note** by default if you don't configure any command it will always display `Hello world`.
Copy file name to clipboardExpand all lines: docs/experimental/async-server.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
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.
4
4
5
-
**Note**: This feature is optional, to use it you must before run `composer require innmind/async-http-server`.
5
+
> **Note** This feature is optional, to use it you must before run `composer require innmind/async-http-server`.
6
6
7
7
To use it is similar to the standard [http](../http.md) handler, the first difference is the namespace of the main entrypoint:
8
8
@@ -29,4 +29,6 @@ Note the namespace is `Main\Async\Http` instead of `Main\Http`. The other differ
29
29
30
30
All the configuration of the `Application` object is identical to the other contexts.
31
31
32
-
**Note**: The server currently does have limitations, streamed requests (via `Transfer-Encoding`) are not supported and multipart requests are not parsed.
32
+
> **Note** The server currently does have limitations, streamed requests (via `Transfer-Encoding`) are not supported and multipart requests are not parsed.
33
+
34
+
> **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.
Copy file name to clipboardExpand all lines: docs/http.md
+43-5Lines changed: 43 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,6 +94,43 @@ new class extends Http {
94
94
95
95
For simple apps having the whole behaviour next to the route can be ok. But like in this case it can be repetitive, for such case we can specify our behaviours elsewhere: [services](#Services).
96
96
97
+
## Short syntax
98
+
99
+
The previous shows the default way to declare routes, but for very simple apps it can be a bit verbose. The framework provides a shorter syntax to handle routes:
100
+
101
+
```php
102
+
use Innmind\Framework\{
103
+
Main\Http,
104
+
Application,
105
+
};
106
+
use Innmind\Router\Route\Variables;
107
+
use Innmind\Http\Message\{
108
+
ServerRequest,
109
+
Response\Response,
110
+
StatusCode,
111
+
};
112
+
use Innmind\Filesystem\File\Content;
113
+
114
+
new class extends Http {
115
+
protected function configure(Application $app): Application
116
+
{
117
+
return $app
118
+
->route('GET /', static fn(ServerRequest $request) => new Response(
119
+
StatusCode::ok,
120
+
$request->protocolVersion(),
121
+
null,
122
+
Content\Lines::ofContent('Hello world!'),
123
+
))
124
+
->route('GET /{name}', static fn(ServerRequest $request, Variables $variables) => new Response(
Services are any object that are referenced by a string in a [`Container`](https://github.com/Innmind/DI). For example let's take the route handler from the previous section and move them inside services.
Here the services are invokable anonymous classes to conform to the callable expected for a `Route` but you can create dedicated classes for each one.
162
200
163
-
**Note**: Head to the [services topic](services.md) for a more in-depth look of what's possible.
201
+
> **Note** Head to the [services topic](services.md) for a more in-depth look of what's possible.
164
202
165
203
## Executing code on any route
166
204
@@ -216,7 +254,7 @@ This example will refuse any request that doesn't have an `Authorization` header
216
254
217
255
You can have multiple calls to `mapRequestHandler` to compose behaviours like an onion.
218
256
219
-
**Note**: the default request handler is the inner router of the framework, this means that you can completely change the default behaviour of the framework by returning a new request handler that never uses the default one.
257
+
> **Note** the default request handler is the inner router of the framework, this means that you can completely change the default behaviour of the framework by returning a new request handler that never uses the default one.
Copy file name to clipboardExpand all lines: docs/middlewares.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Middlewares are a way to regroup all the configuration you've seen in other topics under a name. This means that you can either group part of your own application undeer a middleware or expose a package for other to use via Packagist.
4
4
5
-
**Note**: you can search for [`innmind/framework-middlewares` on Packagist](https://packagist.org/providers/innmind/framework-middlewares) for middlewares published by others.
5
+
> **Note** you can search for [`innmind/framework-middlewares` on Packagist](https://packagist.org/providers/innmind/framework-middlewares) for middlewares published by others.
6
6
7
7
Let's say you have an application that sends emails you could have a middleware that looks like this:
0 commit comments