Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. GPBUtil.php

function GPBUtil::checkMapField

1 call to GPBUtil::checkMapField()
Struct::setFields in vendor/google/protobuf/src/Google/Protobuf/Struct.php
Unordered map of dynamically typed values.

File

vendor/google/protobuf/src/Google/Protobuf/Internal/GPBUtil.php, line 205

Class

GPBUtil

Namespace

Google\Protobuf\Internal

Code

public static function checkMapField(&$var, $key_type, $value_type, $klass = null) {
    if (!$var instanceof MapField && !is_array($var)) {
        throw new \Exception("Expect dict.");
    }
    if (is_array($var)) {
        $tmp = new MapField($key_type, $value_type, $klass);
        foreach ($var as $key => $value) {
            $tmp[$key] = $value;
        }
        return $tmp;
    }
    else {
        if ($var->getKeyType() != $key_type) {
            throw new \Exception("Expect map field of key type.");
        }
        if ($var->getValueType() != $value_type) {
            throw new \Exception("Expect map field of value type.");
        }
        if ($var->getValueType() === GPBType::MESSAGE && $var->getValueClass() !== $klass && $var->getLegacyValueClass() !== $klass) {
            throw new \Exception("Expect map field of " . $klass . ".");
        }
        return $var;
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal