protected function compileEnum(proto\EnumDescriptorProto $enum, $ns)
 {
     $s = array();
     $s[] = "namespace " . $this->normalizeNS($ns) . " {";
     $s[] = "";
     $s[] = "  // @@protoc_insertion_point(scope_namespace)";
     $s[] = "  // @@protoc_insertion_point(namespace_{$ns})";
     $s[] = "";
     $cmt = $this->compiler->getComment($ns . '.' . $enum->getName(), '   * ');
     if ($cmt) {
         $s[] = "  /**";
         $s[] = $cmt;
         $s[] = "   */";
     }
     $s[] = "  class " . $enum->getName() . ' extends \\DrSlump\\Protobuf\\Enum {';
     foreach ($enum->getValueList() as $value) {
         $s[] = "    const " . $value->getName() . " = " . $value->getNumber() . ";";
     }
     $s[] = "";
     $s[] = "    // @@protoc_insertion_point(scope_class)";
     $s[] = '    // @@protoc_insertion_point(class_' . $ns . '.' . $enum->getName() . ')';
     $s[] = "  }";
     $s[] = "}";
     $s[] = "";
     return implode(PHP_EOL, $s);
 }
示例#2
0
 public function compileEnum(proto\EnumDescriptorProto $enum, $namespace)
 {
     $s[] = "{$namespace}.{$enum->name} = {";
     $lines = array();
     foreach ($enum->getValueList() as $value) {
         $lines[] = "  /** @const */ {$value->name}: {$value->number}";
     }
     $s[] = implode(",\n", $lines);
     $s[] = '};';
     $s[] = '';
     return implode("\n", $s);
 }