public function set($name, $value) { if (!isset($this->mapping[$name])) { throw new WrongArgumentException("knows nothing about property '{$name}'"); } $primitive = $this->mapping[$name]; $setter = 'set' . ucfirst($primitive->getName()); if (!method_exists($this->object, $setter)) { throw new WrongArgumentException("cannot find mutator for '{$name}' in class " . get_class($this->object)); } if (is_object($value)) { if ($primitive instanceof PrimitiveAnyType && $value instanceof PrototypedEntity) { $value = ObjectToDTOConverter::create($value->entityProto())->make($value); } else { $value = $this->dtoValue($value, $primitive); } } elseif (is_array($value) && is_object(current($value))) { $dtoValue = []; foreach ($value as $oneValue) { Assert::isTrue(is_object($oneValue), 'array must contain only objects'); $dtoValue[] = $this->dtoValue($oneValue, $primitive); } $value = $dtoValue; } return $this->object->{$setter}($value); }
public final function makeDto() { return ObjectToDTOConverter::create($this->entityProto())->make($this); }