Esempio n. 1
0
        $records = $app->getReturnedValue();
        $response = new \Api\Responses\JSONResponse();
        $response->useEnvelope(true)->convertSnakeCase(false)->send($records);
        return;
    } else {
        if ($app->request->get('format') == 'javascript') {
            // Results returned from the route's controller.  All Controllers should return an array
            $records = $app->getReturnedValue();
            $response = new \Api\Responses\JavascriptResponse();
            $response->useEnvelope(true)->convertSnakeCase(false)->send($records);
            return;
        } else {
            if ($app->request->get('format') == 'csv') {
                $records = $app->getReturnedValue();
                $response = new \Api\Responses\CSVResponse();
                $response->useHeaderRow(true)->send($records);
                return;
            } else {
                throw new \Api\Exceptions\HTTPException('Could not return results in specified format', 403, array('dev' => 'Could not understand format specified by format paramter in query string.', 'internalCode' => 'NF1000', 'more' => 'Type may not be implemented. Choose either "csv" or "json"'));
            }
        }
    }
});
/**
 * The notFound service is the default handler function that runs when no route was matched.
 * We set a 404 here unless there's a suppress error codes.
 */
$app->notFound(function () use($app) {
    throw new \Api\Exceptions\HTTPException('Not Found.', 404, array('dev' => 'That route was not found on the server.', 'internalCode' => 'NF1000', 'more' => 'Check route for mispellings.'));
});
/**