/** * Scalr-Evironment middleware handler * * It extracts :environment group parameter from the route * and sets application setting * * @param Route $route A route * @throws ApiErrorException */ public function handleEnvironment($route) { $params = $route->getParams(); if (!is_numeric($params['environment']) || $params['environment'] <= 0) { throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Environment has not been provided with the request"); } $this->settings[self::SETTING_SCALR_ENVIRONMENT] = (int) $params['environment']; unset($params['environment']); $route->setParams($params); }
/** * ApiVersion middleware handler * * It extracts :apiversion group parameter from the route * and sets application setting * * @param Route $route A route */ public function handleApiVersion($route) { $params = $route->getParams(); if (!is_numeric($params['apiversion'])) { $this->halt(400, 'Invalid API version'); } $this->settings[self::SETTING_API_VERSION] = (int) $params['apiversion']; unset($params['apiversion']); $route->setParams($params); }