/** * Registers a service to this server instance * @param string $name The name of the service * @param string|array|zibo\library\Callback $callback The callback with the logic of the service * @param string $returnType The type of the resulting value * @param array $parameterTypes The types of parameters for this service * @param string $description A description of this service * @return null * @throws zibo\library\xmlrpc\exception\XmlRpcException when the name of the service is empty * @throws zibo\library\xmlrpc\exception\XmlRpcException when the name of the service is already used by another service * @throws zibo\library\xmlrpc\exception\XmlRpcException when a invalid return type or parameter type has been detected * @throws zibo\library\xmlrpc\exception\XmlRpcException when the description is not a valid string */ public function registerService($name, $callback, $returnType = 'string', $parameterTypes = null, $description = null) { if (String::isEmpty($name)) { throw new XmlRpcException('Name of the service is empty'); } if (isset($this->services[$name])) { throw new XmlRpcException($name . ' service already registered'); } $callback = new Callback($callback); if (!Value::isValidType($returnType)) { throw new XmlRpcException('Return type ' . $returnType . ' is not a valid type'); } if ($parameterTypes == null) { $parameterTypes = array(); } elseif (!is_array($parameterTypes)) { $parameterTypes = array($parameterTypes); } foreach ($parameterTypes as $type) { if (!Value::isValidType($type)) { throw new XmlRpcException('Parameter type ' . $type . ' is not a valid type'); } } if ($description != null && !is_string($description)) { throw new XmlRpcException('Provided description is not a string'); } $service = array(self::SERVICE_CALLBACK => $callback, self::SERVICE_RETURN_TYPE => $returnType, self::SERVICE_PARAMETERS_TYPES => $parameterTypes, self::SERVICE_DESCRIPTION => $description); $this->services[$name] = $service; }