public static function handleRequest()
 {
     if (empty(Site::$pathStack) || empty(Site::$pathStack[0])) {
         return static::throwInvalidRequestError();
     }
     // get endpoint
     if (!($Endpoint = Endpoints\Endpoint::getFromPath(Site::$pathStack))) {
         return static::throwNotFoundError('Endpoint not found');
     }
     // check access
     if (!$Endpoint->Public) {
         $GLOBALS['Session']->requireAccountLevel('Staff');
     }
     return static::respond('docs', $Endpoint->getSwaggerData());
 }
<?php

namespace Gatekeeper;

use Gatekeeper\Endpoints\Endpoint;
// detect endpoint if it has not already been set
if (!$_EVENT['request']->getEndpoint()) {
    if (!($Endpoint = Endpoint::getFromPath($_EVENT['request']->getPathStack()))) {
        return ApiRequestHandler::throwNotFoundError('No endpoint was found that can handle this path');
    }
    // trim path stack
    $_EVENT['request']->setPathStack(array_slice($_EVENT['request']->getPathStack(), substr_count($Endpoint->Path, '/') + 1));
    // save determined endpoint to request object
    $_EVENT['request']->setEndpoint($Endpoint);
}