public function _scope($from, $to, $action)
{
switch ($action) {
case static::ACT_CONVERT_TO_OBJECT:
/* @var $from Script */
$to->scope = $from->getScope();
break;
case static::ACT_CONVERT_TO_ENTITY:
/* @var $to Script */
switch ($from->scope) {
case ScopeInterface::SCOPE_SCALR:
$to->accountId = null;
$to->envId = null;
break;
case ScopeInterface::SCOPE_ACCOUNT:
$to->accountId = $this->controller->getUser()->getAccountId();
$to->envId = null;
break;
case ScopeInterface::SCOPE_ENVIRONMENT:
$to->accountId = $this->controller->getUser()->getAccountId();
$to->envId = $this->controller->getEnvironment()->id;
break;
default:
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Unexpected scope value");
}
break;
case static::ACT_GET_FILTER_CRITERIA:
if (empty($from->scope)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed scope value");
}
switch ($from->scope) {
case ScopeInterface::SCOPE_SCALR:
return [['accountId' => null], ['envId' => null]];
case ScopeInterface::SCOPE_ENVIRONMENT:
return [['accountId' => $this->controller->getUser()->getAccountId()], ['envId' => $this->controller->getEnvironment()->id]];
case ScopeInterface::SCOPE_ACCOUNT:
return [['accountId' => $this->controller->getUser()->getAccountId()], ['envId' => null]];
default:
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Unexpected scope value");
}
break;
}
}