Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 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\Wsdl;
/**
* Abstract class for Zend\Soap\Wsdl\Strategy.
*/
abstract class AbstractComplexTypeStrategy implements ComplexTypeStrategyInterface
{
/**
* Context object
* @var Wsdl
*/
protected $context;
/**
* Set the WSDL Context object this strategy resides in.
*
* @param Wsdl $context
*/
public function setContext(Wsdl $context)
{
$this->context = $context;
}
/**
* Return the current WSDL context object
*
* @return Wsdl
*/
public function getContext()
{
return $this->context;
}
/**
* Look through registered types
*
* @param string $phpType
* @return string
*/
public function scanRegisteredTypes($phpType)
{
if (array_key_exists($phpType, $this->getContext()->getTypes())) {
$soapTypes = $this->getContext()->getTypes();
return $soapTypes[$phpType];
}
return;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 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\Wsdl;
class AnyType implements ComplexTypeStrategyInterface
{
/**
* Not needed in this strategy.
*
* @param Wsdl $context
*/
public function setContext(Wsdl $context)
{
}
/**
* Returns xsd:anyType regardless of the input.
*
* @param string $type
* @return string
*/
public function addComplexType($type)
{
return Wsdl::XSD_NS . ':anyType';
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 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, '[]');
}
}

View File

@@ -0,0 +1,130 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 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\Wsdl;
class ArrayOfTypeSequence extends DefaultComplexType
{
/**
* Add an unbounded ArrayOfType based on the xsd:sequence syntax if
* type[] is detected in return value doc comment.
*
* @param string $type
* @return string tns:xsd-type
*/
public function addComplexType($type)
{
$nestedCounter = $this->getNestedCount($type);
if ($nestedCounter > 0) {
$singularType = $this->getSingularType($type);
$complexType = '';
for ($i = 1; $i <= $nestedCounter; $i++) {
$complexType = $this->getTypeBasedOnNestingLevel($singularType, $i);
$complexTypePhp = $singularType . str_repeat('[]', $i);
$childType = $this->getTypeBasedOnNestingLevel($singularType, $i-1);
$this->addSequenceType($complexType, $childType, $complexTypePhp);
}
return $complexType;
}
if (($soapType = $this->scanRegisteredTypes($type)) !== null) {
// Existing complex type
return $soapType;
}
// New singular complex type
return parent::addComplexType($type);
}
/**
* Return the ArrayOf or simple type name based on the singular xsdtype
* and the nesting level
*
* @param string $singularType
* @param int $level
* @return string
*/
protected function getTypeBasedOnNestingLevel($singularType, $level)
{
if ($level == 0) {
// This is not an Array anymore, return the xsd simple type
return $this->getContext()->getType($singularType);
}
return Wsdl::TYPES_NS
. ':'
. str_repeat('ArrayOf', $level)
. ucfirst($this->getContext()->translateType($singularType));
}
/**
* From a nested definition with type[], get the singular xsd:type
*
* @param string $type
* @return string
*/
protected function getSingularType($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, '[]');
}
/**
* Append the complex type definition to the WSDL via the context access
*
* @param string $arrayType Array type name (e.g. 'tns:ArrayOfArrayOfInt')
* @param string $childType Qualified array items type (e.g. 'xsd:int', 'tns:ArrayOfInt')
* @param string $phpArrayType PHP type (e.g. 'int[][]', '\MyNamespace\MyClassName[][][]')
*/
protected function addSequenceType($arrayType, $childType, $phpArrayType)
{
if ($this->scanRegisteredTypes($phpArrayType) !== null) {
return;
}
// Register type here to avoid recursion
$this->getContext()->addType($phpArrayType, $arrayType);
$dom = $this->getContext()->toDomDocument();
$arrayTypeName = substr($arrayType, strpos($arrayType, ':') + 1);
$complexType = $dom->createElementNS(Wsdl::XSD_NS_URI, 'complexType');
$this->getContext()->getSchema()->appendChild($complexType);
$complexType->setAttribute('name', $arrayTypeName);
$sequence = $dom->createElementNS(Wsdl::XSD_NS_URI, 'sequence');
$complexType->appendChild($sequence);
$element = $dom->createElementNS(Wsdl::XSD_NS_URI, 'element');
$sequence->appendChild($element);
$element->setAttribute('name', 'item');
$element->setAttribute('type', $childType);
$element->setAttribute('minOccurs', 0);
$element->setAttribute('maxOccurs', 'unbounded');
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 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\Wsdl;
/**
* Interface strategies that generate an XSD-Schema for complex data types in WSDL files.
*/
interface ComplexTypeStrategyInterface
{
/**
* Method accepts the current WSDL context file.
*
* @param Wsdl $context
*/
public function setContext(Wsdl $context);
/**
* Create a complex type based on a strategy
*
* @param string $type
* @return string XSD type
*/
public function addComplexType($type);
}

View File

@@ -0,0 +1,154 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 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;
use Zend\Soap\Wsdl\ComplexTypeStrategy\ComplexTypeStrategyInterface as ComplexTypeStrategy;
class Composite implements ComplexTypeStrategy
{
/**
* Typemap of Complex Type => Strategy pairs.
* @var array
*/
protected $typeMap = [];
/**
* Default Strategy of this composite
* @var string|ComplexTypeStrategy
*/
protected $defaultStrategy;
/**
* Context WSDL file that this composite serves
* @var Wsdl|null
*/
protected $context;
/**
* Construct Composite WSDL Strategy.
*
* @param array $typeMap
* @param string|ComplexTypeStrategy $defaultStrategy
*/
public function __construct(
array $typeMap = [],
$defaultStrategy = 'Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType'
) {
foreach ($typeMap as $type => $strategy) {
$this->connectTypeToStrategy($type, $strategy);
}
$this->defaultStrategy = $defaultStrategy;
}
/**
* Connect a complex type to a given strategy.
*
* @param string $type
* @param string|ComplexTypeStrategy $strategy
* @return Composite
* @throws Exception\InvalidArgumentException
*/
public function connectTypeToStrategy($type, $strategy)
{
if (!is_string($type)) {
throw new Exception\InvalidArgumentException('Invalid type given to Composite Type Map.');
}
$this->typeMap[$type] = $strategy;
return $this;
}
/**
* Return default strategy of this composite
*
* @return ComplexTypeStrategy
* @throws Exception\InvalidArgumentException
*/
public function getDefaultStrategy()
{
$strategy = $this->defaultStrategy;
if (is_string($strategy) && class_exists($strategy)) {
$strategy = new $strategy;
}
if (!($strategy instanceof ComplexTypeStrategy)) {
throw new Exception\InvalidArgumentException(
'Default Strategy for Complex Types is not a valid strategy object.'
);
}
$this->defaultStrategy = $strategy;
return $strategy;
}
/**
* Return specific strategy or the default strategy of this type.
*
* @param string $type
* @return ComplexTypeStrategy
* @throws Exception\InvalidArgumentException
*/
public function getStrategyOfType($type)
{
if (isset($this->typeMap[$type])) {
$strategy = $this->typeMap[$type];
if (is_string($strategy) && class_exists($strategy)) {
$strategy = new $strategy();
}
if (!($strategy instanceof ComplexTypeStrategy)) {
throw new Exception\InvalidArgumentException(sprintf(
'Strategy for Complex Type "%s" is not a valid strategy object.',
$type
));
}
$this->typeMap[$type] = $strategy;
} else {
$strategy = $this->getDefaultStrategy();
}
return $strategy;
}
/**
* Method accepts the current WSDL context file.
*
* @param Wsdl $context
* @return Composite
*/
public function setContext(Wsdl $context)
{
$this->context = $context;
return $this;
}
/**
* Create a complex type based on a strategy
*
* @param string $type
* @return string XSD type
* @throws Exception\InvalidArgumentException
*/
public function addComplexType($type)
{
if (!($this->context instanceof Wsdl)) {
throw new Exception\InvalidArgumentException(sprintf(
'Cannot add complex type "%s", no context is set for this composite strategy.',
$type
));
}
$strategy = $this->getStrategyOfType($type);
$strategy->setContext($this->context);
return $strategy->addComplexType($type);
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 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
));
}
$class = new ReflectionClass($type);
$phpType = $class->getName();
if (($soapType = $this->scanRegisteredTypes($phpType)) !== null) {
return $soapType;
}
$dom = $this->getContext()->toDomDocument();
$soapTypeName = $this->getContext()->translateType($phpType);
$soapType = Wsdl::TYPES_NS . ':' . $soapTypeName;
// Register type here to avoid recursion
$this->getContext()->addType($phpType, $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;
}
}