Esempio n. 1
0
 /**
  * Creates a new instance of the given class and populates it with the array of data. The data can
  * be in different forms depending on the adapter being used, REST vs. SOAP. For REST, the data is
  * in snake_case (e.g. tax_class_id) while for SOAP the data is in camelCase (e.g. taxClassId).
  *
  * @param string|\ReflectionClass $class
  * @param array $data
  * @return object the newly created and populated object
  */
 protected function _createFromArray($class, $data)
 {
     $className = is_string($class) ? $class : $class->getName();
     $builder = $this->_objectManager->create($className . "Builder");
     $class = new ClassReflection($className);
     foreach ($data as $propertyName => $value) {
         // Converts snake_case to uppercase CamelCase to help form getter/setter method names
         // This use case is for REST only. SOAP request data is already camel cased
         $camelCaseProperty = str_replace(' ', '', ucwords(str_replace('_', ' ', $propertyName)));
         $methodName = $this->_processGetterMethod($class, $camelCaseProperty);
         $methodReflection = $class->getMethod($methodName);
         if ($methodReflection->isPublic()) {
             $returnType = $this->_typeProcessor->getGetterReturnType($methodReflection)['type'];
             $setterName = 'set' . $camelCaseProperty;
             $builder->{$setterName}($this->_convertValue($value, $returnType));
         }
     }
     return $builder->create();
 }
 /**
  * Creates a new instance of the given class and populates it with the array of data. The data can
  * be in different forms depending on the adapter being used, REST vs. SOAP. For REST, the data is
  * in snake_case (e.g. tax_class_id) while for SOAP the data is in camelCase (e.g. taxClassId).
  *
  * @param string|\ReflectionClass $class
  * @param array $data
  * @return object the newly created and populated object
  */
 protected function _createFromArray($class, $data)
 {
     $className = is_string($class) ? $class : $class->getName();
     $builder = $this->_objectManager->create($className . "Builder");
     $class = new ClassReflection($className);
     foreach ($data as $propertyName => $value) {
         // Converts snake_case to uppercase CamelCase to help form getter/setter method names
         // This use case is for REST only. SOAP request data is already camel cased
         $camelCaseProperty = SimpleDataObjectConverter::snakeCaseToUpperCamelCase($propertyName);
         $methodName = $this->_processGetterMethod($class, $camelCaseProperty);
         $methodReflection = $class->getMethod($methodName);
         if ($methodReflection->isPublic()) {
             $returnType = $this->_typeProcessor->getGetterReturnType($methodReflection)['type'];
             $setterName = 'set' . $camelCaseProperty;
             if ($camelCaseProperty === 'CustomAttributes') {
                 $setterValue = $this->convertCustomAttributeValue($value, $returnType, $className);
             } else {
                 $setterValue = $this->_convertValue($value, $returnType);
             }
             $builder->{$setterName}($setterValue);
         }
     }
     return $builder->create();
 }