Source of file DefaultComplexType.php
Size: 3,027 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Soap/Wsdl/ComplexTypeStrategy/DefaultComplexType.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; use ReflectionClass; use Zend\Soap\Exception; use Zend\Soap\Wsdl; class DefaultComplexType extends AbstractComplexTypeStrategy { /** * Add a complex type by recursively using all the class properties fetched via Reflection. * * @param string $type Name of the class to be specified * @return string XSD Type for the given PHP type * @throws Exception\InvalidArgumentException if class does not exist */ public function addComplexType($type) { if (!class_exists($type)) { throw new Exception\InvalidArgumentException(sprintf( 'Cannot add a complex type %s that is not an object or where ' . 'class could not be found in "DefaultComplexType" strategy.', $type )); } if (($soapType = $this->scanRegisteredTypes($type)) !== null) { return $soapType; } $dom = $this->getContext()->toDomDocument(); $class = new ReflectionClass($type); $soapTypeName = $this->getContext()->translateType($type); $soapType = Wsdl::TYPES_NS . ':' . $soapTypeName; // Register type here to avoid recursion $this->getContext()->addType($type, $soapType); $defaultProperties = $class->getDefaultProperties(); $complexType = $dom->createElementNS(Wsdl::XSD_NS_URI, 'complexType'); $complexType->setAttribute('name', $soapTypeName); $all = $dom->createElementNS(Wsdl::XSD_NS_URI, '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->createElementNS(Wsdl::XSD_NS_URI, '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); } } $complexType->appendChild($all); $this->getContext()->getSchema()->appendChild($complexType); return $soapType; } } |