@abstract    Compute Debug CheckSum String from Object Attributes

@param array $input Array of Object Data ($Code => $Value)

@return null|string Unik String Checksum
546145
public static function debugFromArray($input = null)
    {
        //====================================================================//
        // Safety Check
        if (is_null($input) || !self::isValid($input)) {
            return null;
        }
        //====================================================================//
        // return Encoded CheckSum
        return self::getDebug($input);
    }
469944
public function encrypt($input)
    {
        if (! $input) {
            return $input;
        }

        $methods = $this->getEncryptionMethods();
        $method  = reset($methods);
        $mkey    = key($methods);

        if ('mcrypt' == $method) {
            $result = $this->encryptMcrypt($input);
        } elseif ('null' == $method) {
            $result = $input;
        } else {
            $result = $this->encryptOpenSsl($input, $method);
        }

        return ":$mkey:" . base64_encode($result);
    }
1058542
protected function parseTable($input)
    {
        $input = (array) $input;

        return array_map(function ($key, $value) {
            $bytes = ['used_memory', 'free_memory', 'wasted_memory', 'buffer_size'];
            $times = ['start_time', 'last_restart_time'];

            if (in_array($key, $bytes)) {
                $value = number_format($value / 1048576, 2).' MB';
            } elseif (in_array($key, $times)) {
                $value = date('Y-m-d H:i:s', $value);
            }

            return [
                'key'       => $key,
                'value'     => $value,
            ];
        }, array_keys($input), $input);
    }
156010
public function parse($input)
    {
        // define partial regexes
        $iri = '(?:<([^>]*)>)';
        $bnode = '(_:(?:[A-Za-z0-9]+))';
        $plain = '"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"';
        $datatype = "\\^\\^$iri";
        $language = '(?:@([a-z]+(?:-[a-z0-9]+)*))';
        $literal = "(?:$plain(?:$datatype|$language)?)";
        $ws = '[ \\t]';
        $comment = "#.*";

        $subject = "(?:$iri|$bnode)$ws+";
        $property = "$iri$ws+";
        $object = "(?:$iri|$bnode|$literal)";
        $graph = "$ws+(?:$iri|$bnode)";

        // full regexes
        $eoln = '/(?:(\r\n)|[\n\r])/';
        $quadRegex = "/^$ws*$subject$property$object$graph?$ws*.$ws*$/";
        $ignoreRegex = "/^$ws*(?:$comment)?$/";

        // build RDF statements
        $statements = array();

        // split N-Quad input into lines
        $lines = preg_split($eoln, $input);
        $line_number = 0;

        foreach ($lines as $line) {
            $line_number++;

            // skip empty lines
            if (preg_match($ignoreRegex, $line)) {
                continue;
            }

            // parse quad
            if (!preg_match($quadRegex, $line, $match)) {
                throw new InvalidQuadException(
                    sprintf(
                        'Error while parsing N-Quads. Invalid quad in line %d: %s',
                        $line_number,
                        $line
                    ),
                    $line
                );
            }

            // get subject
            if ($match[1] !== '') {
                $subject = new IRI($match[1]);
            } else {
                $subject = new IRI($match[2]);
            }

            // get property
            $property = new IRI($match[3]);

            // get object
            if ($match[4] !== '') {
                $object = new IRI($match[4]);  // IRI
            } elseif ($match[5] !== '') {
                $object = new IRI($match[5]);  // bnode
            } else {
                $unescaped = str_replace(
                    array('\"', '\t', '\n', '\r', '\\\\'),
                    array('"', "\t", "\n", "\r", '\\'),
                    $match[6]
                );

                if (isset($match[7]) && $match[7] !== '') {
                    $object = new TypedValue($unescaped, $match[7]);
                } elseif (isset($match[8]) && $match[8] !== '') {
                    $object = new LanguageTaggedString($unescaped, $match[8]);
                } else {
                    $object = new TypedValue($unescaped, RdfConstants::XSD_STRING);
                }
            }

            // get graph
            $graph = null;
            if (isset($match[9]) && $match[9] !== '') {
                $graph = new IRI($match[9]);
            } elseif (isset($match[10]) && $match[10] !== '') {
                $graph = new IRI($match[10]);
            }

            $quad = new Quad($subject, $property, $object, $graph);

            // TODO Make sure that quads are unique??
            $statements[] = $quad;
        }

        return $statements;
    }
282239
private function arrayAnalyzer($input)
    {
        $result = [];
        foreach ($input as $key => $value) {
            if ($key == 'Field') {
                $result[] = $value;
            } elseif ($key == 'Type') {
                if (str_contains($value, 'int')) {
                    $result[] = 'text';
                } elseif (str_contains($value, 'char')) {
                    $result[] = 'text';
                } elseif ($value = 'date') {
                    $result[] = 'date';
                }
            }
        }

        return $result;
    }
730190
public function compile($input)
    {
        if (strlen($input) == 0) {
            return null;
        }
        try {
            $buffer = new Buffer();
            $this->parse($input)->compile($buffer);
            $code = $buffer->getResult();
            return $code;
        } catch (\UnexpectedValueException $e) {
            throw new \UnexpectedValueException('Error while compiling input: ' . Util::toPhp($input), 0, $e);
        }
    }
900825
protected function parseType(array $input)
    {
        /** @var string $type */
        /** @var string[] $types */
        extract($input);
        switch ($type) {
            case 'array':
                if (!is_array($this->{$key}))
                    return false;
                break;
            case 'int':
            case 'integer':
                if (!is_int($this->{$key}))
                    return false;
                break;
            case 'or':
                $valid = false;
                foreach ($types as $_type) {
                    if (gettype($this->{$key}) == $_type) {
                        $valid = true;
                        break;
                    }
                }
                if (!$valid) return false;
                break;
            default:
                //throw new Exception('Incorrect rule');
                return null;
        }
        return true;
    }
479049
protected static function utf8_to_codepoints($input) {
		$codepoints = array();

		// Get number of bytes
		$strlen = strlen($input);

		for ($position = 0; $position < $strlen; $position++) {
			$value = ord($input[$position]);

			// One byte sequence:
			if ((~$value & 0x80) === 0x80) {
				$character = $value;
				$length = 1;
				$remaining = 0;
			}
			// Two byte sequence:
			elseif (($value & 0xE0) === 0xC0) {
				$character = ($value & 0x1F) << 6;
				$length = 2;
				$remaining = 1;
			}
			// Three byte sequence:
			elseif (($value & 0xF0) === 0xE0) {
				$character = ($value & 0x0F) << 12;
				$length = 3;
				$remaining = 2;
			}
			// Four byte sequence:
			elseif (($value & 0xF8) === 0xF0) {
				$character = ($value & 0x07) << 18;
				$length = 4;
				$remaining = 3;
			}
			// Invalid byte:
			else {
				throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $value);
			}

			if ($remaining > 0) {
				if ($position + $length > $strlen) {
					throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
				}
				for ($position++; $remaining > 0; $position++) {
					$value = ord($input[$position]);

					// If it is invalid, count the sequence as invalid and reprocess the current byte:
					if (($value & 0xC0) !== 0x80) {
						throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
					}

					$character |= ($value & 0x3F) << (--$remaining * 6);
				}
				$position--;
			}

			if (
				// Non-shortest form sequences are invalid
				   $length > 1 && $character <= 0x7F
				|| $length > 2 && $character <= 0x7FF
				|| $length > 3 && $character <= 0xFFFF
				// Outside of range of ucschar codepoints
				// Noncharacters
				|| ($character & 0xFFFE) === 0xFFFE
				|| $character >= 0xFDD0 && $character <= 0xFDEF
				|| (
					// Everything else not in ucschar
					   $character > 0xD7FF && $character < 0xF900
					|| $character < 0x20
					|| $character > 0x7E && $character < 0xA0
					|| $character > 0xEFFFD
				)
			) {
				throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
			}

			$codepoints[] = $character;
		}

		return $codepoints;
	}
1109229
public function verifySalt($input)
    {
        $appearsValid = (1 === preg_match('/^_[\.\/0-9A-Za-z]{8}$/', $input));
        if ($appearsValid) {
            $costFactor = $this->_decodeInt24(substr($input, 1, 4));
            if ($costFactor < 1 || $costFactor > (1 << 24) - 1) {
                $appearsValid = false;
            }
        }

        return $appearsValid;
    }
604554
public function decrypt($input)
    {
        if (! $input) {
            return $input;
        }

        $methods = $this->getEncryptionMethods();
        if (':' == $input[0]) {
            list($empty, $mkey, $base64) = explode(':', $input, 3);

            if (! isset($methods[$mkey])) {
                $error = sprintf("Encryption method '%s' not defined in projec.ini.", $mkey);
                throw new \Gems_Exception_Coding($error);
            }

            $method = $methods[$mkey];
        } else {
            $mkey   = 'mcrypt';
            $base64 = $input;
            $method = $mkey;
        }

        $decoded = base64_decode($base64);
        if ('mcrypt' == $method) {
            $output = $this->decryptMcrypt($decoded);
        } elseif ('null' == $method) {
            $output = $base64;
        } else {
            $output = $this->decryptOpenSsl($decoded, $method);
        }

        if (false === $output) {
            return $input;
        } else {
            return $output;
        }
    }
563541
private static function ucs4_ucs4array($input)
    {
        $output = array();

        $inp_len = strlen($input);
        // Input length must be dividable by 4
        if ($inp_len % 4) {
            throw new Exception('Input UCS4 string is broken');
        }
        // Empty input - return empty output
        if (!$inp_len) return $output;

        for ($i = 0, $out_len = -1; $i < $inp_len; ++$i) {
            if (!($i % 4)) { // Increment output position every 4 input bytes
                $out_len++;
                $output[$out_len] = 0;
            }
            $output[$out_len] += ord($input{$i}) << (8 * (3 - ($i % 4) ) );
        }
        return $output;
    }
274002
protected function parseRange($input): ?array
    {
        if ($input === null || $input === '*' || $input === '*.*.*.*'
            || $input === '0.0.0.0-255.255.255.255'
        ) {
            return null;
        }

        $range = ['min' => null, 'max' => null, 'mask' => null];

        if (strpos($input, '-') !== false) {
            [$range['min'], $range['max']] = explode('-', $input);
        } elseif (strpos($input, '*') !== false) {
            $this->parseRangeUsingWildcards($input, $range);
        } elseif (strpos($input, '/') !== false) {
            $this->parseRangeUsingCidr($input, $range);
        } else {
            throw new ComponentException('Invalid network range');
        }

        if (!$this->verifyAddress($range['min'])) {
            throw new ComponentException('Invalid network range');
        }

        if (isset($range['max']) && !$this->verifyAddress($range['max'])) {
            throw new ComponentException('Invalid network range');
        }

        return $range;
    }
220765
public function dump($input)
    {

        foreach ($this->lex($input) as $token) {

            $type = $token['type'];
            $line = $token['line'];
            $offset = $token['offset'];
            unset($token['type'], $token['line'], $token['offset']);

            echo "[$type($line:$offset)";
            $vals = implode(', ', array_map(function ($key, $value) {

                return "$key=$value";
            }, array_keys($token), $token));

            if (!empty($vals))
                echo " $vals";

            echo ']';

            if ($type === 'newLine')
                echo "\n";
        }
    }
538165
protected function _decodePart($input)
    {
        $n = static::INITIAL_N;
        $i = 0;
        $bias = static::INITIAL_BIAS;
        $output = '';

        $pos = strrpos($input, static::DELIMITER);
        if ($pos !== false) {
            $output = substr($input, 0, $pos++);
        } else {
            $pos = 0;
        }

        $outputLength = strlen($output);
        $inputLength = strlen($input);

        /* Punycode lookup is case-insensitive. */
        $input = Horde_String::lower($input);

        while ($pos < $inputLength) {
            $oldi = $i;
            $w = 1;

            for ($k = static::BASE; ; $k += static::BASE) {
                $digit = static::$_decodeTable[$input[$pos++]];
                $i = $i + ($digit * $w);
                $t = $this->_calculateThreshold($k, $bias);

                if ($digit < $t) {
                    break;
                }

                $w = $w * (static::BASE - $t);
            }

            $bias = $this->_adapt($i - $oldi, ++$outputLength, ($oldi === 0));
            $n = $n + (int) ($i / $outputLength);
            $i = $i % ($outputLength);

            $output = Horde_String::substr($output, 0, $i, 'UTF-8') .
                $this->_codePointToChar($n) .
                Horde_String::substr($output, $i, $outputLength - 1, 'UTF-8');

            ++$i;
        }

        return $output;
    }
198675
public static function readMessage($input)
    {
        $line = fgets($input);
        $values = explode(':', $line);
        if (count($values) !== 2 || trim($values[0]) !== self::CONTENT_LENGTH) {
            return null;
        }
        $length = intval(trim($values[1]));

        // read one empty line.
        while (trim(fgets($input)) !== '') {}

        $json = fread($input, $length);
        return Common::decode($json);
    }
1255207
private function utf8_ucs4array($input)
    {
        $startByte = 0;
        $nextByte = 0;

        $output = [];
        $outputLength = 0;
        $inputLength = $this->byteLength($input);
        $mode = 'next';
        $test = 'none';
        for ($k = 0; $k < $inputLength; ++$k) {
            $v = ord($input{$k}); // Extract byte from input string

            if ($v < 128) { // We found an ASCII char - put into string as is
                $output[$outputLength] = $v;
                ++$outputLength;
                if ('add' === $mode) {
                    if ($this->safeMode) {
                        $output[$outputLength - 2] = $this->safeCodepoint;
                        $mode = 'next';
                    } else {
                        throw new InvalidCharacterException(
                            sprintf(
                                'Conversion from UTF-8 to UCS-4 failed: malformed input at byte %d',
                                $k
                            ),
                            302
                        );
                    }
                }

                continue;
            }

            if ('next' === $mode) { // Try to find the next start byte; determine the width of the Unicode char
                $startByte = $v;
                $mode = 'add';
                $test = 'range';
                if ($v >> 5 === 6) { // &110xxxxx 10xxxxx
                    $nextByte = 0; // How many times subsequent bit masks must rotate 6bits to the left
                    $v = ($v - 192) << 6;
                } elseif ($v >> 4 === 14) { // &1110xxxx 10xxxxxx 10xxxxxx
                    $nextByte = 1;
                    $v = ($v - 224) << 12;
                } elseif ($v >> 3 === 30) { // &11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
                    $nextByte = 2;
                    $v = ($v - 240) << 18;
                } elseif ($this->safeMode) {
                    $mode = 'next';
                    $output[$outputLength] = $this->safeCodepoint;
                    ++$outputLength;

                    continue;
                } else {
                    throw new InvalidCharacterException(
                        sprintf('This might be UTF-8, but I don\'t understand it at byte %d', $k),
                        303
                    );
                }
                if (($inputLength - $k - $nextByte) < 2) {
                    $output[$outputLength] = $this->safeCodepoint;
                    $mode = 'no';

                    continue;
                }

                if ('add' === $mode) {
                    $output[$outputLength] = (int)$v;
                    ++$outputLength;

                    continue;
                }
            }
            if ('add' == $mode) {
                if (!$this->safeMode && $test === 'range') {
                    $test = 'none';
                    if (($v < 0xA0 && $startByte === 0xE0)
                        || ($v < 0x90 && $startByte === 0xF0)
                        || ($v > 0x8F && $startByte === 0xF4)
                    ) {
                        throw new InvalidCharacterException(
                            sprintf('Bogus UTF-8 character (out of legal range) at byte %d', $k),
                            304
                        );
                    }
                }
                if ($v >> 6 === 2) { // Bit mask must be 10xxxxxx
                    $v = ($v - 128) << ($nextByte * 6);
                    $output[($outputLength - 1)] += $v;
                    --$nextByte;
                } else {
                    if ($this->safeMode) {
                        $output[$outputLength - 1] = ord($this->safeCodepoint);
                        $k--;
                        $mode = 'next';

                        continue;
                    } else {
                        throw new InvalidCharacterException(
                            sprintf('Conversion from UTF-8 to UCS-4 failed: malformed input at byte %d', $k),
                            302
                        );
                    }
                }
                if ($nextByte < 0) {
                    $mode = 'next';
                }
            }
        } // for

        return $output;
    }
618336
public function decode($input)
    {
        // Don't use UCS-2.
        $output = [];
        $inputLength = strlen($input);
        $i = 0;
        $n = self::INITIAL_N;
        $bias = self::INITIAL_BIAS;

        // Handle the basic code points: let `basic` be the number of input code
        // points before the last delimiter, or `0` if there is none, then copy
        // the first basic code points to the output.

        $basic = strrpos($input, self::DELIMITER);
        if ($basic === false ) {
            $basic = 0;
        }

        for ($j = 0; $j < $basic; ++$j) {
            // if it's not a basic code point
            if ( ord($input[$j]) >= 0x80) {
                $this->error('not-basic');
            }
            $output[] = ord($input[$j]);
        }

        // Main decoding loop: start just after the last delimiter if any basic code
        // points were copied; start at the beginning otherwise.

        for ( $index = $basic > 0 ? $basic + 1 : 0; $index < $inputLength; /* no final expression */) {

            // `index` is the index of the next character to be consumed.
            // Decode a generalized variable-$length integer into `delta`,
            // which gets added to `i`. The overflow checking is easier
            // if we increase `i` as we go, then subtract off its starting
            // value at the end to obtain `delta`.
            $oldi = $i;
            for ( $w = 1, $k = self::BASE; /* no condition */; $k += self::BASE) {

                if ($index >= $inputLength) {
                    $this->error('invalid-input');
                }

                $digit = $this->basicToDigit(ord($input[$index++]));

                if ($digit >= self::BASE || $digit > floor((self::MAX_INT - $i) / $w)) {
                    $this->error('overflow');
                }

                $i += $digit * $w;
                $t = $k <= $bias ? self::T_MIN : ($k >= $bias + self::T_MAX ? self::T_MAX : $k - $bias);

                if ($digit < $t) {
                    break;
                }

                $baseMinusT = self::BASE - $t;
                if ($w > floor(self::MAX_INT / $baseMinusT)) {
                    $this->error('overflow');
                }

                $w *= $baseMinusT;

            }

            $out = count($output) + 1;
            $bias = $this->adapt($i - $oldi, $out, $oldi == 0);

            // `i` was supposed to wrap around from `out` to `0`,
            // incrementing `n` each time, so we'll fix that now:
            if (floor($i / $out) > self::MAX_INT - $n) {
                $this->error('overflow');
            }

            $n += floor($i / $out);
            $i %= $out;

            // Insert `n` at position `i` of the output.
            array_splice($output, $i++, 0, $n);
        }

        return mb_convert_encoding($this->ucs2Encode($output), "UTF-8", "UTF-16");
    }