require_once "../../bootstrap.php"; KalturaLog::setContext("TESTME"); $service = $_GET["service"]; $action = $_GET["action"]; $bench_start = microtime(true); KalturaLog::INFO(">------- api_v3 testme [{$service}][{$action}]-------"); function toArrayRecursive(KalturaPropertyInfo $propInfo) { return $propInfo->toArray(); } $serviceMap = KalturaServicesMap::getMap(); $actionInfo = null; try { $serviceReflector = $serviceMap[strtolower($service)]; /* @var $serviceReflector KalturaServiceActionItem */ $actionReflector = new KalturaActionReflector($service, $action, $serviceReflector->actionMap[$action]); $actionParams = $actionReflector->getActionParams(); $actionInfo = $actionReflector->getActionInfo(); $actionInfo = array("actionParams" => array(), "description" => $actionInfo->description); foreach ($actionParams as $actionParam) { $actionInfo["actionParams"][] = toArrayRecursive($actionParam); } } catch (Exception $ex) { KalturaLog::ERR("<------- api_v3 testme [{$service}][{$action}\n" . $ex->__toString() . " " . " -------"); } //echo "<pre>"; //echo print_r($actionInfo); echo json_encode($actionInfo); $bench_end = microtime(true); KalturaLog::INFO("<------- api_v3 testme [{$service}][{$action}][" . ($bench_end - $bench_start) . "] -------");
private function getServiceActionElement(KalturaActionReflector $actionReflector) { $outputTypeReflector = $actionReflector->getActionOutputType(); $actionInfo = $actionReflector->getActionInfo(); $actionParams = $actionReflector->getActionParams(); $outputType = null; if ($outputTypeReflector) { $outputType = $outputTypeReflector->getType(); } $actionElement = $this->_doc->createElement("action"); $actionElement->setAttribute("name", $actionReflector->getActionName()); foreach ($actionParams as $actionParam) { /* @var $actionParam KalturaParamInfo */ $actionParamElement = $this->_doc->createElement("param"); $actionParamElement->setAttribute("name", $actionParam->getName()); if ($actionParam->isAssociativeArray()) { $actionParamElement->setAttribute("type", "map"); $actionParamElement->setAttribute("arrayType", $actionParam->getArrayType()); } elseif ($actionParam->isArray()) { $actionParamElement->setAttribute("type", "array"); $actionParamElement->setAttribute("arrayType", $actionParam->getArrayType()); } elseif ($actionParam->isEnum()) { $actionParamElement->setAttribute("type", "int"); $actionParamElement->setAttribute("enumType", $actionParam->getType()); } else { if ($actionParam->isStringEnum()) { $actionParamElement->setAttribute("type", "string"); $actionParamElement->setAttribute("enumType", $actionParam->getType()); } else { $actionParamElement->setAttribute("type", $actionParam->getType()); } } $actionParamElement->setAttribute("optional", $actionParam->isOptional() ? "1" : "0"); if ($actionParam->isOptional()) { $defaultValue = $actionParam->getDefaultValue(); if ($defaultValue === null) { $defaultValue = "null"; } switch ($actionParam->getType()) { case "bool": if ($defaultValue === true) { $actionParamElement->setAttribute("default", "true"); } else { if ($defaultValue === false) { $actionParamElement->setAttribute("default", "false"); } } break; case "bigint": case "int": case "float": case "string": $actionParamElement->setAttribute("default", $defaultValue); break; default: if ($actionParam->isEnum()) { $actionParamElement->setAttribute("default", $defaultValue); } else { $actionParamElement->setAttribute("default", "null"); } } } $description = $actionParam->getDescription(); $description = $this->fixDescription($description); $actionParamElement->setAttribute("description", $description); $actionElement->appendChild($actionParamElement); } $resultElement = $this->_doc->createElement("result"); $arrayType = null; if ($outputTypeReflector) { if ($outputTypeReflector->isAssociativeArray()) { $resultElement->setAttribute("type", "map"); $arrayType = $outputTypeReflector->getArrayType(); $resultElement->setAttribute("arrayType", $arrayType); } else { if ($outputTypeReflector->isArray()) { $resultElement->setAttribute("type", "array"); $arrayType = $outputTypeReflector->getArrayType(); $resultElement->setAttribute("arrayType", $arrayType); } else { $resultElement->setAttribute("type", $outputType); } } } $description = $actionInfo->description; $description = $this->fixDescription($description); $actionElement->setAttribute("description", kString::stripUtf8InvalidChars($description)); $actionElement->setAttribute("enableInMultiRequest", $outputType === 'file' ? "0" : "1"); $actionElement->appendChild($resultElement); return $actionElement; }
protected function shouldUseServiceAction(KalturaActionReflector $actionReflector) { $serviceId = $actionReflector->getServiceId(); if ($actionReflector->getActionClassInfo()->serverOnly) { KalturaLog::info("Service [" . $serviceId . "] is server only"); return false; } $actionId = $actionReflector->getActionId(); if (strpos($actionReflector->getActionInfo()->clientgenerator, "ignore") !== false) { KalturaLog::info("Action [{$actionId}] in service [{$serviceId}] ignored by generator"); return false; } if (isset($this->_serviceActions[$serviceId]) && isset($this->_serviceActions[$serviceId][$actionId])) { KalturaLog::err("Service [{$serviceId}] action [{$actionId}] already exists!"); return false; } return true; }
public function dispatch($service, $action, $params = array()) { $start = microtime(true); // prevent impersonate to partner zero $p = isset($params["p"]) && $params["p"] ? $params["p"] : null; if (!$p) { $p = isset($params["partnerId"]) && $params["partnerId"] ? $params["partnerId"] : null; } $GLOBALS["partnerId"] = $p; // set for logger $userId = ""; $ksStr = isset($params["ks"]) ? $params["ks"] : null; if (!$service) { throw new KalturaAPIException(KalturaErrors::SERVICE_NOT_SPECIFIED); } //strtolower on service - map is indexed according to lower-case service IDs $service = strtolower($service); $serviceActionItem = KalturaServicesMap::retrieveServiceActionItem($service, $action); $action = strtolower($action); if (!isset($serviceActionItem->actionMap[$action])) { KalturaLog::crit("Action does not exist!"); throw new KalturaAPIException(KalturaErrors::ACTION_DOES_NOT_EXISTS, $action, $service); } try { $actionReflector = new KalturaActionReflector($service, $action, $serviceActionItem->actionMap[$action]); } catch (Exception $e) { throw new Exception("Could not create action reflector for service [{$service}], action [{$action}]. Received error: " . $e->getMessage()); } $actionParams = $actionReflector->getActionParams(); $actionInfo = $actionReflector->getActionInfo(); // services.ct - check if partner is allowed to access service ... kCurrentContext::$host = isset($_SERVER["HOSTNAME"]) ? $_SERVER["HOSTNAME"] : gethostname(); kCurrentContext::$user_ip = requestUtils::getRemoteAddress(); kCurrentContext::$ps_vesion = "ps3"; kCurrentContext::$service = $serviceActionItem->serviceInfo->serviceName; kCurrentContext::$action = $action; kCurrentContext::$client_lang = isset($params['clientTag']) ? $params['clientTag'] : null; kCurrentContext::initKsPartnerUser($ksStr, $p, $userId); // validate it's ok to access this service $deserializer = new KalturaRequestDeserializer($params); $this->arguments = $deserializer->buildActionArguments($actionParams); KalturaLog::debug("Dispatching service [" . $service . "], action [" . $action . "], reqIndex [" . kCurrentContext::$multiRequest_index . "] with params " . print_r($this->arguments, true)); $responseProfile = $deserializer->getResponseProfile(); if ($responseProfile) { KalturaLog::debug("Response profile: " . print_r($responseProfile, true)); } kPermissionManager::init(kConf::get('enable_cache')); kEntitlementUtils::initEntitlementEnforcement(); $disableTags = $actionInfo->disableTags; if ($disableTags && is_array($disableTags) && count($disableTags)) { foreach ($disableTags as $disableTag) { KalturaCriterion::disableTag($disableTag); } } if ($actionInfo->validateUserObjectClass && $actionInfo->validateUserIdParamName && isset($actionParams[$actionInfo->validateUserIdParamName])) { // // TODO maybe if missing should throw something, maybe a bone? // if(!isset($actionParams[$actionInfo->validateUserIdParamName])) // throw new KalturaAPIException(KalturaErrors::MISSING_MANDATORY_PARAMETER, $actionInfo->validateUserIdParamName); KalturaLog::debug("validateUserIdParamName: " . $actionInfo->validateUserIdParamName); $objectId = $params[$actionInfo->validateUserIdParamName]; $this->validateUser($actionInfo->validateUserObjectClass, $objectId, $actionInfo->validateUserPrivilege, $actionInfo->validateOptions); } // initialize the service before invoking the action on it // action reflector will init the service to maintain the pluginable action transparency $actionReflector->initService($responseProfile); $invokeStart = microtime(true); KalturaLog::debug("Invoke start"); try { $res = $actionReflector->invoke($this->arguments); } catch (KalturaAPIException $e) { if ($actionInfo->returnType != 'file') { throw $e; } KalturaResponseCacher::adjustApiCacheForException($e); $res = new kRendererDieError($e->getCode(), $e->getMessage()); } kEventsManager::flushEvents(); KalturaLog::debug("Invoke took - " . (microtime(true) - $invokeStart) . " seconds"); KalturaLog::debug("Dispatch took - " . (microtime(true) - $start) . " seconds, memory: " . memory_get_peak_usage(true)); return $res; }
</tr> <?php } ?> <tr> <td class="title">Description</td> <td><?php echo nl2br($serviceInfo->description); ?> </td> </tr> <tr> <td class="title">Actions</td> <td class="odd"> <table cellspacing="0" class="service_actions"> <tr> <th>Name</th> <th>Description</th> </tr> <?php foreach ($actions as $actionId => $actionCallback) { $actionReflector = new KalturaActionReflector($service, $actionId, $actionCallback); $actionInfo = $actionReflector->getActionInfo(); echo '<tr><td><a href="?service=' . $service . '&action=' . $actionId . '">' . $actionReflector->getActionName() . '</td><td>' . nl2br($actionInfo->description) . '</td></tr>'; } ?> </table> </td> </tr> </table>
<?php require_once "../../bootstrap.php"; KalturaLog::setContext("TESTME"); $service = $_GET["service"]; $serviceMap = KalturaServicesMap::getMap(); $serviceActionItem = $serviceMap[strtolower($service)]; if (!$service) { exit; } /* @var $serviceActionItem KalturaServiceActionItem */ $actionsArray = $serviceActionItem->actionMap; $actionNames = array_keys($actionsArray); sort($actionNames); $actions = array(); foreach ($actionNames as $actionName) { $actionReflector = new KalturaActionReflector($service, $actionName, $actionsArray[$actionName]); $actionInfo = $actionReflector->getActionInfo(); $actionDisplayName = $actionReflector->getActionId(); $actionLabel = $actionReflector->getActionName(); if ($actionInfo->deprecated) { $actionLabel .= ' (deprecated)'; } $actions[] = array('action' => $actionName, 'name' => $actionName, 'label' => $actionLabel); } echo json_encode($actions);
<?php $serviceMap = KalturaServicesMap::getMap(); $serviceReflector = $serviceMap[strtolower($service)]; if (!$serviceReflector) { die('Service "' . $service . '" not found'); } /* @var $serviceReflector KalturaServiceActionItem */ $actions = $serviceReflector->actionMap; try { $actionReflector = new KalturaActionReflector($service, $action, $actions[$action]); $actionParams = $actionReflector->getActionParams($action); } catch (Exception $ex) { die('Action "' . $action . '" does not exist for service "' . $service . '"'); } $actionInfo = $actionReflector->getActionInfo(); ?> <h2>Kaltura API</h2> <table class="action"> <tr> <th colspan="5" class="service_action_title"><?php echo $service; ?> :<?php echo $action; ?> </th> </tr> <?php $description = trim(nl2br($actionInfo->description)); if ($description) {