public function testGetSetPropertyWriter() { $context = new Array2ObjectContext(); $writer = new AccessorWriter(); $context->setWriter($writer); static::assertEquals($writer, $context->getWriter()); }
/** * @param object $object object instance to populate * @param array $data array of data to apply * * @throws \InvalidArgumentException */ public function populate($object, array $data) { if (!is_object($object)) { throw new \InvalidArgumentException('The first param should be a object.'); } if ($object instanceof Array2ObjectInterface) { $object->__populate($data); } else { $reflClass = new \ReflectionClass($object); foreach (Utils::getClassProperties($reflClass) as $property) { foreach ($data as $key => $value) { if ($this->context->getMatcher()->match($property, $key) && $this->context->getWriter()->isWritable($object, $property->getName())) { $types = Utils::getPropertyTypes($property); $value = $this->parseValue($value, $types, $property, $object); $this->context->getWriter()->setValue($object, $property->getName(), $value); } } } } }