Serialize, compress and encode the entire form including it's values

@param boolean $blnSubmittedValues
Whether or not to include submitted values or only serialize default values.
@return String Base64 encoded, gzcompressed, serialized form.
776514
public function serialize($blnSubmittedValues = true)
    {
        // Validate & cache all values
        $this->valuesAsHtml($blnSubmittedValues); // Especially dynamic counters need this!

        return base64_encode(gzcompress(serialize($this)));
    }
317733
public function serialize()
    {
        $serialized = serialize([$this->_options, $this->_auth]);

        // encode data (optionally attempt to zip)
        if (function_exists('gzencode') && isset($this->_options['serialzip']) && $this->_options['serialzip']) {
            $encoded = self::GZIP_SERIAL_PREFIX . gzencode($serialized);
        } else {
            $encoded = self::BASE64_SERIAL_PREFIX . base64_encode($serialized);
        }
        return $encoded;
    }
445220
public function postProcessFormValues(array $formValues)
    {
        $driver = $formValues['gitDriver'];
        $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
            'Lightwerk.SurfCaptain.sources.default.driver', $driver);
        // reset
        $this->distributionSettings['Lightwerk']['SurfCaptain']['sources']['default']['mapping'] = [];
        switch ($driver) {
            case 'GitHub':
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Repository.repositoryUrl', '{{ssh_url}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Repository.webUrl', '{{url}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Commit.id', '{{sha}}');
                break;
            case 'GitLab':
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Repository.repositoryUrl', '{{ssh_url_to_repo}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Commit.date', '{{committed_date}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Commit.committerName', '{{committer.name}}');
                break;
            case 'BitBucket':
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Repository.webUrl', '{{links.html.href}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Repository.repositoryUrl', '{{links.clone.1.href}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Branch.name', '{{branch}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Branch.commit.id', '{{raw_node}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Branch.commit.committerName', '{{author}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Branch.commit.date', '{{timestamp}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Branch.commit.message', '{{message}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Tag.name', '{{_KEY_}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Tag.commit.id', '{{raw_node}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Tag.commit.committerName', '{{author}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Tag.commit.date', '{{timestamp}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Tag.commit.message', '{{message}}');
                break;
            default:
                throw new SetupException('unknown driver ' . $driver, 1427623122);
        }
        $this->configurationSource->save(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS,
            $this->distributionSettings);
    }
373218
public function base64Decode(string $base64Encoded): string
    {
        if ($remainder = strlen($base64Encoded) % 4) {
            $base64Encoded .= str_repeat('=', 4 - $remainder);
        }

        return base64_decode(strtr($base64Encoded, '-_', '+/'));
    }
379072
private static function encodeValue($value)
    {
        $value = gmp_strval($value);

        return Base64Url::encode(self::convertDecToBin($value));
    }
449912
public function base64Encode(string $base64Decoded): string
    {
        $base64Decoded = base64_encode($base64Decoded);
        $base64Decoded = rtrim(strtr($base64Decoded, '-_', '+/'), '=');

        return $base64Decoded;
    }
1234531
public function form_submit($params) {
        if (!isset($params['field'])) {
            throw new \UnexpectedValueException("The field parameter is required.");
        }
        $value = isset($params['value']) ? $params['value'] : null;
        $attributes = isset($params['attrs']) ? $params['attrs'] : array();
        return Form::submit($params['field'], $value, $attributes);
    }
895871
public function encode()
    {
        $mimeType = Resources::MULTIPART_MIXED_TYPE;
        $batchGuid = Utilities::getGuid();
        $batchId = sprintf('batch_%s', $batchGuid);
        $contentType1 = ['content_type' => "$mimeType"];
        $changeSetGuid = Utilities::getGuid();
        $changeSetId = sprintf('changeset_%s', $changeSetGuid);
        $contentType2 = ['content_type' => "$mimeType; boundary=$changeSetId"];
        $options = [
            'encoding' => 'binary',
            'content_type' => Resources::HTTP_TYPE,
        ];

        // Create changeset MIME part
        $changeSet = new Mail_mimePart();

        $i = 1;
        foreach ($this->_contexts as $context) {
            $context->addHeader(Resources::CONTENT_ID, $i);
            $changeSet->addSubpart((string) $context, $options);

            ++$i;
        }

        // Encode the changeset MIME part
        $changeSetEncoded = $changeSet->encode($changeSetId);

        // Create the batch MIME part
        $batch = new Mail_mimePart(Resources::EMPTY_STRING, $contentType1);

        // Add changeset encoded to batch MIME part
        $batch->addSubpart($changeSetEncoded['body'], $contentType2);

        // Encode batch MIME part
        $batchEncoded = $batch->encode($batchId);

        $this->_headers = $batchEncoded['headers'];
        $this->_body = $batchEncoded['body'];
    }
846105
public static function varDump($blnDisplayOutput = true)
    {
        $strToReturn = '';
        foreach (static::$objTimerArray as $objTimer) {
            $strToReturn .= $objTimer->__toString() . "\n";
        }
        if ($blnDisplayOutput) {
            echo nl2br($strToReturn);
            return '';
        } else {
            return $strToReturn;
        }
    }
666297
public function exportValue(&$submitvalues, $notused = false) {
        global $COURSE;

        // Get the values from all the child elements.
        $vals = array();
        foreach ($this->_elements as $element) {
            $thisexport = $element->exportValue($submitvalues[$this->getName()], true);
            if (!is_null($thisexport)) {
                $vals += $thisexport;
            }
        }

        $type = (isset($vals['modgrade_type'])) ? $vals['modgrade_type'] : 'none';
        $point = (isset($vals['modgrade_point'])) ? $vals['modgrade_point'] : null;
        $scale = (isset($vals['modgrade_scale'])) ? $vals['modgrade_scale'] : null;
        $rescalegrades = (isset($vals['modgrade_rescalegrades'])) ? $vals['modgrade_rescalegrades'] : null;

        $return = $this->process_value($type, $scale, $point, $rescalegrades);
        return array($this->getName() => $return, $this->getName() . '_rescalegrades' => $rescalegrades);
    }
1039733
protected function encode($dump)
    {
        foreach ($this->getDumpEncoders() as $encoder) {
            $dump = $encoder->encode($dump);
        }

        return $dump;
    }
891395
function exportValue(&$submitValues, $assoc = false)
    {
        if ('submit' == $this->getAttribute('type')) {
            return $this->_prepareValue($this->_findValue($submitValues), $assoc);
        } else {
            return null;
        }
    }
156550
public function toHtml($submitted = false, $blnSimpleLayout = false, $blnLabel = true, $blnDisplayErrors = true)
    {
        $blnError = ($submitted && ! $this->__validator->validate() && $blnDisplayErrors) ? true : false;

        if (! $blnSimpleLayout) {
            // *** We asume that all dynamic fields greater than 0 are never required.
            if ($this->__validator->getRequired()) {
                $this->setMeta("class", "vf__required");
            } else {
                $this->setMeta("class", "vf__optional");
            }

            if ($blnError) {
                $this->setMeta("class", "vf__error");
            }

            if (! $blnLabel) {
                $this->setMeta("class", "vf__nolabel");
            }

            // Call this right before __getMetaString();
            $this->setConditionalMeta();

            $strOutput = "<div{$this->__getMetaString()}>\n";

            if ($blnError) {
                $strOutput .= "<p class=\"vf__error\">{$this->__validator->getError()}</p>";
            }

            if ($this->__getValue($submitted)) {
                // *** Add the "checked" attribute to the input field.
                $this->setFieldMeta("checked", "checked");
            } else {
                // *** Remove the "checked" attribute from the input field. Just to be sure it wasn't set before.
                $this->setFieldMeta("checked", null, true);
            }

            if ($blnLabel) {
                $strLabel = (! empty($this->__requiredstyle) && $this->__validator->getRequired()) ? sprintf($this->__requiredstyle, $this->__label) : $this->__label;
                if (! empty($this->__label)) {
                    $strOutput .= "<label for=\"{$this->__id}\"{$this->__getLabelMetaString()}>{$strLabel}</label>\n";
                }
            }
        } else {
            if ($blnError) {
                $this->setMeta("class", "vf__error");
            }

            $this->setMeta("class", "vf__multifielditem");

            // Call this right before __getMetaString();
            $this->setConditionalMeta();

            $strOutput = "<div{$this->__getMetaString()}>\n";

            if ($this->__getValue($submitted)) {
                // *** Add the "checked" attribute to the input field.
                $this->setFieldMeta("checked", "checked");
            } else {
                // *** Remove the "checked" attribute from the input field. Just to be sure it wasn't set before.
                $this->setFieldMeta("checked", null, true);
            }
        }

        $strOutput .= "<input type=\"checkbox\" name=\"{$this->__name}\" id=\"{$this->__id}\"{$this->__getFieldMetaString()}/>\n";

        if (! empty($this->__tip)) {
            $strOutput .= "<small class=\"vf__tip\"{$this->__getTipMetaString()}>{$this->__tip}</small>\n";
        }

        $strOutput .= "</div>\n";

        return $strOutput;
    }
661450
protected function unserialize($source)
    {
        $source = base64_decode($source);
        $result = @unserialize($source);
        if ($result === false && $source !== serialize(false)) {
            throw new \UnexpectedValueException();
        }
        return $result;
    }
1366695
protected function compress(){
		switch($this->compress){
			case self::COMPRESS_GZIP:
				$this->payload = gzdeflate($this->payload);
				break;
			case self::COMPRESS_BZIP:
				$this->payload = bzcompress($this->payload);
				break;
			case self::COMPRESS_LZF:
				$this->payload = lzf_compress($this->payload);
				break;
			case self::COMPRESS_OFF:
			default:
				//anything but known values result in OFF
				break;
		}
		return true;
	}
445906
protected function encodeValues(&$values)
    {
        if (is_array($values)) {
            foreach ($values as &$value) {
                $value = $this->encodeValues($value);
            }
        } elseif (is_float($values)) {
            $values = Common::forceDotAsSeparatorForDecimalPoint($values);
        } elseif (is_string($values)) {
            $values = htmlentities($values, ENT_COMPAT, 'UTF-8');
            $values = str_replace('$', '&#36;', $values);
        }
        return $values;
    }
301453
private function formatValues()
    {
        array_walk($this->parameters, function (&$value, $key) {
            $parameterValue = $value;

            if (is_bool($parameterValue)) {
                $parameterValue = var_export($parameterValue, true);
            }

            $formattedValue = sprintf(self::DEFAULT_PAIR_FORMAT, $key, $parameterValue);

            if (isset($this->pairFormats[$key])) {
                $formattedValue = sprintf($this->pairFormats[$key], $key, $parameterValue);
            }

            $value = $formattedValue;
        });
    }