Updating accepts() and doing some refactoring.

This commit is contained in:
mark_story 2010-07-01 00:26:15 -04:00
parent 8d32ad2821
commit ba287ec99e

View file

@ -452,10 +452,7 @@ class RequestHandlerComponent extends Object {
return false; return false;
} elseif (is_string($type)) { } elseif (is_string($type)) {
$type = $this->mapAlias($type); $type = $this->mapAlias($type);
if (in_array($type, $accepted)) { return in_array($type, $accepted);
return true;
}
return false;
} }
return false; return false;
} }
@ -477,7 +474,7 @@ class RequestHandlerComponent extends Object {
} elseif (is_array($type)) { } elseif (is_array($type)) {
foreach ($type as $t) { foreach ($type as $t) {
if ($this->requestedWith($t)) { if ($this->requestedWith($t)) {
return $this->mapType($t); return $t;
} }
} }
return false; return false;
@ -689,28 +686,24 @@ class RequestHandlerComponent extends Object {
/** /**
* Maps a content-type back to an alias * Maps a content-type back to an alias
* *
* @param mixed $type Content type * @param mixed $type Either a string content type to map, or an array of types.
* @return mixed Alias * @return mixed Aliases for the types provided.
*/ */
public function mapType($ctype) { public function mapType($ctype) {
if (is_array($ctype)) { if (is_array($ctype)) {
return array_map(array($this, 'mapType'), $ctype); return array_map(array($this, 'mapType'), $ctype);
} else { }
$keys = array_keys($this->__requestContent); $keys = array_keys($this->__requestContent);
$count = count($keys); $count = count($keys);
for ($i = 0; $i < $count; $i++) { foreach ($this->__requestContent as $alias => $types) {
$name = $keys[$i]; if (is_array($types) && in_array($ctype, $types)) {
$type = $this->__requestContent[$name]; return $alias;
} elseif (is_string($types) && $types == $ctype) {
if (is_array($type) && in_array($ctype, $type)) { return $alias;
return $name;
} elseif (!is_array($type) && $type == $ctype) {
return $name;
} }
} }
return $ctype; return null;
}
} }
/** /**