Ejemplo n.º 1
0
 /**
  * Action returns array of the parameters the action method expects
  * @return array<KalturaParamInfo>
  */
 public function getActionParams()
 {
     if (is_null($this->_actionParams)) {
         // reflect the service
         $reflectionClass = new ReflectionClass($this->_actionClass);
         $reflectionMethod = $reflectionClass->getMethod($this->_actionMethodName);
         $docComment = $reflectionMethod->getDocComment();
         $reflectionParams = $reflectionMethod->getParameters();
         $this->_actionParams = array();
         foreach ($reflectionParams as $reflectionParam) {
             $name = $reflectionParam->getName();
             if (in_array($name, $this->_reservedKeys)) {
                 throw new Exception("Param [{$name}] in action [{$this->_actionMethodName}] is a reserved key");
             }
             $parsedDocComment = new KalturaDocCommentParser($docComment, array(KalturaDocCommentParser::DOCCOMMENT_REPLACENET_PARAM_NAME => $name));
             $paramClass = $reflectionParam->getClass();
             // type hinting for objects
             if ($paramClass) {
                 $type = $paramClass->getName();
             } else {
                 $result = null;
                 if ($parsedDocComment->param) {
                     $type = $parsedDocComment->param;
                 } else {
                     throw new Exception("Type not found in doc comment for param [" . $name . "] in action [" . $this->_actionMethodName . "] in service [" . $this->_serviceId . "]");
                 }
             }
             $paramInfo = new KalturaParamInfo($type, $name);
             $paramInfo->setDescription($parsedDocComment->paramDescription);
             if ($reflectionParam->isOptional()) {
                 $paramInfo->setDefaultValue($reflectionParam->getDefaultValue());
                 $paramInfo->setOptional(true);
             } else {
                 if ($reflectionParam->getClass() && $reflectionParam->allowsNull()) {
                     $paramInfo->setOptional(true);
                 }
             }
             if (array_key_exists($name, $parsedDocComment->validateConstraints)) {
                 $paramInfo->setConstraints($parsedDocComment->validateConstraints[$name]);
             }
             if (in_array($name, $parsedDocComment->disableRelativeTimeParams, true)) {
                 $paramInfo->setDisableRelativeTime(true);
             }
             $this->_actionParams[$name] = $paramInfo;
         }
     }
     return $this->_actionParams;
 }
Ejemplo n.º 2
0
 public function getActionParams($actionName)
 {
     if (!$this->isActionExists($actionName)) {
         throw new Exception("Action [{$actionName}] does not exists for service [{$this->_serviceId}]");
     }
     $actionId = strtolower($actionName);
     $methodName = $this->_actions[$actionId];
     // reflect the service
     $reflectionClass = new ReflectionClass($this->_serviceClass);
     $reflectionMethod = $reflectionClass->getMethod($methodName);
     $docComment = $reflectionMethod->getDocComment();
     $reflectionParams = $reflectionMethod->getParameters();
     $actionParams = array();
     foreach ($reflectionParams as $reflectionParam) {
         $name = $reflectionParam->getName();
         if (in_array($name, $this->_reservedKeys)) {
             throw new Exception("Param [{$name}] in action [{$actionName}] is a reserved key");
         }
         $parsedDocComment = new KalturaDocCommentParser($docComment, array(KalturaDocCommentParser::DOCCOMMENT_REPLACENET_PARAM_NAME => $name));
         $paramClass = $reflectionParam->getClass();
         // type hinting for objects
         if ($paramClass) {
             $type = $paramClass->getName();
         } else {
             $result = null;
             if ($parsedDocComment->param) {
                 $type = $parsedDocComment->param;
             } else {
                 throw new Exception("Type not found in doc comment for param [" . $name . "] in action [" . $actionName . "] in service [" . $this->_serviceId . "]");
             }
         }
         $paramInfo = new KalturaParamInfo($type, $name);
         $paramInfo->setDescription($parsedDocComment->paramDescription);
         if ($reflectionParam->isOptional()) {
             $paramInfo->setDefaultValue($reflectionParam->getDefaultValue());
             $paramInfo->setOptional(true);
         } else {
             if ($reflectionParam->getClass() && $reflectionParam->allowsNull()) {
                 $paramInfo->setOptional(true);
             }
         }
         $actionParams[] = $paramInfo;
     }
     return $actionParams;
 }