本文整理汇总了PHP中Google\Protobuf\DescriptorProto::addExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP DescriptorProto::addExtension方法的具体用法?PHP DescriptorProto::addExtension怎么用?PHP DescriptorProto::addExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google\Protobuf\DescriptorProto
的用法示例。
在下文中一共展示了DescriptorProto::addExtension方法的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;
}