public function test_isArray() { /** === Test Data === */ $TYPE = '\\Some\\Array\\Type[]'; /** === Call and asserts === */ $res = $this->obj->isArray($TYPE); $this->assertTrue($res); }
/** * Process generally coded methods ("public function getProp()"). * * @param string $type Normalized type name. * @param \Zend\Code\Reflection\MethodReflection[] $methods Reflection of the type's methods. */ public function _processMethods($type, $methods) { foreach ($methods as $method) { $methodName = $method->getName(); $isGetter = strpos($methodName, 'get') === 0; $hasParams = $method->getNumberOfParameters() > 0; $isIterator = $methodName == 'getIterator'; /* only getters w/o parameters will be proceeded */ if ($isGetter && !$hasParams && !$isIterator) { $propName = lcfirst(substr($methodName, 3)); $typeData = $this->_typeProcessor->getGetterReturnType($method); $propType = $typeData['type']; $propIsRequired = $typeData['isRequired']; $propIsArray = $this->_toolsType->isArray($propType); $propType = $this->_toolsType->normalizeType($propType); $propData = new \Praxigento\Core\Reflection\Data\Property(); $propData->setName($propName); $propData->setIsRequired($propIsRequired); $propData->setIsArray($propIsArray); $propData->setType($propType); $this->_registry[$type][$propName] = $propData; $this->register($propType); } } }
/** * @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; }