示例#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 writeAfterService(KalturaServiceReflector $serviceReflector)
 {
     $this->writeTest("\t/**");
     $this->writeTest("\t * Called when all tests are done");
     $this->writeTest("\t * @param int \$id");
     $this->writeTest("\t * @return int");
     $this->writeTest("\t * @depends {$this->lastDependencyTest} - TODO: replace {$this->lastDependencyTest} with last test function that uses that id");
     $this->writeTest("\t */");
     $this->writeTest("\tpublic function testFinished(\$id)");
     $this->writeTest("\t{");
     $this->writeTest("\t\treturn \$id;");
     $this->writeTest("\t}");
     $this->writeTest("");
     $this->writeTest("}");
     $this->writeBase("\t/**");
     $this->writeBase("\t * Called when all tests are done");
     $this->writeBase("\t * @param int \$id");
     $this->writeBase("\t * @return int");
     $this->writeBase("\t */");
     $this->writeBase("\tabstract public function testFinished(\$id);");
     $this->writeBase("");
     $this->writeBase("}");
     $serviceName = $serviceReflector->getServiceName();
     $serviceClass = $serviceReflector->getServiceClass();
     $testPath = realpath(dirname(__FILE__) . '/../') . "/tests/api/{$serviceName}";
     if ($serviceReflector->isFromPlugin()) {
         $servicePath = KAutoloader::getClassFilePath($serviceClass);
         $testPath = realpath(dirname($servicePath) . '/../') . "/tests/services/{$serviceName}";
     }
     $this->writeToFile("{$testPath}/{$serviceClass}BaseTest.php", $this->_txtBase);
     $this->writeToFile("{$testPath}/{$serviceClass}Test.php", $this->_txtTest, false);
     $this->writeToFile("{$testPath}/{$serviceClass}Test.php.ini", $this->_txtIni, false);
 }
 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 writeMainClassServiceInitialization(KalturaServiceReflector $serviceReflector)
 {
     $serviceName = $serviceReflector->getServiceName();
     $serviceClassName = "Kaltura" . $this->upperCaseFirstLetter($serviceName) . "Service";
     $this->echoLine("\t\t\$this->{$serviceName} = new {$serviceClassName}(\$this);");
 }
 protected function addService(KalturaServiceReflector $serviceReflector)
 {
     $serviceName = $serviceReflector->getServiceName();
     if ($serviceReflector->isDeprecated()) {
         KalturaLog::info("Service deprecated [{$serviceName}]");
         return;
     }
     if (array_key_exists($serviceName, $this->_services)) {
         throw new Exception("Service already exists [{$serviceName}]");
     }
     $this->_services[$serviceName] = $serviceReflector;
 }