JsonApiMiddleware::__construct PHP Method

__construct() public method

Sets a buch of static API calls
public __construct ( )
    function __construct()
    {
        $app = \Slim\Slim::getInstance();
        $app->config('debug', false);
        // Mirrors the API request
        $app->get('/return', function () use($app) {
            $app->render(200, array('method' => $app->request()->getMethod(), 'name' => $app->request()->get('name'), 'headers' => $app->request()->headers(), 'params' => $app->request()->params()));
        });
        // Generic error handler
        $app->error(function (Exception $e) use($app) {
            if ($e->getCode()) {
                $errorCode = $e->getCode();
            } else {
                $errorCode = 500;
            }
            // Log error with the same message
            $message = \JsonApiMiddleware::_errorType($e->getCode()) . ": " . $e->getMessage();
            $app->getLog()->error($message . ' in ' . $e->getFile() . ' at line ' . $e->getLine());
            $app->render($errorCode, array('msg' => $message));
        });
        // Not found handler (invalid routes, invalid method types)
        $app->notFound(function () use($app) {
            $app->render(404, array('msg' => 'Invalid route'));
        });
        // Handle Empty response body
        $app->hook('slim.after.router', function () use($app) {
            //Fix sugested by: https://github.com/bdpsoft
            //Will allow download request to flow
            if ($app->response()->header('Content-Type') === 'application/octet-stream') {
                return;
            }
            if (strlen($app->response()->body()) == 0) {
                $app->render(500, array('msg' => 'Empty response'));
            }
        });
    }