本文整理匯總了PHP中Google\Protobuf\DescriptorProto::addEnumType方法的典型用法代碼示例。如果您正苦於以下問題:PHP DescriptorProto::addEnumType方法的具體用法?PHP DescriptorProto::addEnumType怎麽用?PHP DescriptorProto::addEnumType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Google\Protobuf\DescriptorProto
的用法示例。
在下文中一共展示了DescriptorProto::addEnumType方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createDescriptorProto
/**
* @param string $name
* @param array $fields
* @param array $values
*
* @return \google\protobuf\DescriptorProto
*/
protected function createDescriptorProto($name, array $fields, array $values = [])
{
$descriptor = new DescriptorProto();
$enums = isset($values['enums']) ? $values['enums'] : [];
$messages = isset($values['messages']) ? $values['messages'] : [];
$extensions = isset($values['extensions']) ? $values['extensions'] : [];
$descriptor->setName($name);
foreach ($fields as $number => $field) {
if (is_array($field)) {
$name = $field[0];
$type = $field[1];
$label = $field[2];
$typeName = isset($field[3]) ? $field[3] : null;
$values = isset($field[4]) ? $field[4] : [];
$field = $this->createFieldDescriptorProto($number, $name, $type, $label, $typeName, $values);
}
$descriptor->addField($field);
}
foreach ($extensions as $number => $field) {
if (is_array($field)) {
$name = $field[0];
$type = $field[1];
$label = $field[2];
$extendee = $field[3];
$typeName = isset($field[4]) ? $field[4] : null;
$field = $this->createFieldDescriptorProto($number, $name, $type, $label, $typeName);
$field->setExtendee($extendee);
}
$descriptor->addExtension($field);
}
foreach ($enums as $enum) {
if (is_array($enum)) {
$name = $enum['name'];
$values = $enum['values'];
$enum = $this->createEnumDescriptorProto($name, $values);
}
$descriptor->addEnumType($enum);
}
foreach ($messages as $item) {
if (is_array($item)) {
$name = $item['name'];
$fields = isset($item['fields']) ? $item['fields'] : [];
$values = isset($item['values']) ? $item['values'] : [];
$item = $this->createDescriptorProto($name, $fields, $values);
}
$descriptor->addNestedType($item);
}
return $descriptor;
}