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

Breadcrumb

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

function FieldDescriptor::getFieldDescriptor

Parameters

FieldDescriptorProto $proto:

Return value

FieldDescriptor

1 call to FieldDescriptor::getFieldDescriptor()
FieldDescriptor::buildFromProto in vendor/google/protobuf/src/Google/Protobuf/Internal/FieldDescriptor.php

File

vendor/google/protobuf/src/Google/Protobuf/Internal/FieldDescriptor.php, line 227

Class

FieldDescriptor

Namespace

Google\Protobuf\Internal

Code

public static function getFieldDescriptor($proto) {
    $type_name = null;
    $type = $proto->getType();
    switch ($type) {
        case GPBType::MESSAGE:
        case GPBType::GROUP:
        case GPBType::ENUM:
            $type_name = $proto->getTypeName();
            break;
        default:
            break;
    }
    $oneof_index = $proto->hasOneofIndex() ? $proto->getOneofIndex() : -1;
    // TODO: once proto2 is supported, this default should be false
    // for proto2.
    if ($proto->getLabel() === GPBLabel::REPEATED && $proto->getType() !== GPBType::MESSAGE && $proto->getType() !== GPBType::GROUP && $proto->getType() !== GPBType::STRING && $proto->getType() !== GPBType::BYTES) {
        $packed = true;
    }
    else {
        $packed = false;
    }
    $options = $proto->getOptions();
    if ($options !== null) {
        $packed = $options->getPacked();
    }
    $field = new FieldDescriptor();
    $field->setName($proto->getName());
    if ($proto->hasJsonName()) {
        $json_name = $proto->getJsonName();
    }
    else {
        $proto_name = $proto->getName();
        $json_name = implode('', array_map('ucwords', explode('_', $proto_name)));
        if ($proto_name[0] !== "_" && !ctype_upper($proto_name[0])) {
            $json_name = lcfirst($json_name);
        }
    }
    $field->setJsonName($json_name);
    $camel_name = implode('', array_map('ucwords', explode('_', $proto->getName())));
    $field->setGetter('get' . $camel_name);
    $field->setSetter('set' . $camel_name);
    $field->setType($proto->getType());
    $field->setNumber($proto->getNumber());
    $field->setLabel($proto->getLabel());
    $field->setPacked($packed);
    $field->setOneofIndex($oneof_index);
    $field->setProto3Optional($proto->getProto3Optional());
    // At this time, the message/enum type may have not been added to pool.
    // So we use the type name as place holder and will replace it with the
    // actual descriptor in cross building.
    switch ($type) {
        case GPBType::MESSAGE:
            $field->setMessageType($type_name);
            break;
        case GPBType::ENUM:
            $field->setEnumType($type_name);
            break;
        default:
            break;
    }
    return $field;
}
RSS feed
Powered by Drupal