Source of file ArrayOfTypeComplex.php
Size: 4,081 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Soap/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 | <?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 Zend\Soap\Exception; use Zend\Soap\Wsdl; class ArrayOfTypeComplex extends DefaultComplexType { /** * Add an ArrayOfType based on the xsd:complexType syntax if type[] is * detected in return value doc comment. * * @param string $type * @return string tns:xsd-type * @throws Exception\InvalidArgumentException */ public function addComplexType($type) { if (($soapType = $this->scanRegisteredTypes($type)) !== null) { return $soapType; } $singularType = $this->_getSingularPhpType($type); $nestingLevel = $this->_getNestedCount($type); if ($nestingLevel == 0) { return parent::addComplexType($singularType); } if ($nestingLevel != 1) { throw new Exception\InvalidArgumentException( 'ArrayOfTypeComplex cannot return nested ArrayOfObject deeper than one level. ' . 'Use array object properties to return deep nested data.' ); } // The following blocks define the Array of Object structure return $this->_addArrayOfComplexType($singularType, $type); } /** * Add an ArrayOfType based on the xsd:complexType syntax if type[] is * detected in return value doc comment. * * @param string $singularType e.g. '\MyNamespace\MyClassname' * @param string $type e.g. '\MyNamespace\MyClassname[]' * @return string tns:xsd-type e.g. 'tns:ArrayOfMyNamespace.MyClassname' */ protected function _addArrayOfComplexType($singularType, $type) { if (($soapType = $this->scanRegisteredTypes($type)) !== null) { return $soapType; } $xsdComplexTypeName = 'ArrayOf' . $this->getContext()->translateType($singularType); $xsdComplexType = Wsdl::TYPES_NS . ':' . $xsdComplexTypeName; // Register type here to avoid recursion $this->getContext()->addType($type, $xsdComplexType); // Process singular type using DefaultComplexType strategy parent::addComplexType($singularType); // Add array type structure to WSDL document $dom = $this->getContext()->toDomDocument(); $complexType = $dom->createElementNS(Wsdl::XSD_NS_URI, 'complexType'); $this->getContext()->getSchema()->appendChild($complexType); $complexType->setAttribute('name', $xsdComplexTypeName); $complexContent = $dom->createElementNS(Wsdl::XSD_NS_URI, 'complexContent'); $complexType->appendChild($complexContent); $xsdRestriction = $dom->createElementNS(Wsdl::XSD_NS_URI, 'restriction'); $complexContent->appendChild($xsdRestriction); $xsdRestriction->setAttribute('base', Wsdl::SOAP_ENC_NS . ':Array'); $xsdAttribute = $dom->createElementNS(Wsdl::XSD_NS_URI, 'attribute'); $xsdRestriction->appendChild($xsdAttribute); $xsdAttribute->setAttribute('ref', Wsdl::SOAP_ENC_NS . ':arrayType'); $xsdAttribute->setAttributeNS( Wsdl::WSDL_NS_URI, 'arrayType', Wsdl::TYPES_NS . ':' . $this->getContext()->translateType($singularType) . '[]' ); return $xsdComplexType; } /** * From a nested definition with type[], get the singular PHP Type * * @param string $type * @return string */ protected function _getSingularPhpType($type) { return str_replace('[]', '', $type); } /** * Return the array nesting level based on the type name * * @param string $type * @return int */ protected function _getNestedCount($type) { return substr_count($type, '[]'); } } |