protected function Php5ClientGenerator::writeType in Kaltura 6.2
Same name and namespace in other branches
- 7.3 kaltura_client/Php5ClientGenerator.php \Php5ClientGenerator::writeType()
- 7.2 kaltura_client/Php5ClientGenerator.php \Php5ClientGenerator::writeType()
1 call to Php5ClientGenerator::writeType()
- Php5ClientGenerator::generate in kaltura_client/
Php5ClientGenerator.php
File
- kaltura_client/
Php5ClientGenerator.php, line 68
Class
Code
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();
}
}
}