Scalr\Api\Service\User\V1beta0\Adapter\RoleAdapter::_builtinAutomation PHP Method

_builtinAutomation() protected method

protected _builtinAutomation ( $from, $to, $action )
    protected function _builtinAutomation($from, $to, $action)
    {
        switch ($action) {
            case static::ACT_CONVERT_TO_OBJECT:
                /* @var $from Role */
                if ($from->isScalarized) {
                    $to->builtinAutomation = static::behaviorsToData($from->getBehaviors());
                }
                break;
            case static::ACT_CONVERT_TO_ENTITY:
                /* @var $to Role */
                if (!is_array($from->builtinAutomation)) {
                    throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Property builtinAutomation must be an array");
                }
                $behaviors = array_unique($from->builtinAutomation);
                if (count($behaviors) != count($from->builtinAutomation)) {
                    throw new ApiErrorException(409, ErrorMessage::ERR_UNICITY_VIOLATION, "Builtin automation list contains duplicates");
                }
                $behaviors = static::behaviorsToEntity($behaviors);
                $conflicts = Role::getBehaviorsConflicts($behaviors);
                if (!empty($conflicts)) {
                    throw new ApiErrorException(409, ErrorMessage::ERR_UNICITY_VIOLATION, sprintf("The following behaviors can not be combined: [%s]", implode(', ', static::behaviorsToData($conflicts))));
                }
                $to->setBehaviors($behaviors);
                break;
            case static::ACT_GET_FILTER_CRITERIA:
                return [['behaviors' => ['$regex' => implode('|', static::behaviorsToEntity((array) $from->builtinAutomation, false))]]];
        }
    }