odino/exphpress
Composer 安装命令:
composer require odino/exphpress
包简介
The missing, elegant, productive microframework for PHP, inspired by ExpressJS.
README 文档
README
The missing, elegant, productive microframework for PHP, inspired by ExpressJS.
Because PHP is cool too.
Example
The very least you need:
<?php $app = Exphpress\app(); $app->listen(function($req, $res){ $date = new \DateTime(); $res->setContent("Today is " . $date->format('l, jS \o\f F Y')); });
This will return, for every request, something like
Today is Sunday, 13th of July 2014,; if you want to see it in action
clone this repository and run php -S localhost:4000 examples/simple.php.
Getting fancy
Matching a GET request is quite simple:
<?php $app = Exphpress\app(); $app->get("/call-me-maybe/{name}", function($req, $res){ $res->setContent("Hey, I just matched you, and this is crazy..."); });
The above route will be matched when we issue a GET request to our
webserver that matches the path /call-me-maybe/{name}.
The same can be done for post and all other HTTP methods.
Write your own middleware
Middlewares play a big part in a microframework's architecture:
$app->uses(function($req, $res, $next){ if ($todayIsABadDay) { $res->setStatusCode(403); $res->setContent(null); } else { $next(); } });
As you probably understood, the $next is a callback that invokes
the following middleware, which means that you concatenate them at
will (ie. look at this test).
Installation
Exphpress is available through composer (how else?!?!).
Tests
They run on travis through phpspec: if you want to contribute or hack around exphpress simply clone this repository and check into greenland with a:
./vendor/bin/phpspec run
License
For those who care, exphpress is release under the MIT license.
The hell, why?
There's Silex, I know, but I couldn't resist.
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-07-13