Ejemplo n.º 1
0
 /**
  * Format data of array type.
  *
  * @param array $data
  * @param string $dataType
  * @param Mage_Webapi_Model_ConfigAbstract $apiConfig
  * @return array
  * @throws Mage_Webapi_Exception If passed data is not an array
  */
 protected function _formatArrayData($data, $dataType, $apiConfig)
 {
     $itemDataType = $this->_configHelper->getArrayItemType($dataType);
     $formattedData = array();
     if (!is_array($data)) {
         throw new Mage_Webapi_Exception($this->__('Data corresponding to "%s" type is expected to be an array.', $dataType), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
     }
     foreach ($data as $itemData) {
         $formattedData[] = $this->_formatParamData($itemData, $itemDataType, $apiConfig);
     }
     return $formattedData;
 }
Ejemplo n.º 2
0
 /**
  * Process array of types.
  *
  * @param string $type
  * @param array $callInfo
  */
 protected function _processArrayParameter($type, $callInfo = array())
 {
     $arrayItemType = $this->_helper->getArrayItemType($type);
     $arrayTypeName = $this->_helper->translateArrayTypeName($type);
     if (!$this->_helper->isTypeSimple($arrayItemType)) {
         $this->addComplexType($arrayItemType, $callInfo);
     }
     $arrayTypeParameters = array(self::ARRAY_ITEM_KEY_NAME => array('type' => $arrayItemType, 'required' => false, 'isArray' => true, 'documentation' => sprintf('An item of %s.', $arrayTypeName)));
     $arrayTypeData = array('documentation' => sprintf('An array of %s items.', $arrayItemType), 'parameters' => $arrayTypeParameters);
     $this->_config->setTypeData($arrayTypeName, $arrayTypeData);
     $this->addComplexType($arrayTypeName, $callInfo);
 }
Ejemplo n.º 3
0
 /**
  * Retrieve complex type information from class public properties.
  *
  * @param string $class
  * @return array
  * @throws InvalidArgumentException
  */
 protected function _processComplexType($class)
 {
     $typeName = $this->_helper->translateTypeName($class);
     $this->_types[$typeName] = array();
     if ($this->_helper->isArrayType($class)) {
         $this->process($this->_helper->getArrayItemType($class));
     } else {
         if (!class_exists($class)) {
             throw new InvalidArgumentException(sprintf('Could not load the "%s" class as parameter type.', $class));
         }
         $reflection = new ClassReflection($class);
         $docBlock = $reflection->getDocBlock();
         $this->_types[$typeName]['documentation'] = $docBlock ? $this->_getDescription($docBlock) : '';
         $defaultProperties = $reflection->getDefaultProperties();
         /** @var \Zend\Code\Reflection\PropertyReflection $property */
         foreach ($reflection->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
             $this->_processProperty($property, $defaultProperties, $typeName);
         }
     }
     return $this->_types[$typeName];
 }