本文整理汇总了PHP中Google\Protobuf\FieldDescriptorProto::getExtendee方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldDescriptorProto::getExtendee方法的具体用法?PHP FieldDescriptorProto::getExtendee怎么用?PHP FieldDescriptorProto::getExtendee使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google\Protobuf\FieldDescriptorProto
的用法示例。
在下文中一共展示了FieldDescriptorProto::getExtendee方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateBody
/**
* @param \Protobuf\Compiler\Entity $entity
* @param \google\protobuf\FieldDescriptorProto $field
*
* @return string[]
*/
public function generateBody(Entity $entity, FieldDescriptorProto $field)
{
$name = $field->getName();
$tag = $field->getNumber();
$extEntity = $this->getEntity($field->getExtendee());
$extendee = $extEntity->getNamespacedName();
$nameQuoted = var_export($name, true);
$extendeeQuoted = var_export($extendee, true);
$sizeCallback = $this->generateSizeCallback($entity, $field);
$readCallback = $this->generateReadCallback($entity, $field);
$writeCallback = $this->generateWriteCallback($entity, $field);
$callbacks = array_merge($readCallback, [null], $writeCallback, [null], $sizeCallback);
$arguments = [$extendeeQuoted, $nameQuoted, $tag, '$readCallback', '$writeCallback', '$sizeCallback', '__METHOD__'];
$body[] = 'if (self::$' . $name . ' !== null) {';
$body[] = ' return self::$' . $name . ';';
$body[] = '}';
$body[] = null;
$body = array_merge($body, $callbacks);
$body[] = null;
$body[] = 'return self::$' . $name . ' = new \\Protobuf\\Extension\\ExtensionField(' . implode(', ', $arguments) . ');';
return $body;
}
示例2: compileExtension
protected function compileExtension(proto\FieldDescriptorProto $field, $ns, $indent)
{
$extendee = $this->normalizeNS($field->getExtendee());
$name = $this->normalizeNS($ns . '.' . $field->getName());
$field->setName($name);
$s[] = "\\{$extendee}::extension(function(){";
$s[] = $this->compileField($field, $ns, $indent . ' ');
$s[] = ' // @@protoc_insertion_point(scope_extension)';
$s[] = ' // @@protoc_insertion_point(extension_' . $ns . ':' . $field->getName() . ')';
$s[] = ' return $f;';
$s[] = "});";
return $indent . implode(PHP_EOL . $indent, $s);
}
示例3: printExtension
public function printExtension(Printer $printer, FieldDescriptorProto $field)
{
if (ExtensionPool::has($field->getExtendee(), $field->getNumber())) {
// NOTE: already registered.
return;
}
ExtensionPool::register($field->getExtendee(), $field->getNumber(), $field);
$printer->put("\$registry->add('`message`', `extension`, new \\ProtocolBuffers\\FieldDescriptor(array(\n", "message", Helper::getExtendeeClassName($field), "extension", $field->getNumber());
$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");
$printer->put("\"packable\" => `packable`,\n", "packable", FieldDescriptorProto\Label::isPacked($field) ? "true" : "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");
}
示例4: compileExtension
public function compileExtension(proto\FieldDescriptorProto $field, $ns, $indent)
{
$extendee = $this->normalizeReference($field->getExtendee());
$name = $field->getName();
if ($ns) {
$name = $ns . '.' . $name;
}
$field->setName($name);
$s[] = "ProtoJson.extend({$extendee}, {";
$s[] = " {$field->number}: " . $this->generateField($field);
$s[] = "});";
$s[] = '';
return $indent . implode("\n{$indent}", $s);
}
示例5: getExtendeeClassName
public static function getExtendeeClassName(FieldDescriptorProto $field)
{
if (getenv("PEAR_STYLE") || $field->file()->getOptions()->getExtension("php")->getStyle() == Style::PEAR) {
return str_replace(".", "_", preg_replace("/^.+/", ".", $field->getExtendee()));
} else {
return str_replace(".", "\\", $field->getExtendee());
}
}
示例6: isProtobufExtension
/**
* @param \google\protobuf\FieldDescriptorProto $fieldDescriptor
*
* @return boolean
*/
protected function isProtobufExtension(FieldDescriptorProto $fieldDescriptor)
{
if (!$fieldDescriptor->hasExtendee()) {
return false;
}
$extendee = trim($fieldDescriptor->getExtendee(), '.');
$package = 'google.protobuf';
$length = strlen($package);
return substr($extendee, 0, $length) === $package;
}
示例7: generateFieldBody
/**
* @param \google\protobuf\FieldDescriptorProto $field
*
* @return string[]
*/
protected function generateFieldBody(FieldDescriptorProto $field)
{
$lines = [];
$name = $field->getName();
$number = $field->getNumber();
$typeName = $field->getTypeName();
$extendee = $field->getExtendee();
$type = $field->getType()->name();
$label = $field->getLabel()->name();
$default = $this->getDefaultFieldValue($field);
$values = ['number' => var_export($number, true), 'name' => var_export($name, true), 'type' => '\\google\\protobuf\\FieldDescriptorProto\\Type::' . $type . '()', 'label' => '\\google\\protobuf\\FieldDescriptorProto\\Label::' . $label . '()'];
if ($extendee) {
$values['extendee'] = var_export($extendee, true);
}
if ($typeName) {
$values['type_name'] = var_export($typeName, true);
}
if ($field->hasDefaultValue()) {
$values['default_value'] = $default;
}
$lines[] = '\\google\\protobuf\\FieldDescriptorProto::fromArray([';
$lines = array_merge($lines, $this->generateArrayLines($values));
$lines[] = ']),';
return $lines;
}