/** * <MethodDescription> * * @param mixed <description> * * @return mixed <description> */ function translate($type) { # complex types if (is_string($type) && class_exists($type)) { return array(STUDIP_WS_TYPE_STRUCT => $type); } # array types if (is_array($type)) { if (!sizeof($type)) { trigger_error('Array of missing type.', E_USER_ERROR); return array(STUDIP_WS_TYPE_NULL => NULL); } $element_type = current($type); if (is_null($element_type)) { trigger_error(sprintf('Array of unknown type: %s', var_export($element_type, TRUE)), E_USER_ERROR); return array(STUDIP_WS_TYPE_NULL => NULL); } return array(STUDIP_WS_TYPE_ARRAY => Studip_Ws_Type::translate($element_type)); } # basic types if (is_string($type)) { switch ($type) { case 'int': case 'integer': return array(STUDIP_WS_TYPE_INT => NULL); case 'string': case 'text': return array(STUDIP_WS_TYPE_STRING => NULL); case 'base64': return array(STUDIP_WS_TYPE_BASE64 => NULL); case 'bool': case 'boolean': return array(STUDIP_WS_TYPE_BOOL => NULL); case 'float': case 'double': return array(STUDIP_WS_TYPE_FLOAT => NULL); case 'null': return array(STUDIP_WS_TYPE_NULL => NULL); } } # type by example $type_checkers = array('is_bool' => STUDIP_WS_TYPE_BOOL, 'is_float' => STUDIP_WS_TYPE_FLOAT, 'is_int' => STUDIP_WS_TYPE_INT, 'is_string' => STUDIP_WS_TYPE_STRING, 'is_null' => STUDIP_WS_TYPE_NULL); foreach ($type_checkers as $function => $replacement) { if ($function($type)) { return array($replacement => NULL); } } trigger_error('"' . gettype($type) . '" is not a valid type.'); return array(STUDIP_WS_TYPE_NULL => NULL); }
/** * <MethodDescription> * * @param type <description> * * @return type <description> */ function Studip_Ws_Method(&$service, $name, $expects = NULL, $returns = NULL, $description = '') { # check $expects if (is_null($expects)) { $expects = array(); } else { if (!is_array($expects)) { trigger_error('Third argument is expected to be an array.', E_USER_ERROR); return; } } $this->service =& $service; $this->name = $name; $this->description = (string) $description; $this->expects = $expects; $this->returns = $returns; foreach ($this->expects as $key => $entry) { $this->expects[$key] = Studip_Ws_Type::translate($entry); } $this->returns = Studip_Ws_Type::translate($this->returns); }
/** * Constructor. * * @param string the name of the element. * @param mixed the type of the element. * @param array options for the element. * * @return void */ function Studip_Ws_StructElement($name, $type, $options = array()) { $this->name = (string) $name; $this->type = Studip_Ws_Type::translate($type); $this->options = $options; }