2017 © Pedro Peláez
 

library poa

POA Web框架灵感来自于Node.js的KOA框架,基于React-PHP,使用生成器来实现中间件,轻松的组合管理多个中间件之间的协作

image

york8/poa

POA Web框架灵感来自于Node.js的KOA框架,基于React-PHP,使用生成器来实现中间件,轻松的组合管理多个中间件之间的协作

  • Wednesday, February 28, 2018
  • by york8
  • Repository
  • 0 Watchers
  • 1 Stars
  • 10 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

POA

Latest Version on Packagist ![Software License][ico-license] Total Downloads, (*1)

POA(Php cOroutine based Application framework)Web框架,灵感来自于 Node.js 的 KOA 框架,基于 React-PHP, 使用 PHP 的生成器来实现中间件,轻松的组合管理多个中间件之间的协作。, (*2)

作者

安装

composer require york8/poa

使用

// 1. create the Application
$app = new Application();

// 2. define the route rules
$router = new RouterMiddleware(function (Context $context) {
    $context->statusCode(404)->send('Not Found');
});
$router->get(
    '/foo/bar$',
    function (Context $context) {
        $context->send('Hello, ' . $context->getRequest()->getUri());
    }
)->get(
    '/foo/exception',
    function () {
        throw new Exception('I throw an exception just for fun, haha!');
    }
);

// 3. use middlewares what you need
$app->use(new ProfileMiddleware())
    // simple error handle middleware
    ->use(function (Context $context) {
        try {
            yield;
        } catch (Exception $e) {
            fwrite(STDERR, 'EXP: ' . $e->getMessage() . "\n");
            $context->statusCode(500)->send('Exp: ' . $e->getMessage());
        }
    })
    ->use(function (Context $context) {
        $uri = $context->getRequest()->getUri();
        if ($uri->getPath() === '/bar') {
            $context->send('you fire.');
            return false;
        }
        return null;
    })
    ->use($router)
    // global error handle middleware
    ->useErrorMiddleware(function (Throwable $throwable, Context $context) {
        // handle global exception
        $msg = $throwable->getMessage();
        fwrite(STDERR, 'Global Exp: ' . $msg . "\n");
        if ($context) {
            $context->statusCode(500)->send('Oh, No! ' . $msg);
        }
    });

// 4. listen and start the server
$app->listen(8088);

License

The MIT License (MIT). Please see License File for more information., (*3)

The Versions

28/02 2018

dev-master

9999999-dev

POA Web框架灵感来自于Node.js的KOA框架,基于React-PHP,使用生成器来实现中间件,轻松的组合管理多个中间件之间的协作

  Sources   Download

MIT

The Requires

 

by York

middleware framework generator react-php koa

28/02 2018

0.4.1

0.4.1.0

POA Web框架灵感来自于Node.js的KOA框架,基于React-PHP,使用生成器来实现中间件,轻松的组合管理多个中间件之间的协作

  Sources   Download

MIT

The Requires

 

by York

middleware framework generator react-php koa

25/02 2018

0.4.0

0.4.0.0

POA Web框架灵感来自于Node.js的KOA框架,基于React-PHP,使用生成器来实现中间件,轻松的组合管理多个中间件之间的协作

  Sources   Download

MIT

The Requires

 

by York

middleware framework generator react-php koa

23/02 2018

0.3.3

0.3.3.0

POA Web框架灵感来自于Node.js的KOA框架,基于React-PHP,使用生成器来实现中间件,轻松的组合管理多个中间件之间的协作

  Sources   Download

MIT

The Requires

 

by York

middleware framework generator react-php koa

26/01 2018

0.3.2

0.3.2.0

POA Web框架灵感来自于Node.js的KOA框架,基于React-PHP,使用生成器来实现中间件,轻松的组合管理多个中间件之间的协作

  Sources   Download

MIT

The Requires

 

by York

middleware framework generator react-php koa

21/01 2018

0.3.1

0.3.1.0

POA Web框架灵感来自于Node.js的KOA框架,基于React-PHP,使用生成器来实现中间件,轻松的组合管理多个中间件之间的协作

  Sources   Download

MIT

The Requires

 

by York

middleware framework generator react-php koa

21/01 2018

0.3.0

0.3.0.0

POA Web框架灵感来自于Node.js的KOA框架,基于React-PHP,使用生成器来实现中间件,轻松的组合管理多个中间件之间的协作

  Sources   Download

MIT

The Requires

 

by York

middleware framework generator react-php koa