stg/ieu_http

处理HTTP请求和响应的库

2.0.3 2017-07-12 10:44 UTC

This package is auto-updated.

Last update: 2024-08-27 03:43:50 UTC


README

请求

表示HTTP请求的对象。

响应

表示HTTP响应的对象。

JsonResponse

传输JSON编码内容的响应。

RedirectResponse

使用重定向头和meta-refresh的响应。

路由器

将请求路由到相应的处理器。

路由

URL路径描述,包括变量、变量验证和通配符模式。

用法

// {id} matches didgits of all length
$route1a = (new Route('/path/to/user/{id}'))
	->validate('id', '\d+');

// or shorthand

$route1b = (new Route('/path/to/user/{id|\d+}'));

// {everything} matches all allowed chars.
$route2 = new Route('/path/to/{everything}/update');

// Will match every route beginning with /path/to/
$route3 = new Route('/path/to/*')

RouterProvider

用于在ieu.Container.Container依赖注入容器中。实现了与Router相同的接口。在RouterProvider::then-方法中使用的处理器可以访问容器中已知的所有依赖项,以及额外的Request(当前请求)和RouteParameter(在路由模式中找到的所有变量)。

用法

// ieu\Container
(new ieu\Container\Container)
	->provider('Router', new ieu\Http\RouterProvier)
	->config(['RouterProvider', function($routerProvider){
		$routerProvider
			->get('/home', ['Request', 'RouteParameter', function($request, $parameter){
				return new Response('This is the homepage ');
			})
			->otherwise(['Request', 'Error', function($request, $error) {
				// handle error
			});
	}]);

// ieu\App
(new ieu\App)
	->config(['RouterProvider', function($routerProvider){
		$routerProvider
			->get('/home', ['Request', 'RouteParameter', function($request, $parameter){
				return new Response('This is the homepage ');
			});
	}]);