PageRenderTime 35ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Soap/Wsdl/Strategy/DefaultComplexType.php

https://github.com/jverkoey/snaapilookup
PHP | 69 lines | 31 code | 8 blank | 30 comment | 2 complexity | f4ea67c3a7153f2bff7aaeeedd97b7e6 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Soap
  17. * @subpackage Wsdl
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. class Zend_Soap_Wsdl_Strategy_DefaultComplexType extends Zend_Soap_Wsdl_Strategy_Abstract
  23. {
  24. /**
  25. * Add a complex type by recursivly using all the class properties fetched via Reflection.
  26. *
  27. * @param string $type Name of the class to be specified
  28. * @return string XSD Type for the given PHP type
  29. */
  30. public function addComplexType($type)
  31. {
  32. if(!class_exists($type)) {
  33. require_once "Zend/Soap/Wsdl/Exception.php";
  34. throw new Zend_Soap_Wsdl_Exception(sprintf(
  35. "Cannot add a complex type %s that is not an object or where ".
  36. "class could not be found in 'DefaultComplexType' strategy.", $type
  37. ));
  38. }
  39. $dom = $this->getContext()->toDomDocument();
  40. $class = new ReflectionClass($type);
  41. $complexType = $dom->createElement('xsd:complexType');
  42. $complexType->setAttribute('name', $type);
  43. $all = $dom->createElement('xsd:all');
  44. foreach ($class->getProperties() as $property) {
  45. if (preg_match_all('/@var\s+([^\s]+)/m', $property->getDocComment(), $matches)) {
  46. /**
  47. * @todo check if 'xsd:element' must be used here (it may not be compatible with using 'complexType'
  48. * node for describing other classes used as attribute types for current class
  49. */
  50. $element = $dom->createElement('xsd:element');
  51. $element->setAttribute('name', $property->getName());
  52. $element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0])));
  53. $all->appendChild($element);
  54. }
  55. }
  56. $complexType->appendChild($all);
  57. $this->getContext()->getSchema()->appendChild($complexType);
  58. $this->getContext()->addType($type);
  59. return "tns:$type";
  60. }
  61. }