slgdon / fp-web
功能性Web工具包的测试平台
0.0.8
2015-07-07 00:35 UTC
Requires
- php: >=5.5
Requires (Dev)
- phpdocumentor/phpdocumentor: 2.*
- phpunit/phpunit: ~4.7
- satooshi/php-coveralls: dev-master
This package is auto-updated.
Last update: 2024-09-20 10:50:44 UTC
README
功能性Web工具包的测试平台
这只是一个不使用面向对象代码的Web工具包的实验。
理论上,这只是一点PHP代码,应该可以正常使用,但在实际应用中,不要使用这个,而应该使用更成熟、经过更多测试和更广泛使用的工具。
运行示例
$ git clone https://github.com/slogsdon/php-fp-web
$ cd php-fp-web
$ composer install
$ php -S 0.0.0.0:8888 -t example
在另一个终端会话中
$ curl -i https://:8800/index
HTTP/1.1 200 OK
Host: localhost:8888
Connection: close
X-Powered-By: PHP/5.6.10
Content-type: text/html; charset=UTF-8
index
$ curl -i https://:8800/
HTTP/1.1 404 Not Found
Host: localhost:8888
Connection: close
X-Powered-By: PHP/5.6.10
Content-type: text/html; charset=UTF-8
Not Found
使用方法
<?php require 'vendor/autoload.php'; use \FPWeb\App; use \FPWeb\Route; // index handler $index = function ($conn) { // TODO: make this process nicer $conn['response']['body'] = 'index'; return $conn; }; // create routes $routes = [ Route\get('/index', $index), ]; // match request and run match $response = App\run($routes, [ 'param_set' => [$_GET, $_POST], 'on_error' => function ($conn) { $conn['response']['body'] = 'Not Found'; return $conn; }, ]); printf('<pre><code>%s</code></pre>', print_r($response, true));