tdt/negotiators

一个用于内容和服务语言协商的包。

v1.0.2 2013-02-20 15:41 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:59:10 UTC


README

Build Status

PHP编写的服务语言协商:GET参数将覆盖accept头。支持日志记录(monolog)。

安装

使用composer作为依赖项安装

  1. 在根目录中添加composer.json

  2. 添加依赖项

{ 
  "require" : { 
     "tdt/negotiators" : "1.0.*" 
  }
}
  1. 安装composer:http://getcomposer.com

  2. 运行 "composer install"

  3. 包含 vendor/autoload.php

使用方法

$cn = new \tdt\negotiators\ContentNegotiator();
$format = $cn->pop();
$default_format = "json";

// $this->formatAllowed is a function you have to define yourself
while (!$this->formatAllowed($format) && $cn->hasNext()) {
    $format = $cn->pop();
}

if(! $this->formatAllowed($format)){
     throw new Exception("Could not find an appropriate formatter.");
}

// use $format further on

测试

使用phpunit

$ phpunit tests