コード例 #1
0
 /**
  * Convert data from array to Data Object representation if type is Data Object or array of Data Objects.
  *
  * @param mixed $value
  * @param string $type Convert given value to the this type
  * @return mixed
  */
 protected function _convertValue($value, $type)
 {
     $isArrayType = $this->_typeProcessor->isArrayType($type);
     if ($isArrayType && isset($value['item'])) {
         $value = $this->_removeSoapItemNode($value);
     }
     if ($this->_typeProcessor->isTypeSimple($type) || $this->_typeProcessor->isTypeAny($type)) {
         $result = $this->_typeProcessor->processSimpleAndAnyType($value, $type);
     } else {
         /** Complex type or array of complex types */
         if ($isArrayType) {
             // Initializing the result for array type else it will return null for empty array
             $result = is_array($value) ? [] : null;
             $itemType = $this->_typeProcessor->getArrayItemType($type);
             if (is_array($value)) {
                 foreach ($value as $key => $item) {
                     $result[$key] = $this->_createFromArray($itemType, $item);
                 }
             }
         } else {
             $result = $this->_createFromArray($type, $value);
         }
     }
     return $result;
 }
コード例 #2
0
 /**
  * Process different element types.
  *
  * @param string $elementType
  * @param string $documentation
  * @param \DOMElement $appInfoNode
  * @return void
  */
 protected function _processElementType($elementType, $documentation, \DOMElement $appInfoNode)
 {
     if ($elementType == 'int') {
         $this->_processRequiredAnnotation('min', $documentation, $appInfoNode);
         $this->_processRequiredAnnotation('max', $documentation, $appInfoNode);
     }
     if ($elementType == 'string') {
         $this->_processRequiredAnnotation('maxLength', $documentation, $appInfoNode);
     }
     if ($this->_typeProcessor->isArrayType($elementType)) {
         $natureOfTypeNode = $this->_getDom()->createElement(self::APP_INF_NS . ':natureOfType');
         $natureOfTypeNode->appendChild($this->_getDom()->createTextNode('array'));
         $appInfoNode->appendChild($natureOfTypeNode);
     }
 }
コード例 #3
0
 /**
  * Test adding complex type with complex parameters and arrays.
  */
 public function testAddComplexTypeComplexParameters()
 {
     $type = 'VendorModuleADataStructure';
     $parameterType = 'ComplexType';
     $typeData = array('documentation' => 'test', 'parameters' => array('complex_param' => array('type' => $parameterType, 'required' => true, 'documentation' => 'complex type param.')));
     $parameterData = array('documentation' => 'test', 'parameters' => array('string_param' => array('type' => 'ComplexTypeB[]', 'required' => true, 'documentation' => 'string param.')));
     $this->_wsdl->expects($this->at(0))->method('getTypes')->will($this->returnValue(array()));
     $this->_wsdl->expects($this->any())->method('getTypes')->will($this->returnValue(array($type => Wsdl::TYPES_NS . ':' . $type)));
     $this->_wsdl->expects($this->any())->method('toDomDocument')->will($this->returnValue(new \DOMDocument()));
     $schemaMock = $this->getMock('DOMElement', [], ['a']);
     $schemaMock->expects($this->any())->method('appendChild');
     $this->_wsdl->expects($this->any())->method('getSchema')->will($this->returnValue($schemaMock));
     $this->_typeProcessor->expects($this->at(0))->method('getTypeData')->with($type)->will($this->returnValue($typeData));
     $this->_typeProcessor->expects($this->at(1))->method('getTypeData')->with($parameterType)->will($this->returnValue($parameterData));
     $this->assertEquals(Wsdl::TYPES_NS . ':' . $type, $this->_strategy->addComplexType($type));
 }
コード例 #4
0
ファイル: Generator.php プロジェクト: pavelnovitsky/magento2
 /**
  * Add WSDL elements related to generic SOAP fault, which are common for all operations: element, type and message.
  *
  * @param Wsdl $wsdl
  * @return string Default fault message name
  */
 protected function _addGenericFaultComplexTypeNodes($wsdl)
 {
     $faultMessageName = Fault::NODE_DETAIL_WRAPPER;
     $complexTypeName = $this->getElementComplexTypeName($faultMessageName);
     $wsdl->addElement(array('name' => $faultMessageName, 'type' => Wsdl::TYPES_NS . ':' . $complexTypeName));
     $faultParamsComplexType = Fault::NODE_DETAIL_PARAMETER;
     $faultParamsData = array('parameters' => array(Fault::NODE_DETAIL_PARAMETER_KEY => array('type' => 'string', 'required' => true, 'documentation' => ''), Fault::NODE_DETAIL_PARAMETER_VALUE => array('type' => 'string', 'required' => true, 'documentation' => '')));
     $wrappedErrorComplexType = Fault::NODE_DETAIL_WRAPPED_ERROR;
     $wrappedErrorData = array('parameters' => array(Fault::NODE_DETAIL_WRAPPED_ERROR_MESSAGE => array('type' => 'string', 'required' => true, 'documentation' => ''), Fault::NODE_DETAIL_WRAPPED_ERROR_PARAMETERS => array('type' => "{$faultParamsComplexType}[]", 'required' => false, 'documentation' => 'Message parameters.')));
     $genericFaultTypeData = array('parameters' => array(Fault::NODE_DETAIL_TRACE => array('type' => 'string', 'required' => false, 'documentation' => 'Exception calls stack trace.'), Fault::NODE_DETAIL_PARAMETERS => array('type' => "{$faultParamsComplexType}[]", 'required' => false, 'documentation' => 'Additional exception parameters.'), Fault::NODE_DETAIL_WRAPPED_ERRORS => array('type' => "{$wrappedErrorComplexType}[]", 'required' => false, 'documentation' => 'Additional wrapped errors.')));
     $this->_typeProcessor->setTypeData($faultParamsComplexType, $faultParamsData);
     $this->_typeProcessor->setTypeData($wrappedErrorComplexType, $wrappedErrorData);
     $this->_typeProcessor->setTypeData($complexTypeName, $genericFaultTypeData);
     $wsdl->addComplexType($complexTypeName);
     $wsdl->addMessage($faultMessageName, array('messageParameters' => array('element' => Wsdl::TYPES_NS . ':' . $faultMessageName)));
     return Wsdl::TYPES_NS . ':' . $faultMessageName;
 }
コード例 #5
0
ファイル: ClassReflector.php プロジェクト: aiesh/magento2
 /**
  * Retrieve method interface and documentation description.
  *
  * @param ReflectionMethod $method
  * @return array
  * @throws \InvalidArgumentException
  */
 public function extractMethodData(ReflectionMethod $method)
 {
     $methodData = array('documentation' => $method->getDescription(), 'interface' => array());
     $prototypes = $method->getPrototypes();
     /** Take the fullest interface that also includes optional parameters. */
     /** @var \Zend\Server\Reflection\Prototype $prototype */
     $prototype = end($prototypes);
     /** @var \Zend\Server\Reflection\ReflectionParameter $parameter */
     foreach ($prototype->getParameters() as $parameter) {
         $parameterData = array('type' => $this->_typeProcessor->process($parameter->getType()), 'required' => !$parameter->isOptional(), 'documentation' => $parameter->getDescription());
         if ($parameter->isOptional()) {
             $parameterData['default'] = $parameter->getDefaultValue();
         }
         $methodData['interface']['in']['parameters'][$parameter->getName()] = $parameterData;
     }
     if ($prototype->getReturnType() != 'void' && $prototype->getReturnType() != 'null') {
         $methodData['interface']['out']['parameters']['result'] = array('type' => $this->_typeProcessor->process($prototype->getReturnType()), 'documentation' => $prototype->getReturnValue()->getDescription(), 'required' => true);
     }
     return $methodData;
 }
コード例 #6
0
 /**
  * @expectedException \Magento\Webapi\Exception
  * @expectedExceptionMessage Invalid type for value :"1". Expected Type: "int[]".
  */
 public function testProcessSimpleTypeInvalidType()
 {
     $value = 1;
     $type = 'int[]';
     $this->_typeProcessor->processSimpleAndAnyType($value, $type);
 }
コード例 #7
0
 public function testTranslateArrayTypeName()
 {
     $this->assertEquals('ArrayOfComplexType', $this->_typeProcessor->translateArrayTypeName('complexType'));
 }
コード例 #8
0
 /**
  * Set up helper.
  */
 protected function setUp()
 {
     $this->_typeProcessor = $this->getMock('\\Magento\\Webapi\\Model\\Config\\ClassReflector\\TypeProcessor', array('process'), array(), '', false);
     $this->_typeProcessor->expects($this->any())->method('process')->will($this->returnValueMap(array(array('string', 'str'), array('int', 'int'))));
     $this->_classReflector = new \Magento\Webapi\Model\Config\ClassReflector($this->_typeProcessor);
 }