Example #1
0
 /**
  * Format data as object of the specified class.
  *
  * @param array|object $data
  * @param string $dataType
  * @param Mage_Webapi_Model_ConfigAbstract $apiConfig
  * @return object Object of required data type
  * @throws LogicException If specified $dataType is invalid
  * @throws Mage_Webapi_Exception If required fields does not have values specified in $data
  */
 protected function _formatComplexObjectData($data, $dataType, $apiConfig)
 {
     $dataTypeMetadata = $apiConfig->getTypeData($dataType);
     $typeToClassMap = $apiConfig->getTypeToClassMap();
     if (!isset($typeToClassMap[$dataType])) {
         throw new LogicException(sprintf('Specified data type "%s" does not match any class.', $dataType));
     }
     $complexTypeClass = $typeToClassMap[$dataType];
     if (is_object($data) && get_class($data) == $complexTypeClass) {
         /** In case of SOAP the object creation is performed by soap server. */
         return $data;
     }
     $complexDataObject = new $complexTypeClass();
     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 ($dataTypeMetadata['parameters'] as $fieldName => $fieldMetadata) {
         if (isset($data[$fieldName])) {
             $fieldValue = $data[$fieldName];
         } elseif ($fieldMetadata['required'] == false) {
             $fieldValue = $fieldMetadata['default'];
         } else {
             throw new Mage_Webapi_Exception($this->__('Value of "%s" attribute is required.', $fieldName), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
         }
         $complexDataObject->{$fieldName} = $this->_formatParamData($fieldValue, $fieldMetadata['type'], $apiConfig);
     }
     return $complexDataObject;
 }
Example #2
0
 /**
  * Construct config with REST reader & route factory.
  *
  * @param Mage_Webapi_Model_Config_Reader_Rest $reader
  * @param Mage_Webapi_Helper_Config $helper
  * @param Mage_Core_Model_App $app
  * @param Magento_Controller_Router_Route_Factory $routeFactory
  */
 public function __construct(Mage_Webapi_Model_Config_Reader_Rest $reader, Mage_Webapi_Helper_Config $helper, Mage_Core_Model_App $app, Magento_Controller_Router_Route_Factory $routeFactory)
 {
     parent::__construct($reader, $helper, $app);
     $this->_routeFactory = $routeFactory;
 }
Example #3
0
 /**
  * Initialize dependencies.
  *
  * @param Mage_Webapi_Model_Config_Reader_Soap $reader
  * @param Mage_Webapi_Helper_Config $helper
  * @param Mage_Core_Model_App $app
  */
 public function __construct(Mage_Webapi_Model_Config_Reader_Soap $reader, Mage_Webapi_Helper_Config $helper, Mage_Core_Model_App $app)
 {
     parent::__construct($reader, $helper, $app);
 }