protected function Php5ClientGenerator::writeServiceAction in Kaltura 7.2
Same name and namespace in other branches
- 6.2 kaltura_client/Php5ClientGenerator.php \Php5ClientGenerator::writeServiceAction()
- 7.3 kaltura_client/Php5ClientGenerator.php \Php5ClientGenerator::writeServiceAction()
1 call to Php5ClientGenerator::writeServiceAction()
- Php5ClientGenerator::generate in kaltura_client/
Php5ClientGenerator.php
File
- kaltura_client/
Php5ClientGenerator.php, line 166
Class
Code
protected function writeServiceAction($serviceName, $action, $actionParams, $outputTypeReflector) {
$outputType = null;
if ($outputTypeReflector) {
$outputType = $outputTypeReflector
->getType();
}
// method signature
$signature = "";
if (in_array($action, array(
"list",
"clone",
))) {
// because list & clone are preserved in PHP
$signature .= "function " . $action . "Action(";
}
else {
$signature .= "function " . $action . "(";
}
foreach ($actionParams as $actionParam) {
$paramName = $actionParam
->getName();
if ($actionParam
->isSimpleType() || $actionParam
->isEnum()) {
$signature .= "\$" . $paramName;
}
else {
if ($actionParam
->isArray()) {
$signature .= "array \$" . $paramName;
}
else {
if ($actionParam
->isComplexType()) {
$signature .= $actionParam
->getType() . " \$" . $paramName;
}
}
}
if ($actionParam
->isOptional()) {
if ($actionParam
->isSimpleType() || $actionParam
->isEnum()) {
$defaultValue = $actionParam
->getDefaultValue();
if ($defaultValue === false) {
$signature .= " = false";
}
else {
if ($defaultValue === true) {
$signature .= " = true";
}
else {
if ($defaultValue === null) {
$signature .= " = null";
}
else {
if (is_string($defaultValue)) {
$signature .= " = \"{$defaultValue}\"";
}
else {
if (is_numeric($defaultValue)) {
$signature .= " = {$defaultValue}";
}
}
}
}
}
}
else {
$signature .= " = null";
}
}
$signature .= ", ";
}
if ($this
->endsWith($signature, ", ")) {
$signature = substr($signature, 0, strlen($signature) - 2);
}
$signature .= ")";
$this
->echoLine();
$this
->echoLine("\t{$signature}");
$this
->echoLine("\t{");
$this
->echoLine("\t\t\$kparams = array();");
foreach ($actionParams as $actionParam) {
$paramName = $actionParam
->getName();
if ($actionParam
->isComplexType()) {
if ($actionParam
->isEnum()) {
$this
->echoLine("\t\t\$this->client->addParam(\$kparams, \"{$paramName}\", \${$paramName});");
}
else {
if ($actionParam
->isArray()) {
$extraTab = "";
if ($actionParam
->isOptional()) {
$this
->echoLine("\t\tif (\${$paramName} !== null)");
$extraTab = "\t";
}
$this
->echoLine("{$extraTab}\t\tforeach({$paramName} as \$obj)");
$this
->echoLine("{$extraTab}\t\t{");
$this
->echoLine("{$extraTab}\t\t\t\$this->client->addParam(\$kparams, \"{$paramName}\", \$obj->toParams());");
$this
->echoLine("{$extraTab}\t\t}");
}
else {
$extraTab = "";
if ($actionParam
->isOptional()) {
$this
->echoLine("\t\tif (\${$paramName} !== null)");
$extraTab = "\t";
}
$this
->echoLine("{$extraTab}\t\t\$this->client->addParam(\$kparams, \"{$paramName}\", \${$paramName}" . "->toParams());");
}
}
}
else {
$this
->echoLine("\t\t\$this->client->addParam(\$kparams, \"{$paramName}\", \${$paramName});");
}
}
$this
->echoLine("\t\t\$resultObject = \$this->client->callService(\"{$serviceName}\", \"{$action}\", \$kparams);");
$this
->echoLine("\t\t\$this->client->throwExceptionIfError(\$resultObject);");
if (!$outputTypeReflector) {
$outputType = "null";
}
if ($outputTypeReflector && $outputTypeReflector
->isArray()) {
$outputType = "array";
}
$this
->echoLine("\t\t\$this->client->validateObjectType(\$resultObject, \"{$outputType}\");");
$this
->echoLine("\t\treturn \$resultObject;");
$this
->echoLine("\t}");
}