sasezaki/backbeard
Composer 安装命令:
composer require sasezaki/backbeard
包简介
yet another DSLish minimum oriented framework for PHP
README 文档
README
Backbeard is yet another DSLish minimum oriented framework for PHP.
Principle
yield $router($request) => $action();
Usage
<?php use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; use Backbeard\Dispatcher; use Backbeard\ValidationError; $routingFactory = function ($container) { yield '/hello' => 'hello'; $error = (yield ['POST' => '/entry/{id:[0-9]}'] => function ($id) { if ($this->getRequest()->getPost()['NAME'] == 'wtf') { return ['var1' => 'baz']; // will be render entry.phtml } else { return new ValidationError(['error message!']); } }); yield '/entry/{id:[0-9]}' => function ($id) use ($error) { $message = $error ? htmlspecialchars(current($error->getMessages())) :''; return "Hello $id ".$message. '<form method="POST" action="/entry/'.$id.'">'. 'NAME<input type="text" name="NAME">'. '</form>'; }; yield [ 'GET' => '/foo', 'Header' => [ 'User-Agent' => function($headers){ if (!empty($headers) && strpos(current($headers), 'Coffee') === 0) { return true; } } ] ] => function () { return $this->getResponseFactory()->createResponse(418); }; // status code "I'm a teapot" yield (ServerRequestInterface $request) { return true; } => function () { /** @var ResponseInterface $this */ return $this; }; }; (new Dispatcher($routingFactory($container)))->dispatch(new Request);
Install with composer
composer require sasezaki/backbeard dev-master
Using As Middleware for zend-stratigility
https://github.com/struggle-for-php/sfp-stratigility-skeleton
-
php composer.phar create-project -s dev struggle-for-php/sfp-stratigility-skeleton path/to/installWhen install finished, you can try running with php built-in web server
-
php -S localhost:8080 -t public/ public/index.php
NOTES
THIS PROJECT IS A PROOF OF CONCEPT FOR GENERATOR BASED ROUTER, AND NOT INTENDED FOR PRODUCTION USE. PLEASE USE AT YOUR OWN RISK.
统计信息
- 总下载量: 98
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2014-01-11