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()); }
public function descriptorProvider() { return [['Simple.tpl', 'ProtobufCompilerTest.Protos.Simple', ['name' => 'simple.proto', 'package' => 'ProtobufCompilerTest.Protos', 'values' => ['messages' => [['name' => 'Simple', 'fields' => [1 => ['double', Field::TYPE_DOUBLE, Field::LABEL_OPTIONAL], 2 => ['float', Field::TYPE_FLOAT, Field::LABEL_OPTIONAL], 3 => ['int64', Field::TYPE_INT64, Field::LABEL_OPTIONAL], 4 => ['uint64', Field::TYPE_UINT64, Field::LABEL_OPTIONAL], 5 => ['int32', Field::TYPE_INT32, Field::LABEL_OPTIONAL], 6 => ['fixed64', Field::TYPE_FIXED64, Field::LABEL_OPTIONAL], 7 => ['fixed32', Field::TYPE_FIXED32, Field::LABEL_OPTIONAL], 8 => ['bool', Field::TYPE_BOOL, Field::LABEL_OPTIONAL], 9 => ['string', Field::TYPE_STRING, Field::LABEL_OPTIONAL], 12 => ['bytes', Field::TYPE_BYTES, Field::LABEL_OPTIONAL], 13 => ['uint32', Field::TYPE_UINT32, Field::LABEL_OPTIONAL], 15 => ['sfixed32', Field::TYPE_SFIXED32, Field::LABEL_OPTIONAL], 16 => ['sfixed64', Field::TYPE_SFIXED64, Field::LABEL_OPTIONAL], 17 => ['sint32', Field::TYPE_SINT32, Field::LABEL_OPTIONAL], 18 => ['sint64', Field::TYPE_SINT64, Field::LABEL_OPTIONAL]]]]]]], ['PhoneNumber.tpl', 'ProtobufCompilerTest.Protos.PhoneNumber', ['name' => 'addressbook.proto', 'package' => 'ProtobufCompilerTest.Protos', 'values' => ['messages' => [['name' => 'PhoneNumber', 'fields' => [1 => ['number', Field::TYPE_STRING, Field::LABEL_REQUIRED], 2 => ['type', Field::TYPE_ENUM, Field::LABEL_OPTIONAL, '.ProtobufCompilerTest.Protos.PhoneType', ['default' => 'HOME']]]], ['name' => 'PhoneType', 'fields' => []]]]]], ['Person.tpl', 'ProtobufCompilerTest.Protos.Person', ['name' => 'addressbook.proto', 'package' => 'ProtobufCompilerTest.Protos', 'values' => ['messages' => [['name' => 'Person', 'fields' => [1 => ['name', Field::TYPE_STRING, Field::LABEL_REQUIRED], 2 => ['id', Field::TYPE_INT32, Field::LABEL_REQUIRED], 3 => ['email', Field::TYPE_STRING, Field::LABEL_OPTIONAL], 4 => ['phone', Field::TYPE_MESSAGE, Field::LABEL_REPEATED, '.ProtobufCompilerTest.Protos.PhoneNumber']]], ['name' => 'PhoneNumber', 'fields' => []]]]]], ['Person/PhoneType.tpl', 'ProtobufCompilerTest.Protos.Person.PhoneType', ['name' => 'addressbook.proto', 'package' => 'ProtobufCompilerTest.Protos', 'values' => ['messages' => [['name' => 'Person', 'fields' => [], 'values' => ['enums' => [['name' => 'PhoneType', 'values' => [0 => 'MOBILE', 1 => 'HOME', 2 => 'WORK']]]]]]]]], ['Extension/Extension.tpl', 'ProtobufCompilerTest.Protos.Extension.Extension', ['name' => 'extension.proto', 'package' => 'ProtobufCompilerTest.Protos.Extension', 'values' => ['extensions' => [200 => ['habitat', Field::TYPE_STRING, Field::LABEL_OPTIONAL, '.ProtobufCompilerTest.Protos.Extension.Animal'], 201 => ['verbose', Field::TYPE_BOOL, Field::LABEL_OPTIONAL, '.ProtobufCompilerTest.Protos.Extension.Command']], 'messages' => [['name' => 'Dog', 'fields' => [], 'values' => ['extensions' => [101 => ['animal', Field::TYPE_MESSAGE, Field::LABEL_OPTIONAL, '.ProtobufCompilerTest.Protos.Extension.Animal', '.ProtobufCompilerTest.Protos.Extension.Dog']]]], ['name' => 'Command', 'fields' => []], ['name' => 'Animal', 'fields' => []]]]]], ['Extension/Dog.tpl', 'ProtobufCompilerTest.Protos.Extension.Dog', ['name' => 'extension.proto', 'package' => 'ProtobufCompilerTest.Protos.Extension', 'values' => ['messages' => [['name' => 'Dog', 'fields' => [1 => ['bones_buried', Field::TYPE_INT32, Field::LABEL_OPTIONAL, '.ProtobufCompilerTest.Protos.Extension.Dog']], 'values' => ['extensions' => [101 => ['animal', Field::TYPE_MESSAGE, Field::LABEL_OPTIONAL, '.ProtobufCompilerTest.Protos.Extension.Animal', '.ProtobufCompilerTest.Protos.Extension.Dog']]]], ['name' => 'Animal', 'fields' => []]]]]], ['Options/SimpleMessage.tpl', 'ProtobufCompilerTest.Protos.SimpleMessage', ['name' => 'php_options.proto', 'package' => 'ProtobufCompilerTest.Protos', 'values' => ['options' => ['extensions' => [[Extension::package(), 'ProtobufCompilerTest.Protos.Options']]], 'messages' => [['name' => 'SimpleMessage', 'fields' => []]]]]], ['Options/ParentMessage/InnerMessage/InnerMessageEnum.tpl', 'ProtobufCompilerTest.Protos.ParentMessage.InnerMessage.InnerMessageEnum', ['name' => 'php_options.proto', 'package' => 'ProtobufCompilerTest.Protos', 'values' => ['options' => ['extensions' => [[Extension::package(), 'ProtobufCompilerTest.Protos.Options']]], 'messages' => [['name' => 'ParentMessage', 'fields' => [], 'values' => ['messages' => [['name' => 'InnerMessage', 'fields' => [], 'values' => ['enums' => [['name' => 'InnerMessageEnum', 'values' => [0 => 'VALUE']]]]]]]]]]]]]; }
/** * @return \Protobuf\Configuration */ public static function defaultConfig() { $config = Configuration::getInstance(); $registry = $config->getExtensionRegistry(); Extension::registerAllExtensions($registry); return $config; }
/** * @return string */ public function getNamespace() { $package = $this->getPackage(); $extension = Extension::package(); $extensions = $this->getFileOptionsExtensions(); if ($extensions !== null && $extensions->offsetExists($extension)) { $package = $this->fullyQualifiedName($extensions->get($extension), $this->parent); } if ($package === null) { return $package; } return str_replace('.', '\\', $package); }