Scalr\Farm\Role\FarmRoleStorage::setConfigs PHP Method

setConfigs() public method

Save storage configs
public setConfigs ( array $configs, boolean $validate = true )
$configs array Array of storage config
$validate boolean optional If true validate config before save
    public function setConfigs($configs, $validate = true)
    {
        $configs = is_array($configs) ? $configs : [];
        $ephemeralEc2 = [];
        $ephemeralGce = [];
        foreach ($configs as $value) {
            if (!is_array($value) || !is_array($value['settings'])) {
                continue;
            }
            $object = new FarmRoleStorageConfig($this->farmRole);
            $object->apply($value);
            if ($validate) {
                $r = $object->validate();
                if ($r !== true) {
                    throw new FarmRoleStorageException($r);
                }
            }
            $config = new FarmRoleStorageConfig($this->farmRole);
            $config->create($object);
            if ($config->type == FarmRoleStorageConfig::TYPE_EC2_EPHEMERAL) {
                $ephemeralEc2[$config->settings[FarmRoleStorageConfig::SETTING_EC2_EPHEMERAL_NAME]] = $config->id;
            } else {
                if ($config->type == FarmRoleStorageConfig::TYPE_GCE_EPHEMERAL) {
                    $ephemeralGce[$config->settings[FarmRoleStorageConfig::SETTING_GCE_EPHEMERAL_NAME]] = $config->id;
                }
            }
        }
        // validate ephemeral configs
        foreach (self::getConfigs() as $config) {
            if ($config->type == FarmRoleStorageConfig::TYPE_EC2_EPHEMERAL) {
                $name = $config->settings[FarmRoleStorageConfig::SETTING_EC2_EPHEMERAL_NAME];
                if (!isset($ephemeralEc2[$name]) || $ephemeralEc2[$name] != $config->id) {
                    $config->delete();
                }
            } else {
                if ($config->type == FarmRoleStorageConfig::TYPE_GCE_EPHEMERAL) {
                    $name = $config->settings[FarmRoleStorageConfig::SETTING_GCE_EPHEMERAL_NAME];
                    if (!isset($ephemeralGce[$name]) || $ephemeralGce[$name] != $config->id) {
                        $config->delete();
                    }
                }
            }
        }
    }