public function test_formatPropertyName()
 {
     /** === Test Data === */
     $PROPERTY_JSON = 'camel_case_prop';
     $PROPERTY_VALID = 'camelCaseProp';
     /** === Call and asserts  === */
     $res = $this->obj->formatPropertyName($PROPERTY_JSON);
     $this->assertEquals($PROPERTY_VALID, $res);
 }
示例#2
0
 /**
  * @param string $type
  * @param array $data
  * @return DataObject|mixed
  */
 public function parseArrayData($type, $data)
 {
     $isArray = $this->_toolType->isArray($type);
     $typeNorm = $this->_toolType->normalizeType($type);
     if (is_subclass_of($typeNorm, \Flancer32\Lib\DataObject::class)) {
         /* Process data objects separately. Register annotated class and parse parameters types. */
         if ($isArray) {
             /* process $data as array of $types */
             $result = [];
             foreach ($data as $key => $item) {
                 $result[$key] = $this->parseArrayDataRecursive($typeNorm, $item);
             }
         } else {
             /* process $data as data object of $type */
             $typeData = $this->_typePropsRegistry->register($typeNorm);
             $result = $this->_manObj->create($typeNorm);
             foreach ($data as $key => $value) {
                 $propName = $this->_toolType->formatPropertyName($key);
                 if (isset($typeData[$propName])) {
                     /** @var \\Praxigento\Core\Reflection\Data\Property $propertyData */
                     $propertyData = $typeData[$propName];
                     $propertyType = $propertyData->getType();
                     $propertyIsArray = $propertyData->getIsArray();
                     if ($propertyIsArray) {
                         /* property is the array of types */
                         $propertyType = $this->_toolType->getTypeAsArrayOfTypes($propertyType);
                         $complex = $this->parseArrayDataRecursive($propertyType, $value);
                         $result->setData($propName, $complex);
                     } else {
                         if ($this->_toolType->isSimple($propertyType)) {
                             /* property is the simple type */
                             $result->setData($propName, $value);
                         } else {
                             /* property is the complex type, we need to convert recursively */
                             $complex = $this->parseArrayDataRecursive($propertyType, $value);
                             $result->setData($propName, $complex);
                         }
                     }
                 }
             }
         }
     } else {
         $result = $data;
     }
     return $result;
 }