コード例 #1
0
 private function getClassElement(KalturaTypeReflector $typeReflector)
 {
     $properties = $typeReflector->getProperties();
     $classElement = $this->_doc->createElement("class");
     $classElement->setAttribute("name", $typeReflector->getType());
     $parentTypeReflector = $typeReflector->getParentTypeReflector();
     if ($typeReflector->isAbstract()) {
         $classElement->setAttribute("abstract", true);
     }
     if ($parentTypeReflector) {
         $parentType = $parentTypeReflector->getType();
         $classElement->setAttribute("base", $parentType);
     }
     $plugin = $this->extractPluginNameFromPackage($typeReflector->getPackage());
     if ($plugin) {
         $classElement->setAttribute("plugin", $plugin);
     }
     $description = $typeReflector->getDescription();
     $description = $this->fixDescription($description);
     $classElement->setAttribute("description", $description);
     $properties = $typeReflector->getCurrentProperties();
     foreach ($properties as $property) {
         /* @var $property KalturaPropertyInfo */
         if ($property->isServerOnly()) {
             continue;
         }
         $propType = $property->getType();
         $propName = $property->getName();
         $propertyElement = $this->_doc->createElement("property");
         $propertyElement->setAttribute("name", $propName);
         if ($property->isAssociativeArray()) {
             $propertyElement->setAttribute("type", "map");
             $propertyElement->setAttribute("arrayType", $property->getArrayType());
         } else {
             if ($property->isArray()) {
                 $propertyElement->setAttribute("type", "array");
                 $propertyElement->setAttribute("arrayType", $property->getArrayType());
             } else {
                 if ($property->isEnum()) {
                     $propertyElement->setAttribute("type", "int");
                     $propertyElement->setAttribute("enumType", $property->getType());
                 } else {
                     if ($property->isStringEnum()) {
                         $propertyElement->setAttribute("type", "string");
                         $propertyElement->setAttribute("enumType", $property->getType());
                     } else {
                         if ($propType == 'KalturaObject') {
                             $propertyElement->setAttribute("type", 'KalturaObjectBase');
                         } else {
                             $propertyElement->setAttribute("type", $propType);
                         }
                     }
                 }
             }
         }
         $propertyElement->setAttribute("readOnly", $property->isReadOnly() ? "1" : "0");
         $propertyElement->setAttribute("insertOnly", $property->isInsertOnly() ? "1" : "0");
         $description = $property->getDescription();
         $description = $this->fixDescription($description);
         $propertyElement->setAttribute("description", $description);
         $classElement->appendChild($propertyElement);
     }
     return $classElement;
 }
 /**
  *
  * 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";
     }
 }