Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ The preferred way to install this library is using the `reactive-antidot-starter
composer create-project antidot-fw/reactive-antidot-starter
```

> [Reactive Antidot Framework](https://github.com/antidot-framework/reactive-antidot-starter)
> [Antidot Framework Reactive Starter](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
## Config

* Disable LaminasRequest Handler Runner
* Load Antidot React Config Provider after Antidot Framework provider
Expand Down Expand Up @@ -94,7 +94,63 @@ $config = [

```

### Usage
## Usage

It allows executing promises inside PSR-15 and PSR-7 Middlewares and request handlers

### PSR-15 Middleware

```php
<?php
declare(strict_types = 1);

namespace App;

use Antidot\React\PromiseResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class SomeMiddleware implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
return new PromiseResponse(
resolve($request)
->then(static fn(ServerrequestInsterface $request) => $handler->handle($request))
);
}
}
```

### PSR-7 Request Handler

```php
<?php
declare(strict_types = 1);

namespace App;

use Antidot\React\PromiseResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class SomeMiddleware implements RequestHandlerInterface
{
public function process(ServerRequestInterface $request): ResponseInterface
{
return resolve($request)->then(
function(ServerrequestInterface $request): ResponseInterface {
return new Response('Hello World!!!');
}
);;
}
}
```

## Server

Two new commands will be added to the Antidot Framework CLI tool, to allow running the application on top of [Drift server](https://driftphp.io/#/?id=the-server)

Expand Down
Empty file added docs/.nojekyll
Empty file.
221 changes: 221 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
# Antidot React Framework

[![link-packagist](https://img.shields.io/packagist/v/antidot-fw/react-framework.svg?style=flat-square)](https://packagist.org/packages/antidot-fw/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
* DriftPHP Server
* React Http
* React Promises
* 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
```

> [Antidot Framework Reactive Starter](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
<?php
// config/config.php

declare(strict_types=1);

use Antidot\DevTools\Container\Config\ConfigProvider as DevToolsConfigProvider;
use Antidot\SymfonyConfigTranslator\Container\Config\ConfigAggregator;
use Antidot\Yaml\YamlConfigProvider;
use Laminas\ConfigAggregator\ArrayProvider;
use Laminas\ConfigAggregator\PhpFileProvider;

// To enable or disable caching, set the `ConfigAggregator::ENABLE_CACHE` boolean in
// `config/autoload/local.php`.
$cacheConfig = [
'config_cache_path' => '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();
```

Default Config:

```php
<?php

$config = [
'server' => [
'host' => '0.0.0.0',
'port' => 5555,
'buffer_size' => 4096,
'max_concurrency' => 100,
'workers' => 1,
'static_folder' => 'public'
]
]

```

## Usage

It allows executing promises inside PSR-15 and PSR-7 Middlewares and request handlers

### PSR-15 Middleware

```php
<?php
declare(strict_types = 1);

namespace App;

use Antidot\React\PromiseResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class SomeMiddleware implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
return new PromiseResponse(
resolve($request)
->then(static fn(ServerrequestInsterface $request) => $handler->handle($request))
);
}
}
```

### PSR-7 Request Handler

```php
<?php
declare(strict_types = 1);

namespace App;

use Antidot\React\PromiseResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class SomeMiddleware implements RequestHandlerInterface
{
public function process(ServerRequestInterface $request): ResponseInterface
{
return resolve($request)->then(
function(ServerrequestInterface $request): ResponseInterface {
return new Response('Hello World!!!');
}
);;
}
}
```

## Server

Two new commands will be added to the Antidot Framework CLI tool, to allow running the application on top of [Drift server](https://driftphp.io/#/?id=the-server)

* `server:run`: Run Drift HTTP Server
* `server:watch`: Watch Drift HTTP Server for development purposes

```bash
$ bin/console
...
server
server:run Run Drift HTTP Server
server:watch Watch Drift HTTP Server for development purposes
```

```bash
$ bin/console server:run -h
Description:
Run Drift HTTP Server

Usage:
server:run [options] [--] [<path>]

Arguments:
path The server will start listening to this address [default: "0.0.0.0:5555"]

Options:
--static-folder[=STATIC-FOLDER] Static folder path [default: "public"]
--no-static-folder Disable static folder
--debug Enable debug
--no-header Disable the header
--no-cookies Disable cookies
--no-file-uploads Disable file uploads
--concurrent-requests[=CONCURRENT-REQUESTS] Limit of concurrent requests [default: 100]
--request-body-buffer[=REQUEST-BODY-BUFFER] Limit of the buffer used for the Request body. In KiB. [default: 4096]
--adapter[=ADAPTER] Server Adapter [default: "Antidot\React\DriftKernelAdapter"]
--allowed-loop-stops[=ALLOWED-LOOP-STOPS] Number of allowed loop stops [default: 0]
--workers[=WORKERS] Number of workers. Use -1 to get as many workers as physical thread available for your system. Maximum of 128 workers. Option disabled for watch command. [default: 16]
-q, --quiet Do not output any message

```

```bash
$ bin/console server:watch -h
Description:
Watch Drift HTTP Server for development purposes

Usage:
server:watch [options] [--] [<path>]

Arguments:
path The server will start listening to this address [default: "0.0.0.0:5555"]

Options:
--static-folder[=STATIC-FOLDER] Static folder path [default: "public"]
--no-static-folder Disable static folder
--debug Enable debug
--no-header Disable the header
--no-cookies Disable cookies
--no-file-uploads Disable file uploads
--concurrent-requests[=CONCURRENT-REQUESTS] Limit of concurrent requests [default: 512]
--request-body-buffer[=REQUEST-BODY-BUFFER] Limit of the buffer used for the Request body. In KiB. [default: 2048]
--adapter[=ADAPTER] Server Adapter [default: "drift"]
--allowed-loop-stops[=ALLOWED-LOOP-STOPS] Number of allowed loop stops [default: 0]
--workers[=WORKERS] Number of workers. Use -1 to get as many workers as physical thread available for your system. Maximum of 128 workers. Option disabled for watch command. [default: 1]
-q, --quiet Do not output any message

```

6 changes: 6 additions & 0 deletions docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# [Antidot Framework](#Antidot-React-Framework)

> *PSR Compatible async full featured Framework*

*[Start on github](https://github.com/antidot-framework/react-framework)*
*[Getting Started](/#Antidot-React-Framework)*
54 changes: 54 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Antidot Framework Reactive Starter</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@antidotframewo1" />
<meta name="twitter:creator" content="@kpickaza" />
<meta property="og:url" content="https://antidotfw.io" />
<meta property="og:title" content="Antidot React Framework" />
<meta property="og:description" content="PHP full featured micro-framework designed to allow you to write 100% framework agnostic code in async way." />
<meta property="og:image" content="https://antidotfw.io//images/antidot-big.jpeg" />
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
<link rel="icon" href="/favicon.ico" />

</head>
<body>
<div id="app"></div>
<script src="//unpkg.com/docsify-edit-on-github/index.js"></script>
<script>
window.$docsify = {
coverpage: true,
name: 'Antidot React Framework',
repo: 'https://github.com/antidot-framework/react-framework.git',
auto2top: true,
executeScript: true,
loadSidebar: false,
subMaxLevel: 3,
paths: 'auto',
tabs: {
persist : true, // default
sync : true, // default
theme : 'material', // default
tabComments: true, // default
tabHeadings: true // default
},
plugins: [
EditOnGithubPlugin.create(
'https://github.com/antidot-framework/react-framework/blob/master/docs/'
),
]
}
</script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/docsify-tabs@1"></script>
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-php.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-yaml.min.js"></script>
<script src="//unpkg.com/docsify-copy-code"></script>
</body>
</html>