2017 © Pedro Peláez
 

library reactphp-slim

Slim Request and Response extended to allow reactPHP serve a Slim framework instance

image

easyconn/reactphp-slim

Slim Request and Response extended to allow reactPHP serve a Slim framework instance

  • Thursday, October 27, 2016
  • by zhuzhu
  • Repository
  • 1 Watchers
  • 1 Stars
  • 16 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 4 Versions
  • 14 % Grown

The README.md

reactphp-slim

Introduction

This library is created in order to use reactPHP as a HTTP server for Slim framework, I have extended Slim request and response objects to implement functions which allows us to transfer data from native reactPHP objects into Slim objects. With this we will be able to create a basic react server for Slim framework., (*1)

Now working on a new way to setup the reactPHP server and run the Slim Application, please use v0.4.2 release (doc bellow), this version is not finished yet, I'm testing it., (*2)

require '../vendor/autoload.php';

use \mbarquin\reactSlim;

// We keep a new Slim app instance.
$app = new \Slim\App();

// We add a closure to attend defined request routes
$app->any('/hello/{name}', function (
        \Slim\Http\Request $request,
        \Slim\Http\Response $response) {

        $name = $request->getAttribute('name');
        $response->getBody()->write("Hello, $name");

        return $response;
    });

$server = new \mbarquin\reactSlim\Server();

$server->withPort(1337)->run($app);

v0.4.2 Setup

This is the old setup to run the reactPHP server with a slimPHP application, (*3)

require '../vendor/autoload.php';

use mbarquin\reactSlim;

// We keep a new Slim app instance.
$app = new \Slim\App();

// We add a closure to listen defined request routes
$app->get('/hello/{name}', function (
        \mbarquin\reactSlim\Request $request,
        \mbarquin\reactSlim\Response $response) {

        $name = $request->getAttribute('name');
        $response->getBody()->write("Hello, $name");

        return $response;
    });

// We create a closure to be attached to server request event.
$serverCallback = function (
       \React\Http\Request $request,
       \React\Http\Response $response) use ($app){

    $slRequest  = \mbarquin\reactSlim\Request::createFromReactRequest($request);
    $slResponse = new \mbarquin\reactSlim\Response();

    $app->process($slRequest, $slResponse);

    $slResponse->setReactResponse($response, true);
};

// We make the setup of the ReactPHP
$loop   = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http   = new React\Http\Server($socket, $loop);

// Ligamos la closure al evento request.
$http->on('request', $serverCallback);

echo "Server running at http://127.0.0.1:1337\n";

$socket->listen(1337);
$loop->run();

The Versions

27/10 2016

dev-master

9999999-dev

Slim Request and Response extended to allow reactPHP serve a Slim framework instance

  Sources   Download

MIT

The Requires

 

31/08 2016

v0.4.2

0.4.2.0

Slim Request and Response extended to allow reactPHP serve a Slim framework instance

  Sources   Download

MIT

The Requires

 

13/07 2016

v0.4.1

0.4.1.0

Slim Request and Response extended to allow reactPHP serve a Slim framework instance

  Sources   Download

MIT

The Requires

 

13/07 2016

0.4.0

0.4.0.0

Slim Request and Response extended to allow reactPHP serve a Slim framework instance

  Sources   Download

MIT

The Requires