public function testGetNamespaceUsingPhpOptions() { $name = 'SimpleMessage'; $type = Entity::TYPE_MESSAGE; $descriptor = new DescriptorProto(); $fileDescriptor1 = new FileDescriptorProto(); $fileDescriptor2 = new FileDescriptorProto(); $fileDescriptor3 = new FileDescriptorProto(); $fileOptions2 = new FileOptions(); $fileOptions3 = new FileOptions(); $fileOptions2->extensions()->put(Extension::package(), 'Package'); $fileOptions3->extensions()->put(Extension::package(), 'Package'); $fileDescriptor1->setPackage('package'); $fileDescriptor2->setPackage('package'); $fileDescriptor3->setPackage('package'); $fileDescriptor2->setOptions($fileOptions2); $fileDescriptor3->setOptions($fileOptions3); $entity1 = new Entity($type, $name, $descriptor, $fileDescriptor1); $entity2 = new Entity($type, $name, $descriptor, $fileDescriptor2); $entity3 = new Entity($type, $name, $descriptor, $fileDescriptor3, 'Parent'); $this->assertEquals('package', $entity1->getNamespace()); $this->assertEquals('Package', $entity2->getNamespace()); $this->assertEquals('Package\\Parent', $entity3->getNamespace()); }
\google\protobuf\FileOptions::extension(function () { // OPTIONAL STRING php.suffix = 50003 $f = new \StudyDrSlump\Protobuf\Field(); $f->number = 50003; $f->name = "php.suffix"; $f->type = \StudyDrSlump\Protobuf::TYPE_STRING; $f->rule = \StudyDrSlump\Protobuf::RULE_OPTIONAL; $f->default = ".php"; return $f; }); \google\protobuf\FileOptions::extension(function () { // OPTIONAL BOOL php.multifile = 50004 $f = new \StudyDrSlump\Protobuf\Field(); $f->number = 50004; $f->name = "php.multifile"; $f->type = \StudyDrSlump\Protobuf::TYPE_BOOL; $f->rule = \StudyDrSlump\Protobuf::RULE_OPTIONAL; $f->default = FALSE; return $f; }); \google\protobuf\FileOptions::extension(function () { // OPTIONAL BOOL php.generic_services = 50005 $f = new \StudyDrSlump\Protobuf\Field(); $f->number = 50005; $f->name = "php.generic_services"; $f->type = \StudyDrSlump\Protobuf::TYPE_BOOL; $f->rule = \StudyDrSlump\Protobuf::RULE_OPTIONAL; $f->default = FALSE; return $f; }); }
\google\protobuf\FileOptions::extension(function () { // optional php.suffix = 50003 $f = new \DrSlump\Protobuf\Field(); $f->number = 50003; $f->name = "php.suffix"; $f->type = 9; $f->rule = 1; $f->default = ".php"; return $f; }); \google\protobuf\FileOptions::extension(function () { // optional php.multiple = 50004 $f = new \DrSlump\Protobuf\Field(); $f->number = 50004; $f->name = "php.multifile"; $f->type = 8; $f->rule = 1; $f->default = false; return $f; }); \google\protobuf\FileOptions::extension(function () { // optional php.generic_services = 50005 $f = new \DrSlump\Protobuf\Field(); $f->number = 50005; $f->name = "php.generic_services"; $f->type = 8; $f->rule = 1; $f->default = false; return $f; }); }
/** * @param string $name * @param string $package * @param array $values * * @return \google\protobuf\FileDescriptorProto */ protected function createFileDescriptorProto($name, $package, array $values = []) { $descriptor = new FileDescriptorProto(); $extensions = isset($values['extensions']) ? $values['extensions'] : []; $options = isset($values['options']) ? $values['options'] : null; $messages = isset($values['messages']) ? $values['messages'] : []; $services = isset($values['services']) ? $values['services'] : []; $enums = isset($values['enums']) ? $values['enums'] : []; $descriptor->setName($name); $descriptor->setPackage($package); 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 ($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->addMessageType($item); } foreach ($enums as $item) { if (is_array($item)) { $name = $item['name']; $values = isset($item['values']) ? $item['values'] : []; $item = $this->createEnumDescriptorProto($name, $values); } $descriptor->addEnumType($item); } foreach ($services as $item) { if (is_array($item)) { $name = $item['name']; $values = isset($item['values']) ? $item['values'] : []; $item = $this->createServiceDescriptorProto($name, $values); } $descriptor->addService($item); } if ($options !== null) { $fileOptions = new FileOptions(); $optionsExt = isset($options['extensions']) ? $options['extensions'] : []; if (isset($options['packed'])) { $fileOptions->setPacked($options['packed']); } foreach ($optionsExt as $ext) { $fileOptions->extensions()->put($ext[0], $ext[1]); } $descriptor->setOptions($fileOptions); } return $descriptor; }
/** * {@inheritdoc} */ public function serializedSize(\Protobuf\ComputeSizeContext $context) { $calculator = $context->getSizeCalculator(); $size = 0; if ($this->name !== null) { $size += 1; $size += $calculator->computeStringSize($this->name); } if ($this->package !== null) { $size += 1; $size += $calculator->computeStringSize($this->package); } if ($this->dependency !== null) { foreach ($this->dependency as $val) { $size += 1; $size += $calculator->computeStringSize($val); } } if ($this->public_dependency !== null) { foreach ($this->public_dependency as $val) { $size += 1; $size += $calculator->computeVarintSize($val); } } if ($this->weak_dependency !== null) { foreach ($this->weak_dependency as $val) { $size += 1; $size += $calculator->computeVarintSize($val); } } if ($this->message_type !== null) { foreach ($this->message_type as $val) { $innerSize = $val->serializedSize($context); $size += 1; $size += $innerSize; $size += $calculator->computeVarintSize($innerSize); } } if ($this->enum_type !== null) { foreach ($this->enum_type as $val) { $innerSize = $val->serializedSize($context); $size += 1; $size += $innerSize; $size += $calculator->computeVarintSize($innerSize); } } if ($this->service !== null) { foreach ($this->service as $val) { $innerSize = $val->serializedSize($context); $size += 1; $size += $innerSize; $size += $calculator->computeVarintSize($innerSize); } } if ($this->extension !== null) { foreach ($this->extension as $val) { $innerSize = $val->serializedSize($context); $size += 1; $size += $innerSize; $size += $calculator->computeVarintSize($innerSize); } } if ($this->options !== null) { $innerSize = $this->options->serializedSize($context); $size += 1; $size += $innerSize; $size += $calculator->computeVarintSize($innerSize); } if ($this->source_code_info !== null) { $innerSize = $this->source_code_info->serializedSize($context); $size += 1; $size += $innerSize; $size += $calculator->computeVarintSize($innerSize); } if ($this->syntax !== null) { $size += 1; $size += $calculator->computeStringSize($this->syntax); } if ($this->extensions !== null) { $size += $this->extensions->serializedSize($context); } return $size; }
<?php // DO NOT EDIT! Generated by Protobuf for PHP protoc plugin @package_version@ // Source: php.proto // Date: 2011-03-20 01:27:38 namespace { \google\protobuf\FileOptions::extension(function () { // optional php.namespace = 50002 $f = new \DrSlump\Protobuf\Field(); $f->number = 50102; $f->name = "json.namespace"; $f->type = 9; $f->rule = 1; return $f; }); \google\protobuf\FileOptions::extension(function () { // optional php.suffix = 50003 $f = new \DrSlump\Protobuf\Field(); $f->number = 50103; $f->name = "json.suffix"; $f->type = 9; $f->rule = 1; $f->default = ".pb.js"; return $f; }); }
}); \google\protobuf\FileOptions::extension(function () { // optional string suffix = 50003 $f = new \DrSlump\Protobuf\Field(); $f->number = 50003; $f->name = "suffix"; $f->rule = \DrSlump\Protobuf\Protobuf::RULE_OPTIONAL; $f->type = \DrSlump\Protobuf\Protobuf::TYPE_STRING; $f->default = '.php'; return $f; }); \google\protobuf\FileOptions::extension(function () { // optional bool multifile = 50004 $f = new \DrSlump\Protobuf\Field(); $f->number = 50004; $f->name = "multifile"; $f->rule = \DrSlump\Protobuf\Protobuf::RULE_OPTIONAL; $f->type = \DrSlump\Protobuf\Protobuf::TYPE_BOOL; $f->default = false; return $f; }); \google\protobuf\FileOptions::extension(function () { // optional bool generic_services = 50005 $f = new \DrSlump\Protobuf\Field(); $f->number = 50005; $f->name = "generic_services"; $f->rule = \DrSlump\Protobuf\Protobuf::RULE_OPTIONAL; $f->type = \DrSlump\Protobuf\Protobuf::TYPE_BOOL; $f->default = false; return $f; });