当前位置: 首页>>代码示例>>PHP>>正文


PHP DescriptorProto::getOptions方法代码示例

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


在下文中一共展示了DescriptorProto::getOptions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: printGetDescriptor

 public function printGetDescriptor(Printer $printer)
 {
     $php_options = $this->descriptor->getOptions();
     $printer->put("/**\n");
     $printer->put(" * get descriptor for protocol buffers\n");
     $printer->put(" * \n");
     $printer->put(" * @return \\ProtocolBuffersDescriptor\n");
     $printer->put(" */\n");
     $printer->put("public static function getDescriptor()\n");
     $printer->put("{\n");
     $printer->indent();
     $printer->put("static \$descriptor;\n");
     $printer->put("\n");
     $printer->put("if (!isset(\$descriptor)) {\n");
     $printer->indent();
     $printer->put("\$desc = new `class_name`();\n", "class_name", Helper::getDescriptorBuilderClassName($this->descriptor));
     foreach ($this->descriptor->getField() as $offset => $field) {
         /* @var $field \google\protobuf\FieldDescriptorProto */
         $printer->put("\$desc->addField(`tag`, new `class_name`(array(\n", "tag", $field->getNumber(), "class_name", Helper::getFieldDescriptorClassName($this->descriptor));
         $printer->indent();
         $printer->put("\"type\"     => `type`,\n", "type", Helper::getFieldTypeName($field));
         $printer->put("\"name\"     => \"`name`\",\n", "name", $field->getName());
         $printer->put("\"required\" => `required`,\n", "required", FieldDescriptorProto\Label::isRequired($field) ? "true" : "false");
         $printer->put("\"optional\" => `optional`,\n", "optional", FieldDescriptorProto\Label::isOptional($field) ? "true" : "false");
         $printer->put("\"repeated\" => `repeated`,\n", "repeated", FieldDescriptorProto\Label::isRepeated($field) ? "true" : "false");
         $options = $field->getOptions();
         if ($options) {
             $printer->put("\"packable\" => `packable`,\n", "packable", FieldDescriptorProto\Label::isPacked($field) ? "true" : "false");
         } else {
             $printer->put("\"packable\" => `packable`,\n", "packable", "false");
         }
         $printer->put("\"default\"  => `value`,\n", "value", $this->defaultValueAsString($field));
         if (FieldDescriptorProto\Type::isMessage($field)) {
             $name = $field->getTypeName();
             $descriptor = MessagePool::get($name);
             $printer->put("\"message\" => '`message`',\n", "message", Helper::getClassName($descriptor, true));
         }
         $printer->outdent();
         $printer->put(")));\n");
     }
     if ($php_options instanceof \google\protobuf\MessageOptions) {
         $php_message_options = $php_options->getExtension("php_option");
         if ($php_message_options->getUseSingleProperty()) {
             $printer->put("\$phpoptions = \$desc->getOptions()->getExtension");
             $printer->put("(\\ProtocolBuffers::PHP_MESSAGE_OPTION);\n");
             $printer->put("\$phpoptions->setUseSingleProperty(true);\n");
             $printer->put("\$phpoptions->setSinglePropertyName(\"`name`\");\n", "name", $php_message_options->getSinglePropertyName());
             $printer->put("\n");
         }
     }
     $printer->put("// @@protoc_insertion_point(builder_scope:`name`)\n\n", "name", $this->descriptor->full_name);
     $printer->put("\$descriptor = \$desc->build();\n");
     $printer->outdent();
     $printer->put("}\n");
     $printer->put("return \$descriptor;\n");
     $printer->outdent();
     $printer->put("}\n\n");
 }
开发者ID:asamaru7,项目名称:protoc-gen-php,代码行数:58,代码来源:MessageGenerator.php


注:本文中的Google\Protobuf\DescriptorProto::getOptions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。