本文整理汇总了PHP中Preference::match方法的典型用法代码示例。如果您正苦于以下问题:PHP Preference::match方法的具体用法?PHP Preference::match怎么用?PHP Preference::match使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Preference
的用法示例。
在下文中一共展示了Preference::match方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: targetsFor
/**
* Return routes for given request and response
*
* @param string verb
* @param string path
* @param string type The Content-Type, or NULL
* @param scriptlet.Preference accept the "Accept" header's contents
* @return var[]
*/
public function targetsFor($verb, $path, $type, Preference $accept)
{
if (!isset($this->routes[$verb])) {
return array();
}
// Short-circuit
// Figure out matching routes
$path = rtrim($path, '/');
$matching = $order = array();
foreach ($this->routes[$verb] as $route) {
if (!preg_match($route->getPattern(), $path, $segments)) {
continue;
}
// Check input type if specified by client
if (NULL !== $type) {
$pref = new Preference($route->getAccepts($this->input));
if (NULL === ($input = $pref->match(array($type)))) {
continue;
}
$q = $pref->qualityOf($input, 6);
} else {
$input = NULL;
$q = 0.0;
}
// Check output type
if (NULL === ($output = $accept->match($route->getProduces($this->output)))) {
continue;
}
// Found possible candidate
$matching[] = array('handler' => $route->getHandler(), 'target' => $route->getTarget(), 'params' => $route->getParams(), 'segments' => $segments, 'input' => $input, 'output' => $output);
$order[sizeof($matching) - 1] = $q + $accept->qualityOf($output, 6);
}
// Sort by quality
arsort($order, SORT_NUMERIC);
$return = array();
foreach ($order as $offset => $q) {
$return[] = $matching[$offset];
}
return $return;
}