From 0dd6b5d536114758a45f9d44fc27120bb34c5f2b Mon Sep 17 00:00:00 2001 From: Koldo Picaza Date: Sat, 16 Jan 2021 13:02:16 +0100 Subject: [PATCH] add readme --- README.md | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++ composer.json | 2 +- 2 files changed, 149 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e3d5cf..b1ced13 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,151 @@ # Antidot React Framework +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/antidot-framework/react-framework/badges/quality-score.png?b=0.0.x)](https://scrutinizer-ci.com/g/antidot-framework/react-framework/?branch=0.0.x) +[![type-coverage](https://shepherd.dev/github/antidot-framework/react-framework/coverage.svg)](https://shepherd.dev/github/antidot-framework/react-framework) +[![Code Coverage](https://scrutinizer-ci.com/g/antidot-framework/react-framework/badges/coverage.png?b=0.0.x)](https://scrutinizer-ci.com/g/antidot-framework/react-framework/?branch=0.0.x) +[![Build Status](https://scrutinizer-ci.com/g/antidot-framework/react-framework/badges/build.png?b=0.0.x)](https://scrutinizer-ci.com/g/antidot-framework/react-framework/build-status/0.0.x) + +## Requirements: + +* PHP ^7.4|^8.0 +* Antidot Framework +* React Http +* Ramsey Uuid + +## Description + +This package allows running both common synchronous and modern asynchronous PHP following PSR-15 middleware standard approach. + +## Install + +The preferred way to install this library is using the `reactive-antidot-starter` project. + +```bash +composer create-project antidot-fw/reactive-antidot-starter +``` + +> [Reactive Antidot Framework](https://github.com/antidot-framework/reactive-antidot-starter) + +To install it on a existing Antidot Framework Project installation we need to tweak some configurations and replace or create new `index.php` file. + +```bash +composer require antidot-fw/react-framework +``` + +### Config + +* Disable LaminasRequest Handler Runner +* Load Antidot React Config Provider after Antidot Framework provider + +Example config from starter project +```php + 'var/cache/config-cache.php', +]; + +$aggregator = new ConfigAggregator([ + \WShafer\PSR11MonoLog\ConfigProvider::class, + \Antidot\Event\Container\Config\ConfigProvider::class, + \Antidot\Logger\Container\Config\ConfigProvider::class, + \Antidot\Cli\Container\Config\ConfigProvider::class, + \Antidot\Fast\Router\Container\Config\ConfigProvider::class, + \Antidot\Container\Config\ConfigProvider::class, + \Antidot\React\Container\Config\ConfigProvider::class, + class_exists(DevToolsConfigProvider::class) ? DevToolsConfigProvider::class : fn() => [], + new PhpFileProvider(realpath(__DIR__).'/services/{{,*.}prod,{,*.}local,{,*.}dev}.php'), + new YamlConfigProvider(realpath(__DIR__).'/services/{{,*.}prod,{,*.}local,{,*.}dev}.yaml'), + new ArrayProvider($cacheConfig), +], $cacheConfig['config_cache_path']); + +return $aggregator->getMergedConfig(); +``` + +The create your React Http server + +```php +#!/usr/bin/env php +get(Application::class); + (require 'router/middleware.php')($application, $container); + (require 'router/routes.php')($application, $container); + + $server = new Server( + $loop, + new StreamingRequestMiddleware(), + new LimitConcurrentRequestsMiddleware(100), // 100 concurrent buffering handlers + new RequestBodyBufferMiddleware(4 * 1024 * 1024), // 4 MiB + new RequestBodyParserMiddleware(), + static function (ServerRequestInterface $request) use ($application) { + try { + $response = new PromiseResponse( + resolve($request) + ->then(static fn ($request) => $request->withAttribute('request_id', Uuid::uuid4()->toString())) + ->then(static fn ($request) => $application->handle($request)) + ); + } catch (Throwable $exception) { + if (!empty($e = $exception->getPrevious())) { + $exception = $e; + } + + $response = new HtmlResponse( + sprintf( + '%s in file %s in line %s.', + $exception->getMessage(), + $exception->getFile(), + $exception->getLine() + ) + ); + } + + return resolve($response); + } + ); + + $server->on('error', function ($err) { + dump($err); + }); + + $socket = new Socket('0.0.0.0:8080', $loop); + $server->listen($socket); + + $loop->run(); +}); + +``` diff --git a/composer.json b/composer.json index d7d5066..482d3fc 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": "^7.4.3", + "php": "^7.4|^8.0", "antidot-fw/framework": "^0.1.3", "psr/container": "^1.0.0", "ramsey/uuid": "^4.1",