From 74dcc40b7ef6995411721bc91495f8a01a171528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 13 Jun 2021 17:29:07 +0200 Subject: [PATCH] Simplify documentation by omitting optional `LoopInterface` argument --- README.md | 4 +--- docs/api/app.md | 25 +------------------------ docs/api/middleware.md | 4 +--- docs/best-practices/controllers.md | 8 ++------ docs/getting-started/quickstart.md | 4 +--- 5 files changed, 6 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index f84ec5e..7e73347 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,7 @@ empty project directory: require __DIR__ . '/../vendor/autoload.php'; -$loop = React\EventLoop\Factory::create(); -$app = new FrameworkX\App($loop); +$app = new FrameworkX\App(); $app->get('/', function () { return new React\Http\Message\Response( @@ -41,7 +40,6 @@ $app->get('/users/{name}', function (Psr\Http\Message\ServerRequestInterface $re }); $app->run(); -$loop->run(); ``` Next, we need to install X and its dependencies to actually run this project. diff --git a/docs/api/app.md b/docs/api/app.md index 81be014..f881269 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -3,42 +3,19 @@ The `App` class is your main entrypoint to any application that builds on top of X. It provides a simple API for routing HTTP requests as commonly used in RESTful applications. -Internally, the `App` object builds on top of [ReactPHP](https://reactphp.org/) -to do its magic, hence you have to create it like this: - ```php # app.php run(); -$loop->run(); ``` -> ℹ️ **Heads up!** -> -> Major improvements upcoming! We're actively contributing to our underlying -> libraries to make sure this can look like this in the near future: -> -> ```php -> # app.php -> -> require __DIR__ . '/vendor/autoload.php'; -> -> $app = new FrameworkX\App(); -> -> // Register routes here, see routing… -> -> $app->run(); -> ``` - ## Routing The `App` class offers a number of API methods that allow you to route incoming diff --git a/docs/api/middleware.md b/docs/api/middleware.md index bebad5c..fc44b58 100644 --- a/docs/api/middleware.md +++ b/docs/api/middleware.md @@ -257,13 +257,11 @@ a global middleware handler for all registered routes: use Acme\Todo\AdminMiddleware; use Acme\Todo\UserController; -$loop = React\EventLoop\Factory::create(); -$app = new FrameworkX\App($loop, new AdminMiddleware()); +$app = new FrameworkX\App(new AdminMiddleware()); $app->get('/user', new UserController()); $app->run(); -$loop->run(); ``` You can also combine global middleware handlers (think logging) with additional diff --git a/docs/best-practices/controllers.md b/docs/best-practices/controllers.md index c0bf2ae..a55ac63 100644 --- a/docs/best-practices/controllers.md +++ b/docs/best-practices/controllers.md @@ -13,8 +13,7 @@ To get started, let's take a look at the following simple closure definitions: require __DIR__ . '/vendor/autoload.php'; -$loop = React\EventLoop\Factory::create(); -$app = new FrameworkX\App($loop); +$app = new FrameworkX\App(); $app->get('/', function () { return new React\Http\Message\Response( @@ -33,7 +32,6 @@ $app->get('/users/{name}', function (Psr\Http\Message\ServerRequestInterface $re }); $app->run(); -$loop->run(); ``` While easy to get started, it's also easy to see how this will get out of hand for more complex @@ -49,14 +47,12 @@ definition into three even simpler files: require __DIR__ . '/vendor/autoload.php'; -$loop = React\EventLoop\Factory::create(); -$app = new FrameworkX\App($loop); +$app = new FrameworkX\App(); $app->get('/', new Acme\Todo\HelloController()); $app->get('/users/{name}', new Acme\Todo\UserController()); $app->run(); -$loop->run(); ``` ```php diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index 53faa1c..0039003 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -22,8 +22,7 @@ You can use this example to get started by creating a new `app.php` file in your require __DIR__ . '/vendor/autoload.php'; -$loop = React\EventLoop\Factory::create(); -$app = new FrameworkX\App($loop); +$app = new FrameworkX\App(); $app->get('/', function () { return new React\Http\Message\Response( @@ -42,7 +41,6 @@ $app->get('/users/{name}', function (Psr\Http\Message\ServerRequestInterface $re }); $app->run(); -$loop->run(); ``` On a code level, this is everything you need to get started.