public function adaptResponse($contentType, Request $request, Response $response, array $result)
 {
     if ($contentType != "application/json") {
         return false;
     }
     $response->setContent(json_encode(iterator_to_array_recursive($result)));
     return true;
 }
Example #2
0
/**
 * Iterator trough a traversable recursively
 * 
 * @param mixed $traversable
 * @return array
 */
function iterator_to_array_recursive($traversable)
{
    $results = array();
    foreach ($traversable as $key => $value) {
        if (is_array($value) || is_object($value)) {
            $value = iterator_to_array_recursive($value);
        }
        $results[$key] = $value;
    }
    return $results;
}