Scalr\Api\Rest\ApiApplication::setupRoutes PHP Метод

setupRoutes() публичный Метод

Sets up all API routes
public setupRoutes ( ) : ApiApplication
Результат ApiApplication Returns current instance
    public function setupRoutes()
    {
        $this->group('/api', [$this, 'handleApiVersion'], [$this, 'preflightRequestHandlerMiddleware'], [$this, 'authenticationMiddleware'], function () {
            $this->group('/v:apiversion', function () {
                $roleRequirements = ['roleId' => '\\d+'];
                $imageRequirements = ['imageId' => ApiApplication::REGEXP_UUID];
                $eventRequirements = ['eventId' => Entity\EventDefinition::NAME_REGEXP];
                $osRequirements = ['osId' => Entity\Os::ID_REGEXP];
                $ccRequirements = ['ccId' => ApiApplication::REGEXP_UUID];
                $cloudCredsRequirements = ['cloudCredentialsId' => static::REGEXP_SHORT_UUID];
                $orchestrationRuleRequirements = ['ruleId' => '\\d+'];
                $scriptRequirements = ['scriptId' => '\\d+'];
                $scriptVersionReqs = array_merge($scriptRequirements, ['versionNumber' => '\\d+']);
                $roleImageReqs = array_merge($roleRequirements, $imageRequirements);
                $roleCategoryReqs = ['roleCategoryId' => '\\d+'];
                $roleVariableReqs = array_merge($roleRequirements, ['variableName' => '\\w+']);
                $roleScriptReqs = array_merge($roleRequirements, $orchestrationRuleRequirements);
                $this->group('/admin', function () {
                    //All Admin API routes are here
                    $this->get('/users/:userId', 'Admin_Users:get', ['userId' => '\\d+']);
                });
                $this->group('/account', function () use($eventRequirements, $roleRequirements, $imageRequirements, $roleImageReqs, $roleCategoryReqs, $roleVariableReqs, $roleScriptReqs, $osRequirements, $ccRequirements, $cloudCredsRequirements, $orchestrationRuleRequirements, $scriptRequirements, $scriptVersionReqs) {
                    //All Account API routes are here
                    $envRequirements = ['envId' => '\\d+'];
                    $teamsReqs = ['teamId' => '\\d+'];
                    $envCloudsReqs = array_merge($envRequirements, ['cloud' => '\\w+']);
                    $envTeamsReqs = array_merge($envRequirements, $teamsReqs);
                    $this->get('/os', ['controller' => 'User_Os:get']);
                    $this->get('/os/:osId', ['controller' => 'User_Os:fetch'], $osRequirements);
                    $this->get('/teams', 'Account_Teams:describe');
                    $this->post('/teams', 'Account_Teams:create');
                    $this->get('/teams/:teamId', 'Account_Teams:fetch', $teamsReqs);
                    $this->patch('/teams/:teamId', 'Account_Teams:modify', $teamsReqs);
                    $this->delete('/teams/:teamId', 'Account_Teams:delete', $teamsReqs);
                    $this->get('/acl-roles', 'Account_AclRoles:describe');
                    $this->get('/environments', 'Account_Environments:describe');
                    $this->post('/environments', 'Account_Environments:create');
                    $this->get('/environments/:envId', 'Account_Environments:fetch', $envRequirements);
                    $this->patch('/environments/:envId', 'Account_Environments:modify', $envRequirements);
                    $this->delete('/environments/:envId', 'Account_Environments:delete', $envRequirements);
                    $this->get('/environments/:envId/clouds', 'Account_Environments:describeClouds', $envRequirements);
                    $this->get('/environments/:envId/clouds/:cloud', 'Account_Environments:fetchCloudCredentials', $envCloudsReqs);
                    $this->post('/environments/:envId/clouds/:cloud', 'Account_Environments:attachCredentials', $envCloudsReqs);
                    $this->delete('/environments/:envId/clouds/:cloud', 'Account_Environments:detachCredentials', $envCloudsReqs);
                    $this->get('/environments/:envId/teams', 'Account_Environments:describeTeams', $envRequirements);
                    $this->post('/environments/:envId/teams', 'Account_Environments:allowTeam', $envRequirements);
                    $this->delete('/environments/:envId/teams/:teamId', 'Account_Environments:denyTeam', $envTeamsReqs);
                    //We explicitly set array of the options to exclude the Route Name as both environment and
                    //account levels have the same controllers and all registered Route Names must be unique withing the router.
                    $this->get('/events', ['controller' => 'User_Events:describe']);
                    $this->get('/events/:eventId', ['controller' => 'User_Events:fetch'], $eventRequirements);
                    $this->post('/events', ['controller' => 'User_Events:create']);
                    $this->patch('/events/:eventId', ['controller' => 'User_Events:modify'], $eventRequirements);
                    $this->delete('/events/:eventId', ['controller' => 'User_Events:delete'], $eventRequirements);
                    $this->get('/images', ['controller' => 'User_Images:describe']);
                    $this->post('/images', ['controller' => 'User_Images:register']);
                    $this->get('/images/:imageId', ['controller' => 'User_Images:fetch'], $imageRequirements);
                    $this->patch('/images/:imageId', ['controller' => 'User_Images:modify'], $imageRequirements);
                    $this->delete('/images/:imageId', ['controller' => 'User_Images:deregister'], $imageRequirements);
                    $this->post('/images/:imageId/actions/:action/', ['controller' => 'User_Images:copy'], array_merge($imageRequirements, ['action' => 'copy']));
                    $this->get('/roles', ['controller' => 'User_Roles:describe']);
                    $this->post('/roles', ['controller' => 'User_Roles:create']);
                    $this->get('/roles/:roleId', ['controller' => 'User_Roles:fetch'], $roleRequirements);
                    $this->patch('/roles/:roleId', ['controller' => 'User_Roles:modify'], $roleRequirements);
                    $this->delete('/roles/:roleId', ['controller' => 'User_Roles:delete'], $roleRequirements);
                    $this->get('/roles/:roleId/images/', ['controller' => 'User_Roles:describeImages'], $roleRequirements);
                    $this->post('/roles/:roleId/images/', ['controller' => 'User_Roles:registerImage'], $roleRequirements);
                    $this->get('/roles/:roleId/images/:imageId', ['controller' => 'User_Roles:fetchImage'], $roleImageReqs);
                    $this->delete('/roles/:roleId/images/:imageId', ['controller' => 'User_Roles:deregisterImage'], $roleImageReqs);
                    $this->post('/roles/:roleId/images/:imageId/actions/:action/', ['controller' => 'User_Roles:replaceImage'], array_merge($roleImageReqs, ['action' => 'replace']));
                    $this->get('/role-categories', ['controller' => 'User_RoleCategories:describe']);
                    $this->post('/role-categories', ['controller' => 'User_RoleCategories:create']);
                    $this->get('/role-categories/:roleCategoryId', ['controller' => 'User_RoleCategories:fetch'], $roleCategoryReqs);
                    $this->patch('/role-categories/:roleCategoryId', ['controller' => 'User_RoleCategories:modify'], $roleCategoryReqs);
                    $this->delete('/role-categories/:roleCategoryId', ['controller' => 'User_RoleCategories:delete'], $roleCategoryReqs);
                    $this->get('/roles/:roleId/global-variables', ['controller' => 'User_Roles:describeVariables'], $roleRequirements);
                    $this->post('/roles/:roleId/global-variables', ['controller' => 'User_Roles:createVariable'], $roleRequirements);
                    $this->get('/roles/:roleId/global-variables/:variableName', ['controller' => 'User_Roles:fetchVariable'], $roleVariableReqs);
                    $this->patch('/roles/:roleId/global-variables/:variableName', ['controller' => 'User_Roles:modifyVariable'], $roleVariableReqs);
                    $this->delete('/roles/:roleId/global-variables/:variableName', ['controller' => 'User_Roles:deleteVariable'], $roleVariableReqs);
                    $this->get('/roles/:roleId/orchestration-rules', ['controller' => 'User_RoleScripts:describe'], $roleRequirements);
                    $this->post('/roles/:roleId/orchestration-rules', ['controller' => 'User_RoleScripts:create'], $roleRequirements);
                    $this->get('/roles/:roleId/orchestration-rules/:ruleId', ['controller' => 'User_RoleScripts:fetch'], $roleScriptReqs);
                    $this->patch('/roles/:roleId/orchestration-rules/:ruleId', ['controller' => 'User_RoleScripts:modify'], $roleScriptReqs);
                    $this->delete('/roles/:roleId/orchestration-rules/:ruleId', ['controller' => 'User_RoleScripts:delete'], $roleScriptReqs);
                    $this->get('/orchestration-rules', 'User_AccountScripts:describe');
                    $this->post('/orchestration-rules', 'User_AccountScripts:create');
                    $this->get('/orchestration-rules/:ruleId', 'User_AccountScripts:fetch', $orchestrationRuleRequirements);
                    $this->patch('/orchestration-rules/:ruleId', 'User_AccountScripts:modify', $orchestrationRuleRequirements);
                    $this->delete('/orchestration-rules/:ruleId', 'User_AccountScripts:delete', $orchestrationRuleRequirements);
                    $this->get('/scripts', ['controller' => 'User_Scripts:describe']);
                    $this->post('/scripts', ['controller' => 'User_Scripts:create']);
                    $this->get('/scripts/:scriptId', ['controller' => 'User_Scripts:fetch'], $scriptRequirements);
                    $this->patch('/scripts/:scriptId', ['controller' => 'User_Scripts:modify'], $scriptRequirements);
                    $this->delete('/scripts/:scriptId', ['controller' => 'User_Scripts:delete'], $scriptRequirements);
                    $this->get('/scripts/:scriptId/script-versions', ['controller' => 'User_ScriptVersions:describe'], $scriptRequirements);
                    $this->post('/scripts/:scriptId/script-versions', ['controller' => 'User_ScriptVersions:create'], $scriptRequirements);
                    $this->get('/scripts/:scriptId/script-versions/:versionNumber', ['controller' => 'User_ScriptVersions:fetch'], $scriptVersionReqs);
                    $this->patch('/scripts/:scriptId/script-versions/:versionNumber', ['controller' => 'User_ScriptVersions:modify'], $scriptVersionReqs);
                    $this->delete('/scripts/:scriptId/script-versions/:versionNumber', ['controller' => 'User_ScriptVersions:delete'], $scriptVersionReqs);
                    $this->get("/cloud-credentials", ['controller' => 'User_CloudCredentials:describe']);
                    $this->post("/cloud-credentials", ['controller' => 'User_CloudCredentials:create']);
                    $this->get("/cloud-credentials/:cloudCredentialsId", ['controller' => 'User_CloudCredentials:fetch'], $cloudCredsRequirements);
                    $this->patch("/cloud-credentials/:cloudCredentialsId", ['controller' => 'User_CloudCredentials:modify'], $cloudCredsRequirements);
                    $this->delete("/cloud-credentials/:cloudCredentialsId", ['controller' => 'User_CloudCredentials:delete'], $cloudCredsRequirements);
                    if ($this->getContainer()->config->{"scalr.analytics.enabled"}) {
                        $this->get('/cost-centers/', ['controller' => 'User_CostCenters:describe']);
                        $this->get('/cost-centers/:ccId', ['controller' => 'User_CostCenters:fetch'], $ccRequirements);
                    }
                });
                $this->group('/user/:environment', [$this, 'handleEnvironment'], [$this, 'environmentAuthenticationMiddleware'], function () use($eventRequirements, $roleRequirements, $imageRequirements, $roleImageReqs, $roleCategoryReqs, $roleVariableReqs, $roleScriptReqs, $osRequirements, $ccRequirements, $cloudCredsRequirements, $orchestrationRuleRequirements, $scriptRequirements, $scriptVersionReqs) {
                    //All User API Environment level routes are here
                    $farmRequirements = ['farmId' => '\\d+'];
                    $farmRoleRequirements = ['farmRoleId' => '\\d+'];
                    $farmVariableReqs = array_merge($farmRequirements, ['variableName' => '\\w+']);
                    $farmRoleVariableReqs = array_merge($farmRoleRequirements, ['variableName' => '\\w+']);
                    $farmRoleScriptReqs = array_merge($farmRoleRequirements, $orchestrationRuleRequirements);
                    $scalingMetricsReqs = ['metricName' => Entity\ScalingMetric::NAME_REGEXP];
                    $farmRoleScalingRuleReqs = array_merge($farmRoleRequirements, ['scalingRuleName' => Entity\ScalingMetric::NAME_REGEXP]);
                    $serverRequirements = ['serverId' => ApiApplication::REGEXP_UUID];
                    $this->get('/os', 'User_Os:get');
                    $this->get('/os/:osId', 'User_Os:fetch', $osRequirements);
                    $this->get('/events', 'User_Events:describe');
                    $this->get('/events/:eventId', 'User_Events:fetch', $eventRequirements);
                    $this->post('/events', 'User_Events:create');
                    $this->patch('/events/:eventId', 'User_Events:modify', $eventRequirements);
                    $this->delete('/events/:eventId', 'User_Events:delete', $eventRequirements);
                    $this->get('/images', 'User_Images:describe');
                    $this->post('/images', 'User_Images:register');
                    $this->get('/images/:imageId', 'User_Images:fetch', $imageRequirements);
                    $this->patch('/images/:imageId', 'User_Images:modify', $imageRequirements);
                    $this->delete('/images/:imageId', 'User_Images:deregister', $imageRequirements);
                    $this->post('/images/:imageId/actions/:action/', 'User_Images:copy', array_merge($imageRequirements, ['action' => 'copy']));
                    $this->get('/roles', 'User_Roles:describe');
                    $this->post('/roles', 'User_Roles:create');
                    $this->get('/roles/:roleId', 'User_Roles:fetch', $roleRequirements);
                    $this->patch('/roles/:roleId', 'User_Roles:modify', $roleRequirements);
                    $this->delete('/roles/:roleId', 'User_Roles:delete', $roleRequirements);
                    $this->get('/roles/:roleId/images/', 'User_Roles:describeImages', $roleRequirements);
                    $this->post('/roles/:roleId/images/', 'User_Roles:registerImage', $roleRequirements);
                    $this->get('/roles/:roleId/images/:imageId', 'User_Roles:fetchImage', $roleImageReqs);
                    $this->delete('/roles/:roleId/images/:imageId', 'User_Roles:deregisterImage', $roleImageReqs);
                    $this->post('/roles/:roleId/images/:imageId/actions/:action/', 'User_Roles:replaceImage', array_merge($roleImageReqs, ['action' => 'replace']));
                    $this->get('/role-categories', 'User_RoleCategories:describe');
                    $this->post('/role-categories', 'User_RoleCategories:create');
                    $this->get('/role-categories/:roleCategoryId', 'User_RoleCategories:fetch', $roleCategoryReqs);
                    $this->patch('/role-categories/:roleCategoryId', 'User_RoleCategories:modify', $roleCategoryReqs);
                    $this->delete('/role-categories/:roleCategoryId', 'User_RoleCategories:delete', $roleCategoryReqs);
                    $this->get('/roles/:roleId/global-variables', 'User_Roles:describeVariables', $roleRequirements);
                    $this->post('/roles/:roleId/global-variables', 'User_Roles:createVariable', $roleRequirements);
                    $this->get('/roles/:roleId/global-variables/:variableName', 'User_Roles:fetchVariable', $roleVariableReqs);
                    $this->patch('/roles/:roleId/global-variables/:variableName', 'User_Roles:modifyVariable', $roleVariableReqs);
                    $this->delete('/roles/:roleId/global-variables/:variableName', 'User_Roles:deleteVariable', $roleVariableReqs);
                    $this->get('/roles/:roleId/orchestration-rules', 'User_RoleScripts:describe', $roleRequirements);
                    $this->post('/roles/:roleId/orchestration-rules', 'User_RoleScripts:create', $roleRequirements);
                    $this->get('/roles/:roleId/orchestration-rules/:ruleId', 'User_RoleScripts:fetch', $roleScriptReqs);
                    $this->patch('/roles/:roleId/orchestration-rules/:ruleId', 'User_RoleScripts:modify', $roleScriptReqs);
                    $this->delete('/roles/:roleId/orchestration-rules/:ruleId', 'User_RoleScripts:delete', $roleScriptReqs);
                    $this->get('/farms', 'User_Farms:describe');
                    $this->post('/farms', 'User_Farms:create');
                    $this->get('/farms/:farmId', 'User_Farms:fetch', $farmRequirements);
                    $this->patch('/farms/:farmId', 'User_Farms:modify', $farmRequirements);
                    $this->delete('/farms/:farmId', 'User_Farms:delete', $farmRequirements);
                    $this->get('/farms/:farmId/servers', 'User_Farms:describeServers', $farmRequirements);
                    $this->get('/farms/:farmId/global-variables', 'User_Farms:describeVariables', $farmRequirements);
                    $this->post('/farms/:farmId/global-variables', 'User_Farms:createVariable', $farmRequirements);
                    $this->get('/farms/:farmId/global-variables/:variableName', 'User_Farms:fetchVariable', $farmVariableReqs);
                    $this->patch('/farms/:farmId/global-variables/:variableName', 'User_Farms:modifyVariable', $farmVariableReqs);
                    $this->delete('/farms/:farmId/global-variables/:variableName', 'User_Farms:deleteVariable', $farmVariableReqs);
                    $this->post('/farms/:farmId/actions/launch', 'User_Farms:launch', $farmRequirements);
                    $this->post('/farms/:farmId/actions/terminate', 'User_Farms:terminate', $farmRequirements);
                    $this->post('/farms/:farmId/actions/clone', 'User_Farms:clone', $farmRequirements);
                    $this->get('/farms/:farmId/farm-roles', 'User_FarmRoles:describe', $farmRequirements);
                    $this->post('/farms/:farmId/farm-roles', 'User_FarmRoles:create', $farmRequirements);
                    $this->get('/farm-roles/:farmRoleId', 'User_FarmRoles:fetch', $farmRoleRequirements);
                    $this->patch('/farm-roles/:farmRoleId', 'User_FarmRoles:modify', $farmRoleRequirements);
                    $this->delete('/farm-roles/:farmRoleId', 'User_FarmRoles:delete', $farmRoleRequirements);
                    $this->get('/farm-roles/:farmRoleId/servers', 'User_FarmRoles:describeServers', $farmRoleRequirements);
                    $this->post('/farm-roles/:farmRoleId/actions/import-server', 'User_FarmRoles:importServer', $farmRoleRequirements);
                    $this->get('/farm-roles/:farmRoleId/placement', 'User_FarmRoles:describePlacement', $farmRoleRequirements);
                    $this->patch('/farm-roles/:farmRoleId/placement', 'User_FarmRoles:modifyPlacement', $farmRoleRequirements);
                    $this->get('/farm-roles/:farmRoleId/instance', 'User_FarmRoles:describeInstance', $farmRoleRequirements);
                    $this->patch('/farm-roles/:farmRoleId/instance', 'User_FarmRoles:modifyInstance', $farmRoleRequirements);
                    $this->get('/farm-roles/:farmRoleId/scaling', 'User_FarmRoles:describeScaling', $farmRoleRequirements);
                    $this->post('/farm-roles/:farmRoleId/scaling', 'User_FarmRoles:createScalingRule', $farmRoleRequirements);
                    $this->patch('/farm-roles/:farmRoleId/scaling', 'User_FarmRoles:modifyScaling', $farmRoleRequirements);
                    $this->get('/farm-roles/:farmRoleId/scaling/:scalingRuleName', 'User_FarmRoles:fetchScalingRule', $farmRoleScalingRuleReqs);
                    $this->patch('/farm-roles/:farmRoleId/scaling/:scalingRuleName', 'User_FarmRoles:modifyScalingRule', $farmRoleScalingRuleReqs);
                    $this->delete('/farm-roles/:farmRoleId/scaling/:scalingRuleName', 'User_FarmRoles:deleteScalingRule', $farmRoleScalingRuleReqs);
                    $this->get('/farm-roles/:farmRoleId/global-variables', 'User_FarmRoles:describeVariables', $farmRoleRequirements);
                    $this->post('/farm-roles/:farmRoleId/global-variables', 'User_FarmRoles:createVariable', $farmRoleRequirements);
                    $this->get('/farm-roles/:farmRoleId/global-variables/:variableName', 'User_FarmRoles:fetchVariable', $farmRoleVariableReqs);
                    $this->patch('/farm-roles/:farmRoleId/global-variables/:variableName', 'User_FarmRoles:modifyVariable', $farmRoleVariableReqs);
                    $this->delete('/farm-roles/:farmRoleId/global-variables/:variableName', 'User_FarmRoles:deleteVariable', $farmRoleVariableReqs);
                    $this->get('/farm-roles/:farmRoleId/orchestration-rules', 'User_FarmRoleScripts:describe', $farmRoleRequirements);
                    $this->post('/farm-roles/:farmRoleId/orchestration-rules', 'User_FarmRoleScripts:create', $farmRoleRequirements);
                    $this->get('/farm-roles/:farmRoleId/orchestration-rules/:ruleId', 'User_FarmRoleScripts:fetch', $farmRoleScriptReqs);
                    $this->patch('/farm-roles/:farmRoleId/orchestration-rules/:ruleId', 'User_FarmRoleScripts:modify', $farmRoleScriptReqs);
                    $this->delete('/farm-roles/:farmRoleId/orchestration-rules/:ruleId', 'User_FarmRoleScripts:delete', $farmRoleScriptReqs);
                    $this->get('/servers', 'User_Servers:describe');
                    $this->get('/servers/:serverId', 'User_Servers:fetch', $serverRequirements);
                    $this->post('/servers/:serverId/actions/suspend', 'User_Servers:suspend', $serverRequirements);
                    $this->post('/servers/:serverId/actions/terminate', 'User_Servers:terminate', $serverRequirements);
                    $this->post('/servers/:serverId/actions/resume', 'User_Servers:resume', $serverRequirements);
                    $this->post('/servers/:serverId/actions/reboot', 'User_Servers:reboot', $serverRequirements);
                    $this->get('/scaling-metrics', 'User_ScalingMetrics:describe');
                    $this->post('/scaling-metrics', 'User_ScalingMetrics:create');
                    $this->get('/scaling-metrics/:metricName', 'User_ScalingMetrics:fetch', $scalingMetricsReqs);
                    $this->patch('/scaling-metrics/:metricName', 'User_ScalingMetrics:modify', $scalingMetricsReqs);
                    $this->delete('/scaling-metrics/:metricName', 'User_ScalingMetrics:delete', $scalingMetricsReqs);
                    $this->get('/scripts', 'User_Scripts:describe');
                    $this->post('/scripts', 'User_Scripts:create');
                    $this->get('/scripts/:scriptId', 'User_Scripts:fetch', $scriptRequirements);
                    $this->patch('/scripts/:scriptId', 'User_Scripts:modify', $scriptRequirements);
                    $this->delete('/scripts/:scriptId', 'User_Scripts:delete', $scriptRequirements);
                    $this->get('/scripts/:scriptId/script-versions', 'User_ScriptVersions:describe', $scriptRequirements);
                    $this->post('/scripts/:scriptId/script-versions', 'User_ScriptVersions:create', $scriptRequirements);
                    $this->get('/scripts/:scriptId/script-versions/:versionNumber', 'User_ScriptVersions:fetch', $scriptVersionReqs);
                    $this->patch('/scripts/:scriptId/script-versions/:versionNumber', 'User_ScriptVersions:modify', $scriptVersionReqs);
                    $this->delete('/scripts/:scriptId/script-versions/:versionNumber', 'User_ScriptVersions:delete', $scriptVersionReqs);
                    $this->get("/cloud-credentials", 'User_CloudCredentials:describe');
                    $this->post("/cloud-credentials", 'User_CloudCredentials:create');
                    $this->get("/cloud-credentials/:cloudCredentialsId", 'User_CloudCredentials:fetch', $cloudCredsRequirements);
                    $this->patch("/cloud-credentials/:cloudCredentialsId", 'User_CloudCredentials:modify', $cloudCredsRequirements);
                    $this->delete("/cloud-credentials/:cloudCredentialsId", 'User_CloudCredentials:delete', $cloudCredsRequirements);
                    if ($this->getContainer()->config->{"scalr.analytics.enabled"}) {
                        $projectRequirements = ['projectId' => ApiApplication::REGEXP_UUID];
                        $this->get('/cost-centers/', 'User_CostCenters:describe');
                        $this->get('/cost-centers/:ccId', 'User_CostCenters:fetch', $ccRequirements);
                        $this->get('/projects/', 'User_Projects:describe');
                        $this->post('/projects/', 'User_Projects:create');
                        $this->get('/projects/:projectId', 'User_Projects:fetch', $projectRequirements);
                    }
                });
            });
        });
        return $this;
    }

Usage Example

Пример #1
0
<?php

include __DIR__ . '/../src/prepend.inc.php';
use Scalr\Api\Rest\ApiApplication;
ini_set('display_errors', '0');
ini_set('html_errors', '0');
$app = new ApiApplication();
register_shutdown_function(function () use($app) {
    $error = error_get_last();
    if ($error && in_array($error['type'], [E_ERROR, E_PARSE, E_COMPILE_ERROR])) {
        if (!headers_sent()) {
            header("HTTP/1.0 500");
        }
    }
    //Collects access log with processing time
    $accessLogPath = \Scalr::config('scalr.system.monitoring.access_log_path');
    if ($accessLogPath && is_writable($accessLogPath)) {
        @error_log(sprintf("%s,%s,\"%s\",%0.4f,%0.4f,%d\n", date('M d H:i:s P'), $app->response->getStatus(), str_replace('"', '""', $app->request->getMethod() . " " . $app->request->getPath()), $app->response->getHeader('X-Scalr-Inittime'), $app->response->getHeader('X-Scalr-Actiontime'), \Scalr::getDb()->numberQueries + (\Scalr::getContainer()->analytics->enabled ? \Scalr::getContainer()->cadb->numberQueries : 0)), 3, $accessLogPath);
    }
});
$app->setupRoutes()->run();
All Usage Examples Of Scalr\Api\Rest\ApiApplication::setupRoutes