public function isEnum() { $this->getTypeReflector(); if ($this->_typeReflector) { return $this->_typeReflector->isEnum(); } else { return false; } }
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; }
/** * @param KalturaTypeReflector $a * @param KalturaTypeReflector $b */ protected function compareTypes(KalturaTypeReflector $a, KalturaTypeReflector $b) { // enums at the begining if ($a->isEnum() && !$b->isEnum()) { return -1; } if ($b->isEnum() && !$a->isEnum()) { return 1; } if ($a->isStringEnum() && !$b->isStringEnum()) { return -1; } if ($b->isStringEnum() && !$a->isStringEnum()) { return 1; } if ($a->getInheritanceLevel() != $b->getInheritanceLevel()) { return $a->getInheritanceLevel() < $b->getInheritanceLevel() ? -1 : 1; } return strcmp($a->getType(), $b->getType()); }
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(); } } }
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; }
/** * * Write the outpur data for the test * @param KalturaTypeReflector $outputTypeReflector */ protected function setOutputData($outputTypeReflector, &$testParams, &$testValues, $isBase = false, &$validateValues = null) { $paramType = $outputTypeReflector->getType(); $paramName = $outputTypeReflector->getName(); $this->writeXmlSource("\t\t\t\t<OutputReference name = '{$paramName}' type = '{$paramType}' key = 'Fill the object key' />"); if ($outputTypeReflector->isSimpleType() || $outputTypeReflector->isEnum() || $outputTypeReflector->isDynamicEnum() || $outputTypeReflector->isDynamicEnum()) { $defaultValue = $outputTypeReflector->getDefaultValue(); $this->writeIni("test1.reference = " . $defaultValue); $this->writeXml("\t\t<OutputReference name = '{$paramName}' type = '{$paramType}' key = '{$defaultValue}' />"); } elseif ($outputTypeReflector->isFile()) { $this->writeIni("test1.reference.objectType = file"); $this->writeIni("test1.reference.path = "); //TODO: add support for files in XML $this->writeXml("\t\t<OutputReference name = '{$paramName}' type='file' key='path/to/file'/>"); } else { $this->writeIni("test1.reference.objectType = {$paramType}"); $this->writeXml("\t\t<OutputReference name = '{$paramName}' type = '{$paramType}' key = 'object key'>"); $actionParamProperties = $outputTypeReflector->getTypeReflector()->getProperties(); foreach ($actionParamProperties as $actionParamProperty) { /* @var $actionParamProperty KalturaPropertyInfo */ if ($actionParamProperty->isReadOnly()) { continue; } $propertyType = $actionParamProperty->getType(); $propertyName = $actionParamProperty->getName(); if ($actionParamProperty->isSimpleType() || $actionParamProperty->isEnum() || $actionParamProperty->isDynamicEnum() || $actionParamProperty->isDynamicEnum()) { $paramDefaultValue = $actionParamProperty->getDefaultValue(); $this->writeIni("test1.reference.{$propertyName} = " . $paramDefaultValue); $this->writeXml("\t\t\t<{$propertyName}>{$paramDefaultValue}</{$propertyName}>"); } elseif ($actionParamProperty->isFile()) { $this->writeIni("test1.reference.{$propertyName}.objectType = file"); $this->writeIni("test1.reference.{$propertyName}.path = "); //TODO: add support for files in XML $this->writeXml("\t\t\t<OutputReference name = '{$paramName}' type='file' key= 'path/to/file'>"); } elseif (!$actionParamProperty->isAbstract()) { if ($propertyName == 'type') { //Causes bug in the Zend config $this->writeIni("test1.reference.objType.{$propertyName} = {$propertyType}"); } else { $this->writeIni("test1.reference.{$propertyName}.objectType = {$propertyType}"); } $this->writeXml("\t\t\t<{$propertyName}>{$propertyType}</{$propertyName}>"); } } $this->writeXml("\t\t</OutputReference>"); } $paramDesc = strlen($outputTypeReflector->getDescription()) ? ' ' . $outputTypeReflector->getDescription() : ''; if ($isBase) { $this->writeBase("\t * @param {$paramType} \$reference{$paramDesc}"); } else { $this->writeTest("\t * @param {$paramType} \$reference{$paramDesc}"); } if (!$outputTypeReflector->isComplexType() || $outputTypeReflector->isEnum() || $outputTypeReflector->isStringEnum() || $outputTypeReflector->isDynamicEnum()) { $testParam = "\$reference"; } else { $testParam = "{$paramType} \$reference"; } if ($outputTypeReflector->isOptional()) { if ($outputTypeReflector->getDefaultValue()) { if ($outputTypeReflector->getType() == 'string') { $testParam .= " = '" . $outputTypeReflector->getDefaultValue() . "'"; } else { $testParam .= " = " . $outputTypeReflector->getDefaultValue(); } } else { $testParam .= " = null"; } } $testParams[] = $testParam; if ($isBase) { $validateValues[] = "\$reference"; } else { //write to TestFile $testValues[] = "\$reference"; } }