Ejemplo n.º 1
0
 /**
  * Gets and validates the provided parameter values
  * @param array $parameters Array with Value objects
  * @param array $parameterTypes Array with the expected types for the provided values
  * @return array Array with the actual values
  * @throws zibo\library\xmlrpc\exception\XmlRpcException when the number of parameters is not the same as the number of expected parameters
  * @throws zibo\library\xmlrpc\exception\XmlRpcException when one of the parameters is not of the expected type and could not be converted to it
  */
 private function getCallbackParameters($parameters, $parameterTypes)
 {
     $result = array();
     $countParameters = count($parameters);
     $countParameterTypes = count($parameterTypes);
     if ($countParameters != $countParameterTypes) {
         throw new XmlRpcException('Incorrect parameter count: expecting ' . $countParameterTypes . ' parameters but got ' . $countParameters . '.');
     }
     for ($i = 0; $i < $countParameters; $i++) {
         $expectedType = $parameterTypes[$i];
         $type = $parameters[$i]->getType();
         if ($expectedType != null && $type != $expectedType) {
             try {
                 $value = $parameters[$i]->getValue();
                 $value = Value::convertValue($value, $type, $expectedType);
                 $parameters[$i] = new Value($value, $type);
             } catch (Exception $e) {
                 throw new XmlRpcException('Parameter ' . ($i + 1) . ' is of type ' . $type . ', expecting type ' . $expectedType . ' (' . $e->getMessage() . ')', 0, $e);
             }
         }
         $result[] = $parameters[$i]->getValue();
     }
     return $result;
 }