private function validate($args) { foreach ($args as $name => $value) { if ($name[0] != '_') { datatype::assert($this->params[$name], $value); } } }
private function preprocess(&$params) { foreach ($this->params as $name => $options) { if (isset($options->type)) { datatype::assert($options->type, $params[$name]); } if (isset($options->filter) and $options->filter == 'json') { $params[$name] = json\encode($params[$name]); } } }
function call($get, $post) { $args = []; foreach ($this->get as $name => $param) { if (isset($param->domains) and isset($get[$name])) { if (($value = security::unwrap($get[$name], $param->domains)) !== null) { $get[$name] = $value; } else { unset($get[$name]); } } $value = isset($get[$name]) ? $get[$name] : (isset($param->default) ? $param->default : ($param->required ? backend_error('bad_input', "Missing GET parameter: {$name}") : null)); if (!is_null($value)) { $min = isset($param->min) ? $param->min : null; $max = isset($param->max) ? $param->max : null; !isset($param->type) or datatype::assert($param->type, $value, $min, $max); $args[$name] = $value; } } foreach ($this->post as $name => $param) { if (isset($param->domains) and isset($post[$name])) { if (($value = security::unwrap($post[$name], $param->domains)) !== null) { $post[$name] = $value; } else { unset($post[$name]); } } $value = isset($post[$name]) ? $post[$name] : (isset($param->default) ? $param->default : ($param->required ? backend_error('bad_input', "Missing POST parameter: {$name}") : null)); if (!is_null($value)) { $min = isset($param->min) ? $param->min : null; $max = isset($param->max) ? $param->max : null; !isset($param->type) or datatype::assert($param->type, $value, $min, $max); $args[$name] = $value; } } if ($this->access and !$this->www->parse_query($this->access, $args)) { return [false, null]; } if ($this->body) { return [true, $this->body->query_direct($args)]; } else { $procedure = $this->procedure; return [true, $this->www->{$procedure}($args)]; } }
/** * Sets the content in the xmlObject. * * @param datatype $xmlObject The xml object to set the content in. * @param array $content The dynamic content blocks to set. * @param bool $enableTracking Set EMV URL in the urls found? * * @return void */ private function setContentInXMLObject($xmlObject, array $content, $enableTracking) { $xmlObject->addChild('content'); // Html markup url expression. $hrefExpr = '%href=([\'"])?((https?|ftp):\\/\\/[^\'" >]+)%i'; // Add Dynamic content blocks to the request object. foreach ($content as $k => $v) { if ($enableTracking) { // Setup url tracking using emv tags. $v = preg_replace($hrefExpr, 'href=$1[EMV URL]$2[EMV /URL]', $v); // Replace the pound symbol for its htmlentity. $v = str_replace('£', '£', $v); } $entry = $xmlObject->content->addChild('entry'); $entry->key = $k; $entry->value = $v; } }
function documentation() { $xml = new xml(); $methods = $xml->element('methods'); $xml->append($methods); foreach ($this->methods as $url => $group) { foreach ($group->schema() as $schema) { list($type, $get, $post) = $schema; $method = $xml->element('method'); $methods->append($method); $method['@id'] = str_pad(dechex(crc32("{$type}:{$url}:" . implode(':', array_keys($get)) . implode(':', array_keys($post)))), 8, '0', STR_PAD_LEFT); $method['@url'] = $url; $method['@type'] = strtoupper($type); foreach ($get as $name => $param) { $g = $xml->element('get'); $g['@name'] = $name; $g['@type'] = $param->type; $g['@min'] = isset($param->min) ? $param->min : 'default (' . datatype::min($param->type) . ')'; $g['@max'] = isset($param->max) ? $param->max : 'default (' . datatype::max($param->type) . ')'; $g['@required'] = $param->required ? 'true' : 'false'; !isset($param->default) or $g['@default'] = $param->default; !isset($param->domains) or $g['@domain'] = implode(', ', $param->domains); $method->append($g); } foreach ($post as $name => $param) { $p = $xml->element('post'); $p['@name'] = $name; $p['@type'] = $param->type; $p['@min'] = isset($param->min) ? $param->min : 'default (' . datatype::min($param->type) . ')'; $p['@max'] = isset($param->max) ? $param->max : 'default (' . datatype::max($param->type) . ')'; $p['@required'] = $param->required ? 'true' : 'false'; !isset($param->default) or $p['@default'] = $param->default; !isset($param->domains) or $p['@domain'] = implode(', ', $param->domains); $method->append($p); } } } $xslt = new XSLTProcessor(); $xsl = new DOMDocument(); $xsl->load(www_root . 'backend/documentation.xsl'); $xslt->importStylesheet($xsl); $documentation = $xslt->transformToDoc($xml->get()); return (object) ['code' => 200, 'message' => 'OK', 'headers' => ['Content-Type' => 'text/html'], 'body' => $documentation->saveXML()]; }