コード例 #1
0
 public function dispatch($service, $action, $params = array())
 {
     KalturaLog::debug("Dispatching service [" . $service . "], action [" . $action . "] with params " . print_r($params, true));
     $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);
     }
     try {
         // load the service reflector
         $reflector = new KalturaServiceReflector($service);
     } catch (Exception $ex) {
         throw new KalturaAPIException(KalturaErrors::SERVICE_DOES_NOT_EXISTS, $service);
     }
     // check if action exists
     if (!$action) {
         throw new KalturaAPIException(KalturaErrors::ACTION_NOT_SPECIFIED, $service);
     }
     if (!$reflector->isActionExists($action)) {
         throw new KalturaAPIException(KalturaErrors::ACTION_DOES_NOT_EXISTS, $action, $service);
     }
     $actionParams = $reflector->getActionParams($action);
     // services.ct - check if partner is allowed to access service ...
     // validate it's ok to access this service
     $deserializer = new KalturaRequestDeserializer($params);
     $arguments = $deserializer->buildActionArguments($actionParams);
     $serviceInstance = $reflector->getServiceInstance();
     kCurrentContext::$host = isset($_SERVER["HOSTNAME"]) ? $_SERVER["HOSTNAME"] : null;
     kCurrentContext::$user_ip = requestUtils::getRemoteAddress();
     kCurrentContext::$ps_vesion = "ps3";
     kCurrentContext::$service = $reflector->getServiceName();
     kCurrentContext::$action = $action;
     kCurrentContext::$client_lang = isset($params['clientTag']) ? $params['clientTag'] : null;
     kCurrentContext::initKsPartnerUser($ksStr, $p, $userId);
     kPermissionManager::init(kConf::get('enable_cache'));
     // initialize the service before invoking the action on it
     $serviceInstance->initService($reflector->getServiceId(), $reflector->getServiceName(), $action);
     $invokeStart = microtime(true);
     KalturaLog::debug("Invoke start");
     $res = $reflector->invoke($action, $arguments);
     KalturaLog::debug("Invoke took - " . (microtime(true) - $invokeStart) . " seconds");
     KalturaLog::debug("Disptach took - " . (microtime(true) - $start) . " seconds");
     $this->clearMemory();
     return $res;
 }
コード例 #2
0
 protected function writeService(KalturaServiceReflector $serviceReflector)
 {
     $serviceName = $serviceReflector->getServiceName();
     $serviceId = $serviceReflector->getServiceId();
     $serviceClass = $serviceReflector->getServiceClass();
     $actions = $serviceReflector->getActions();
     foreach ($actions as $action => $actionName) {
         $actionInfo = $serviceReflector->getActionInfo($action);
         if ($actionInfo->deprecated || $actionInfo->serverOnly) {
             continue;
         }
         if (strpos($actionInfo->clientgenerator, "ignore") !== false) {
             continue;
         }
         $outputTypeReflector = $serviceReflector->getActionOutputType($action);
         $actionParams = $serviceReflector->getActionParams($action);
         $this->writeServiceAction($serviceId, $serviceName, $actionInfo->action, $actionParams, $outputTypeReflector);
     }
 }
コード例 #3
0
 private function testSingleService($service, $testedClient, $permissions, $alwaysAllowedActions)
 {
     $serviceReflector = new KalturaServiceReflector($service);
     $actions = array_keys($serviceReflector->getActions());
     $serviceName = $serviceReflector->getServiceName();
     foreach ($actions as $action) {
         // Params
         $actionParams = $serviceReflector->getActionParams($action);
         $params = array();
         foreach ($actionParams as $actionParam) {
             $actionName = $actionParam->getName();
             $typeName = $actionParam->getType();
             if ($typeName == "KalturaPermissionItem") {
                 $params[] = new KalturaApiActionPermissionItem();
                 continue;
             }
             if ($actionParam->isComplexType()) {
                 if ($actionParam->isArray()) {
                     $params[] = array();
                 } else {
                     $type = $actionParam->getTypeReflector();
                     if ($type != null) {
                         if (!$type->isAbstract()) {
                             $params[] = $type->getInstance();
                         } else {
                             //TODO: handle abstract classes
                             $params[] = new KalturaApiActionPermissionItem();
                         }
                     } else {
                         $params[] = null;
                     }
                 }
             } else {
                 $params[] = 0;
             }
         }
         if ($action == "list") {
             $action .= "Action";
         }
         try {
             call_user_func_array(array($testedClient->{$serviceName}, $action), $params);
             //TODO: Handle non exception cases
             $this->compareServiceAction($permissions, $alwaysAllowedActions, $serviceName, $action);
         } catch (Exception $ex) {
             //Check if the service / action is found in the user permissions
             $this->compareServiceAction($permissions, $alwaysAllowedActions, $serviceName, $action, $ex);
         }
     }
 }
コード例 #4
0
 private function getServiceActionElement(KalturaServiceReflector $serviceReflector, $actionId)
 {
     $outputTypeReflector = $serviceReflector->getActionOutputType($actionId);
     $actionInfo = $serviceReflector->getActionInfo($actionId);
     $actionParams = $serviceReflector->getActionParams($actionId);
     $outputType = null;
     if ($outputTypeReflector) {
         $outputType = $outputTypeReflector->getType();
     }
     $actionElement = $this->_doc->createElement("action");
     $actionElement->setAttribute("name", $actionInfo->action);
     foreach ($actionParams as $actionParam) {
         $actionParamElement = $this->_doc->createElement("param");
         $actionParamElement->setAttribute("name", $actionParam->getName());
         if ($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()) {
             switch ($actionParam->getType()) {
                 case "bool":
                     if ($actionParam->getDefaultValue() === true) {
                         $actionParamElement->setAttribute("default", "true");
                     } else {
                         if ($actionParam->getDefaultValue() === false) {
                             $actionParamElement->setAttribute("default", "false");
                         }
                     }
                     break;
                 case "int":
                 case "float":
                 case "string":
                     if ($actionParam->getDefaultValue() === null) {
                         $actionParamElement->setAttribute("default", "null");
                     } else {
                         $actionParamElement->setAttribute("default", $actionParam->getDefaultValue());
                     }
                     break;
                 default:
                     if ($actionParam->isEnum()) {
                         $actionParamElement->setAttribute("default", $actionParam->getDefaultValue());
                     } 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->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", $description);
     $actionElement->appendChild($resultElement);
     return $actionElement;
 }
コード例 #5
0
<?php

try {
    $serviceReflector = new KalturaServiceReflector($service);
} catch (Exception $ex) {
    die('Service "' . $service . '" not found');
}
$actions = $serviceReflector->getActions();
try {
    $actionParams = $serviceReflector->getActionParams($action);
} catch (Exception $ex) {
    die('Action "' . $action . '" does not exist for service "' . $service . '"');
}
$actionInfo = $serviceReflector->getActionInfo($action);
?>
<h2>Kaltura API</h2>
<table class="action">
	<tr>
		<th colspan="3" class="service_action_title"><?php 
echo $service;
?>
:<?php 
echo $action;
?>
</th>
	</tr>
	<tr>
		<td  colspan="3" class="title">Description:</td>
	</tr>
	<tr>
		<td class="description" colspan="3"><?php