/** * @param array $objectData * @param string $objectClass * @param array $settings * @param string $key * @return object * @throws Exception */ protected function mapOneToObject($objectData, $objectClass, $settings, $key = '') { if (!is_array($objectData)) { throw new Exception('Object mapping is not possible with given unexpected data for ObjectClass ' . $objectClass . ': ' . json_encode($objectData), 1408468371); } $object = $this->getNewInstanceOfObject($objectClass); $properties = ObjectAccess::getSettablePropertyNames($object); foreach ($properties as $property) { $value = $this->getPropertyValue($object, $property, $objectData, $settings, $key); if (isset($value)) { $setterName = ObjectAccess::buildSetterMethodName($property); $object->{$setterName}($value); } } return $object; }
/** * @test */ public function getSettablePropertyNamesReturnsPropertyNamesOfStdClass() { $stdClassObject = new \stdClass(); $stdClassObject->property = 'string1'; $stdClassObject->property2 = NULL; $expectedPropertyNames = array('property', 'property2'); $actualPropertyNames = ObjectAccess::getSettablePropertyNames($stdClassObject); $this->assertEquals($expectedPropertyNames, $actualPropertyNames, 'getSettablePropertyNames returns not all settable properties.'); }