pff/accept-header-service-provider

该软件包的最新版本(v0.1.4)没有提供许可信息。

一个服务提供商,用于帮助启用路由的接受头过滤

v0.1.4 2012-10-04 18:34 UTC

This package is not auto-updated.

Last update: 2024-09-28 12:51:41 UTC


README

Build Status

此服务提供商使您能够轻松根据Silex中的接受头过滤路由。

要安装,请通过composer(或其他您喜欢的任何方式)要求该软件包

"pff/accept-header-service-provider": "dev-master"

要使用它,请按照以下步骤操作

    <?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'));

现在,带有接受头 application/ven.test.v1+jsonapplication/ven.test.v1+xml 的请求将由第一个路由处理,而带有接受头 application/ven.test.v2+jsonapplication/ven.test.v2+xml 的请求将被路由到第二个。