pff/accept-header-service-provider
Composer 安装命令:
composer require pff/accept-header-service-provider
包简介
A service provider to help enable accept header filtering for routes
README 文档
README
This serivce provider enables you to easily filter routes based on accept headers in Silex.
To install, require the package through composer (or install it any other way you care to...)
"pff/accept-header-service-provider": "dev-master"
To use it, simply do the following:
<?php use Pff\ServiceProvider\AcceptHeaderServiceProvider\AcceptHeaderServiceProvider; $app->register(new AcceptHeaderServiceProvider()); $app->get('/test', function($accept_header) { if ($accept_header == 'application/ven.test.v1+json') $cont = json_encode(array('content' => 'hello')); else $cont = '<content>hello</content>'; return new Response($cont, 200, array('Content-Type' => $accept_header)); })->accept(array('application/ven.test.v1+json', 'application/ven.test.v1+xml')); $app->get('/test', function($accept_header) { if ($accept_header == 'application/ven.test.v2+json') $cont = json_encode(array('content' => 'hiya')); else $cont = '<content>hiya</content>'; return new Response($cont, 200, array('Content-Type' => $accept_header)); })->accept(array('application/ven.test.v2+json', 'application/ven.test.v2+xml'));
Now a request with accept headers including application/ven.test.v1+json and application/ven.test.v1+xml
will be handled by the first route, and requests with accept headers including application/ven.test.v2+json and
application/ven.test.v2+xml will be routed to the second.
统计信息
- 总下载量: 12.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2012-10-04