zend的soap是如何通过反射文档自动构建wsdl的
2013-05-03 00:33
369 查看
废话不多说,直接上代码
看到了?先用反射拿到文档,在用正则把类型搞出来。
用它的SOAP自动swdl除了代码写的规范外,注释也要规范,对于懒散惯了的PHPer是不是感觉很操蛋的样子??!!
$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是不是感觉很操蛋的样子??!!
相关文章推荐
- 通过反射途径获得的对象如何自动注入spring Bean
- Zend_Soap_AutoDiscover自动生成wsdl
- 如何让xcode拥有通过注释自动生成文档的功能
- 如何通过C++,实现多个文档内字符(数据)批量提取与保存
- 如何自动执行与 c + + 嵌入 Office ActiveX 文档
- Documentum常见问题4—如何通过vlink方式直接查看文档内容
- seq2seq和attention如何应用到文档自动摘要
- Word文档如何自动生成文献摘要?
- EF CodeFirst 如何通过配置自动创建数据库<当模型改变时>
- C#实现通过模板自动创建Word文档的方法
- Flex中如何通过verticalScrollPosition和maxVerticalScrollPosition属性,TextArea增加新内容的时候自动滚动 .
- 如何通过 Visual C# 使 Excel 自动执行操作以使用数组来填充或获取某区域中的数据
- 如何通过实体组件系统在Javascript中构建游戏
- 如何使用python来模拟鼠标点击(将通过实例自动化模拟在360浏览器中自动搜索"python")
- Java - 如何通过反射调用对象的方法?
- 在Java中如何通过反射找到一个变量,这个变量的类型是指定的类型
- 如何通过反射来代替N多的if...else
- 如何通过gulp构建工具来编译less文件
- c# 如何通过反射 获取\设置属性值
- 关于APT攻击及如何构建安全防御体系——文档加密产品