Пример #1
0
 protected function writeType(KalturaTypeReflector $typeReflector)
 {
     $type = $typeReflector->getType();
     if ($typeReflector->isEnum()) {
         $contants = $typeReflector->getConstants();
         $this->echoLine("class {$type}");
         $this->echoLine("{");
         foreach ($contants as $contant) {
             $name = $contant->getName();
             $value = $contant->getDefaultValue();
             $this->echoLine("\tconst {$name} = {$value};");
         }
         $this->echoLine("}");
         $this->echoLine();
     } else {
         if (!$typeReflector->isArray()) {
             // class definition
             $properties = $typeReflector->getProperties();
             $this->echoLine("class {$type} extends KalturaObjectBase");
             $this->echoLine("{");
             // class properties
             foreach ($properties as $property) {
                 $propType = $property->getType();
                 $propName = $property->getName();
                 $this->echoLine("\t/**");
                 $description = str_replace("\n", "\n\t * ", $property->getDescription());
                 // to format multiline descriptions
                 $this->echoLine("\t * " . $description);
                 $this->echoLine("\t *");
                 $this->echoLine("\t * @var {$propType}");
                 if ($property->isReadOnly()) {
                     $this->echoLine("\t * @readonly");
                 }
                 if ($property->isInsertOnly()) {
                     $this->echoLine("\t * @insertonly");
                 }
                 $this->echoLine("\t */");
                 $propertyLine = "public \${$propName}";
                 if ($property->isSimpleType() || $property->isEnum()) {
                     $propertyLine .= " = null";
                 }
                 $this->echoLine("\t{$propertyLine};");
                 $this->echoLine("");
             }
             $this->echoLine();
             $this->echoLine("\tpublic function toParams()");
             $this->echoLine("\t{");
             $this->echoLine("\t\t\$kparams = array();");
             foreach ($properties as $property) {
                 $propType = $property->getType();
                 $propName = $property->getName();
                 if ($property->isSimpleType() || $property->isEnum()) {
                     $this->echoLine("\t\t\$this->addIfNotNull(\$kparams, \"{$propName}\", \$this->{$propName});");
                 } else {
                     continue;
                     // ignore sub objects and arrays
                 }
             }
             $this->echoLine("\t\treturn \$kparams;");
             $this->echoLine("\t}");
             // close class
             $this->echoLine("}");
             $this->echoLine();
         }
     }
 }
Пример #2
0
 private function getEnumElement(KalturaTypeReflector $typeReflector)
 {
     $enumElement = $this->_doc->createElement("enum");
     $enumElement->setAttribute("name", $typeReflector->getType());
     if ($typeReflector->isEnum()) {
         $enumElement->setAttribute("enumType", "int");
     } else {
         if ($typeReflector->isStringEnum()) {
             $enumElement->setAttribute("enumType", "string");
         }
     }
     $plugin = $this->extractPluginNameFromPackage($typeReflector->getPackage());
     if ($plugin) {
         $enumElement->setAttribute("plugin", $plugin);
     }
     $constants = array();
     foreach ($typeReflector->getConstants() as $contant) {
         $name = $contant->getName();
         $value = $contant->getDefaultValue();
         $constants[$name] = $value;
     }
     asort($constants);
     foreach ($constants as $name => $value) {
         $const = $this->_doc->createElement("const");
         $const->setAttribute("name", $name);
         $const->setAttribute("value", $value);
         $enumElement->appendChild($const);
     }
     return $enumElement;
 }
Пример #3
0
 private function getEnumElement(KalturaTypeReflector $typeReflector)
 {
     $enumElement = $this->_doc->createElement("enum");
     $enumElement->setAttribute("name", $typeReflector->getType());
     if ($typeReflector->isEnum()) {
         $enumElement->setAttribute("enumType", "int");
     } else {
         if ($typeReflector->isStringEnum()) {
             $enumElement->setAttribute("enumType", "string");
         }
     }
     $package = $typeReflector->getPackage();
     if (is_string($package)) {
         $packages = explode('.', $package, 2);
         if (count($packages) == 2 && $packages[0] == 'plugins') {
             $enumElement->setAttribute("plugin", $packages[1]);
         }
     }
     $contants = $typeReflector->getConstants();
     foreach ($contants as $contant) {
         $name = $contant->getName();
         $value = $contant->getDefaultValue();
         $const = $this->_doc->createElement("const");
         $const->setAttribute("name", $name);
         $const->setAttribute("value", $value);
         $enumElement->appendChild($const);
     }
     return $enumElement;
 }