Helper function to parse a parameters-like tokenized array.

@param mixed $data  Message data. Either a Horde_Imap_Client_Tokenize
object or null.

@return array  The parameter array.
164507
protected function _parseStructureParams($data)
    {
        $params = array();

        if (is_null($data)) {
            return $params;
        }

        while (($name = $data->next()) !== false) {
            $params[Horde_String::lower($name)] = $data->next();
        }

        $cp = new Horde_Mime_Headers_ContentParam('Unused', $params);

        return $cp->params;
    }
50817
private function parseSockData($data)
    {
        $return = [];

        $lines = (array) explode("\n", trim($data));

        foreach ($lines as $line) {
            if (preg_match('/(\w+)\s*:\s*([-+]?[\d\.]+)/i', $line, $match) == 1) {
                $return[] = array(
                    'path' => 'N/A',
                    'name' => $match[1],
                    'temp' => $match[2],
                    'unit' => '', // TODO
                );
            }
        }

        return $return;
    }
675111
protected function parseGroup($data)
    {
        $set = $this->_parseDataItemToKeys($data);
        return empty($set) ? '' : 'GROUP BY ' . implode(',', array_unique($set));
    }
412507
public static function parseArray(array $data)
    {
        $type = strtoupper($data['data_type']);
        if (!defined(static::class . '::' . $type))
            throw new InvalidValueException("Invalid column type: $type");
            
        return array(
            'name' => $data['column_name'],
            'type' => $type,
            'max_length' => $data['character_maximum_length'] ?? null,
            'is_nullable' => isset($data['is_nullable']) ? $data['is_nullable'] == true : false,
            'column_default' => $data['column_default'] ?? null,
            'numeric_precision' => $data['numeric_precision'] ?? null,
            'numeric_scale' => $data['numeric_scale'] ?? null,
            'serial' => isset($data['serial']) ? $data['serial'] == true : false,
            'enum_values' => $data['enum_values'] ?? null
        );
    }
415072
private function parseIniString($data)
    {
        $config = $this->arr();
        $data = parse_ini_string($data, true);
        foreach ($data as $section => $value) {
            $config = $config->mergeRecursive($this->processValue($section, $value));
        }

        return $config;
    }
3999
protected function _parseLanguage(Horde_Imap_Client_Tokenize $data)
    {
        $lang_list = $data->flushIterator();

        if (count($lang_list) === 1) {
            // This is the language that was set.
            $this->_setInit('lang', reset($lang_list));
        } else {
            // These are the languages that are available.
            $this->_setInit('langavail', $lang_list);
        }
    }
977828
private static function decode($data) {
		if((is_array($data) && isset($data[0])) || (isset($data[0]) && !is_string($data[0]))) {
			return self::parseArray($data);
		} else if (is_null($data) || is_scalar($data)) {
			return $data;
		} else {
			return self::decodeNewObject($data);
		}
	}
1120188
protected function parseDataForModelFindParams($data)
    {
        if ( ! is_array($data) || ! isset($data['id']) || empty($data['id'])) {
            return false;
        }

        return intval($data['id']);
    }
1245085
protected function _parseID(
        Horde_Imap_Client_Interaction_Pipeline $pipeline,
        Horde_Imap_Client_Tokenize $data
    )
    {
        if (!isset($pipeline->data['id'])) {
            $pipeline->data['id'] = array();
        }

        if (!is_null($data->next())) {
            while (($curr = $data->next()) !== false) {
                if (!is_null($id = $data->next())) {
                    $pipeline->data['id'][$curr] = $id;
                }
            }
        }
    }
1111667
public static function normalize($data)
    {
        $result = [];

        foreach ($data as $key => $value) {
            if (!is_int($key)) {
                $result[$key] = $value;
                continue;
            }
            if (!is_scalar($value)) {
                throw new Exception("Invalid array format, a value can't be normalized");
            }
            $result[$value] = null;
        }
        return $result;
    }
92273
private function convertSerializedToArray($data)
    {
        $data = @unserialize($data);

        // Maybe the response was a serialized JSON string
        // So let's try to convert that to an array...
        if (is_string($data))
        {
            return $this->convertJsonToArray($data);
        }

        // It could be an object or an array of object
        // but we want a associative array, so use
        // JSON to encode it and then decode it properly...
        if ((is_object($data) or is_array($data)) and $json = $this->convertToJson($data))
        {
            return $this->convertJsonToArray($json);
        }

        return null;
    }
535982
public static function fromArray(array $data)
    {
        $result = '';
        foreach ($data as $name => $value) {
            $value = StringHelper::toString($value, "'", Serialize::SERIALIZE_JSON);
            $result .= "$name=$value; ";
        }

        return $result === '' ? null : rtrim($result);
    }
405455
public function parse($data) {
    $info = [];

    if (preg_match_all('
      @^\s*                           # Start at the beginning of a line, ignoring leading whitespace
      ((?:
        [^=;\[\]]|                    # Key names cannot contain equal signs, semi-colons or square brackets,
        \[[^\[\]]*\]                  # unless they are balanced and not nested
      )+?)
      \s*=\s*                         # Key/value pairs are separated by equal signs (ignoring white-space)
      (?:
        ("(?:[^"]|(?<=\\\\)")*")|     # Double-quoted string, which may contain slash-escaped quotes/slashes
        (\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes
        ([^\r\n]*?)                   # Non-quoted string
      )\s*$                           # Stop at the next end of a line, ignoring trailing whitespace
      @msx', $data, $matches, PREG_SET_ORDER)) {
      foreach ($matches as $match) {
        // Fetch the key and value string.
        $i = 0;
        foreach (['key', 'value1', 'value2', 'value3'] as $var) {
          $$var = isset($match[++$i]) ? $match[$i] : '';
        }

        if (isset($key) && isset($value1) && isset($value2) && isset($value3)) {
          $value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3;

          // Parse array syntax.
          $keys = preg_split('/\]?\[/', rtrim($key, ']'));
          $last = array_pop($keys);
          $parent = &$info;

          // Create nested arrays.
          foreach ($keys as $key) {
            if ($key == '') {
              $key = count($parent);
            }
            if (!isset($parent[$key]) || !is_array($parent[$key])) {
              $parent[$key] = [];
            }
            $parent = &$parent[$key];
          }

          // Handle PHP constants.
          if (preg_match('/^\w+$/i', $value) && defined($value)) {
            $value = constant($value);
          }

          // Insert actual value.
          if ($last == '') {
            $last = count($parent);
          }
          $parent[$last] = $value;
        }
      }
    }

    return $info;
  }
925758
protected function parseData(array $data)
    {
        $this->files = [];

        foreach ($data as $key => $value) {
            // If this value is an instance of the HttpFoundation File class we will
            // remove it from the data array and add it to the files array, which
            // we use to conveniently separate out these files from other data.
            if (in_array($value, $_FILES, true)) {
                $this->files[$key] = $value;

                unset($data[$key]);
            }
        }

        return $data;
    }
350011
protected function _parseACL(
        Horde_Imap_Client_Interaction_Pipeline $pipeline,
        Horde_Imap_Client_Tokenize $data
    )
    {
        $acl = array();

        // Ignore mailbox argument -> index 1
        $data->next();

        while (($curr = $data->next()) !== false) {
            $acl[$curr] = ($curr[0] === '-')
                ? new Horde_Imap_Client_Data_AclNegative($data->next())
                : new Horde_Imap_Client_Data_Acl($data->next());
        }

        $pipeline->data['getacl'] = $acl;
    }
1013124
protected function parseHeader($data)
    {
        $leftover = '';

        $length = mb_strlen($data, '8bit');

        for ($i = 0; $i < $length; $i++) {
            switch ($this->cursor) {
            case 0x00:
                $char = $this->getChar($data, $i);

                $this->fin    = (($char & 0x80) === 0x80);
                $this->rsv1   = (($char & 0x40) === 0x40);
                $this->rsv2   = (($char & 0x20) === 0x20);
                $this->rsv3   = (($char & 0x10) === 0x10);
                $this->opcode = $char & 0x0f;

                break;

            case 0x01:
                $char = $this->getChar($data, $i);

                $this->isMasked = (($char & 0x80) === 0x80);
                $this->length    = $char & 0x7f;

                if ($this->isMasked) {
                    $this->headerLength += 4;
                }

                // extended length
                if ($this->length === 0x7e) {
                    $this->headerLength += 2;
                } elseif ($this->length === 0x7f) {
                    $this->headerLength += 6;
                }

                break;

            case 0x02:
            case 0x03:
                if ($this->length === 0x7e) {
                    $this->lengthData .= mb_substr($data, $i, 1, '8bit');
                    if ($this->cursor === 0x03) {
                        $this->length16 = $this->getShort($this->lengthData);
                    }
                } elseif ($this->length === 0x7f) {
                    $this->lengthData .= mb_substr($data, $i, 1, '8bit');
                } else {
                    $this->mask .= mb_substr($data, $i, 1, '8bit');
                }
                break;

            case 0x04:
            case 0x05:
            case 0x06:
            case 0x07:
                if ($this->length === 0x7f) {
                    $this->lengthData .= mb_substr($data, $i, 1, '8bit');
                } else {
                    $this->mask .= mb_substr($data, $i, 1, '8bit');
                }
                break;

            case 0x08:
            case 0x09:
                $this->lengthData .= mb_substr($data, $i, 1, '8bit');
                if ($this->cursor === 0x09) {
                    $this->length64 = $this->getLong($this->lengthData);
                }
                break;

            case 0x0a:
            case 0x0b:
                $this->mask .= mb_substr($data, $i, 1, '8bit');
                break;

            default:
                throw new Exception('Parsed frame header length incorrectly.');
            }

            $this->cursor++;

            // check if finished parsing header
            if ($this->cursor === $this->headerLength) {
                $this->isHeaderComplete = true;
                $this->state = self::STATE_HEADERS_RECEIVED;
                break;
            }
        }

        // we have more data
        if ($i < $length) {
            $data = mb_substr($data, $i + 1, $length - $i - 1, '8bit');
            $leftover = $this->parseData($data);
        }

        return $leftover;
    }
875388
protected function formatWeappMessage(array $data = [])
    {
        $params = $this->baseFormat($data, $this->weappMessage);

        $params['data'] = $this->formatData($params['data'] ?? []);

        return $params;
    }