/**
  * @return \Protobuf\Extension\ExtensionFieldMap
  */
 protected function getFileOptionsExtensions()
 {
     if (!$this->fileDescriptor->hasOptions()) {
         return null;
     }
     return $this->fileDescriptor->getOptions()->extensions();
 }
Beispiel #2
0
 public function generateSiblings($package_name, GeneratorContext $context, &$file_list)
 {
     if ($this->file->getOptions()->getExtension("php")->getMultipleFiles()) {
         foreach ($this->file->getEnumType() as $enum) {
             $enum->full_name = Helper::getPackageName($this->file) . "." . $enum->getName();
             $path = $package_name . DIRECTORY_SEPARATOR . $enum->getName() . ".php";
             $output = $context->open($path);
             $file_list[] = $path;
             $printer = new Printer($output, "`");
             $gen = new EnumGenerator($context, $enum, $file_list);
             $gen->generate($printer);
         }
         foreach ($this->file->getMessageType() as $message) {
             $message->full_name = Helper::getPackageName($this->file) . "." . $message->getName();
             $path = $package_name . DIRECTORY_SEPARATOR . $message->getName() . ".php";
             $output = $context->open($path);
             $file_list[] = $path;
             $printer = new Printer($output, "`");
             $gen = new MessageGenerator($context, $message, $file_list);
             $gen->generate($printer);
         }
         /* TODO(chobie): add service here */
     }
 }
 public function compileProtoFile(proto\FileDescriptorProto $proto)
 {
     $file = new \google\protobuf\compiler\CodeGeneratorResponse\File();
     $opts = $proto->getOptions();
     $name = pathinfo($proto->getName(), PATHINFO_FILENAME);
     $name .= isset($opts['json.suffix']) ? $opts['json.suffix'] : '.js';
     $file->setName($name);
     $namespace = $this->getNamespace($proto);
     $s[] = "// DO NOT EDIT! Generated by Protobuf for PHP protoc plugin " . Protobuf::VERSION;
     $s[] = "// Source: " . $proto->getName();
     $s[] = "//   Date: " . date('Y-m-d H:i:s');
     $s[] = "";
     $s[] = "(function(){";
     $s[] = "/** @namespace */";
     $s[] = "var {$namespace} = {$namespace} || {};";
     $s[] = "";
     $s[] = "// Make it CommonJS compatible";
     $s[] = "if (typeof exports !== 'undefined') {";
     $s[] = "  var ProtoJson = this.ProtoJson;";
     $s[] = "  if (!ProtoJson && typeof require !== 'undefined')";
     $s[] = "    ProtoJson = require('ProtoJson');";
     $s[] = "  {$namespace} = exports;";
     $s[] = "} else {";
     $s[] = "  this.{$namespace} = {$namespace};";
     $s[] = "}";
     $s[] = "";
     // Generate Enums
     foreach ($proto->getEnumTypeList() as $enum) {
         $s[] = $this->compileEnum($enum, $namespace);
     }
     // Generate Messages
     foreach ($proto->getMessageTypeList() as $msg) {
         $s[] = $this->compileMessage($msg, $namespace);
     }
     // Collect extensions
     if ($proto->hasExtension()) {
         foreach ($proto->getExtensionList() as $field) {
             $this->extensions[$field->getExtendee()][] = array($namespace, $field);
         }
     }
     // Dump all extensions found in this proto file
     if (count($this->extensions)) {
         foreach ($this->extensions as $extendee => $fields) {
             foreach ($fields as $pair) {
                 list($ns, $field) = $pair;
                 $s[] = $this->compileExtension($field, $ns, '');
             }
         }
     }
     $s[] = "})();";
     $src = implode("\n", $s);
     $file->setContent($src);
     return array($file);
 }
Beispiel #4
0
 public static function IsPackageNameOverriden(FileDescriptorProto $file)
 {
     $package = getEnv("PACKAGE");
     $result = null;
     if ($package) {
         $result = $package;
     } else {
         if ($file->getOptions()->getJavaPackage()) {
             $result = $file->getOptions()->getJavaPackage();
         }
     }
     if ($result) {
         return true;
     } else {
         return false;
     }
 }