From 89d474640cfeb9e1d019da5a66bbaf9a837164cd Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sat, 21 Mar 2026 16:54:35 +0100 Subject: [PATCH] fix documentation --- README.md | 8 ++++--- docs/in-app.md | 5 ++-- docs/record.md | 65 +++++++++++++++++++++++++++----------------------- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 642821f..422d103 100644 --- a/README.md +++ b/README.md @@ -21,15 +21,17 @@ The profiler contains 2 types of entities: a profile and sections. A profile contains a name (usually the http path called or the cli), the point in time the profile started, the status (succeeded, failed or pending) and an exit message. A section is a part of a profile. By default there are 9 sections: + - Http: the request and response (if the app didn't crash) the app received - Exception: the stack trace represented as graph (see [`innmind/stack-trace`](https://packagist.org/packages/innmind/stack-trace)) - App graph: the object graph representing the application (see [`innmind/object-graph`](https://packagist.org/packages/innmind/object-graph)) - Call graph: a flamechart - Environment: the list of environment variables - Processes: the list of commands run on the machine -- Remote / Http: all the http requests issued by the application -- Remote / Processes: all the commands run on a distant machine -- Remote / Sql: all the SQL queries issued to a database +- Remote + - Http: all the http requests issued by the application + - Processes: all the commands run on a distant machine + - Sql: all the SQL queries issued to a database ![](overview/index.png) ![](overview/http.png) diff --git a/docs/in-app.md b/docs/in-app.md index 8067745..2fde5e8 100644 --- a/docs/in-app.md +++ b/docs/in-app.md @@ -1,6 +1,6 @@ # Add the profiler to an existing app -For this use cas you must [`innmind/framework`](https://packagist.org/packages/innmind/framework). +For this use case you must use [`innmind/framework`](https://packagist.org/packages/innmind/framework). ```php use Innmind\Framework\{ @@ -20,4 +20,5 @@ new class extends Http { This example will expose the profiler under the `/_profiler/` route and the profiles will be stored in the `/tmp/` folder. Using the tmp folder means the profiles will be lost when rebooting your machine, you can use a local folder if you want to keep them. -> **Note** this example add the middleware in the entrypoint of your app but you can add it in your own middleware. +> [!NOTE] +> This example add the middleware in the entrypoint of your app but you can add it in your own middleware. diff --git a/docs/record.md b/docs/record.md index 61dc729..532f75e 100644 --- a/docs/record.md +++ b/docs/record.md @@ -8,13 +8,17 @@ The examples show how to record data when the profiler is [in the current app](i use Innmind\Framework\{ Application, Middleware, - Http\RequestHandler, }; use Innmind\Profiler\{ Web\Kernel, + Web\Services, Profiler, + Profiler\Mutation, + Profile\Id, }; -use Innmind\Http\Message\{ +use Innmind\DI\Container; +use Innmind\Route\Component; +use Innmind\Http\{ ServerRequest, Response, }; @@ -26,36 +30,37 @@ final class YourApp implements Middleware { return $app ->map(Kernel::inApp(Path::of('/tmp/'))) - ->mapRequestHandler( - static fn($handler, $get) => new class($handler, $get('innmind/profiler')) implements RequestHandler { - public function __construct( - private RequestHandler $inner, - private Profiler $profiler, - ) { - } + ->mapRoute( + static fn( + Component $route, + Container $get, + ) => Component::of(static function(ServerRequest $request, mixed $input) use ($route, $get) { + $profiler = $get(Services::profiler()); - public function __invoke(ServerRequest $request): Response - { - $profile = $this->profiler->start($request->url()->path()->toString()); - $this->profiler->mutate( - $profile, - static function($mutation) { - $mutation->sections(); // call any method here to record sections data - }, + return $profiler + ->start($request->url()->path()->toString()) + ->flatMap( + static fn(Id $profile) => $profiler + ->mutate( + $profile, + static fn(Mutation $mutation) => $mutation + ->http() + ->received($request->body()), + ) + ->flatMap(static fn() => $route($request, $input)) + ->flatMap( + static fn(Response $response) => $profiler + ->mutate( + $profile, + static fn(Mutation $mutation) => match ($response->statusCode()->successful()) { + true => $mutation->succeed($response->statusCode()->toString()), + false => $mutation->fail($response->statusCode()->toString()), + }, + ) + ->map(static fn() => $response), + ), ); - - $response = ($this->inner)($request); - $this->profiler->mutate( - $profile, - static fn($mutation) => match ($response->statusCode()->successful()) { - true => $mutation->succeed($response->statusCode()->toString()), - false => $mutation->fail($response->statusCode()->toString()), - }, - ); - - return $response; - } - }, + }), ); } }