您的位置:首页 > 编程语言 > PHP开发

zend的soap是如何通过反射文档自动构建wsdl的

2013-05-03 00:33 369 查看
废话不多说,直接上代码

$class = new ReflectionClass($type);

$defaultProperties = $class->getDefaultProperties();

$complexType = $dom->createElement('xsd:complexType');
$complexType->setAttribute('name', $type);

$all = $dom->createElement('xsd:all');

foreach ($class->getProperties() as $property) {
if ($property->isPublic() && preg_match_all('/@var\s+([^\s]+)/m', $property->getDocComment(), $matches)) {

/**
* @todo check if 'xsd:element' must be used here (it may not be compatible with using 'complexType'
* node for describing other classes used as attribute types for current class
*/
$element = $dom->createElement('xsd:element');
$element->setAttribute('name', $propertyName = $property->getName());
$element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0])));

// If the default value is null, then this property is nillable.
if ($defaultProperties[$propertyName] === null) {
$element->setAttribute('nillable', 'true');
}

$all->appendChild($element);
}
}


看到了?先用反射拿到文档,在用正则把类型搞出来。

用它的SOAP自动swdl除了代码写的规范外,注释也要规范,对于懒散惯了的PHPer是不是感觉很操蛋的样子??!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: