Пример #1
0
 /**
  * @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;
 }