protected function set($property, $value)
{
if ($property instanceof Property) {
$name = $property->getName();
} else {
$name = $property;
$property = $this->getCurrentReflection()->getEntityProperty($name);
if ($property === null) {
throw new MemberAccessException("Cannot access undefined property '{$name}' in entity " . get_called_class() . '.');
}
}
if ($value === null and !$property->isNullable()) {
throw new InvalidValueException("Property '{$name}' in entity " . get_called_class() . ' cannot be null.');
}
$pass = $property->getSetterPass();
$column = $property->getColumn();
if ($property->isBasicType()) {
if ($pass !== null) {
$value = $this->{$pass}($value);
}
if ($value !== null) {
settype($value, $property->getType());
}
if ($property->containsEnumeration() and !$property->isValueFromEnum($value)) {
throw new InvalidValueException("Given value is not from possible values enumeration in property '{$property->getName()}' in entity " . get_called_class() . '.');
}
$this->row->{$column} = $value;
return;
}
// property doesn't contain basic type
$type = $property->getType();
$givenType = gettype($value) !== 'object' ? gettype($value) : 'instance of ' . get_class($value);
if ($property->hasRelationship()) {
if ($value !== null) {
if (!$value instanceof $type) {
throw new InvalidValueException("Unexpected value type given in property '{$property->getName()}' in entity " . get_called_class() . ", {$property->getType()} expected, {$givenType} given.");
}
if ($value->isDetached()) {
// the value should be entity
throw new InvalidValueException("Detached entity cannot be assigned to property '{$property->getName()}' with relationship in entity " . get_called_class() . '.');
}
}
$this->assignEntityToProperty($value, $name);
// $pass is irrelevant relevant here
return;
}
//property doesn't contain basic type and property doesn't contain relationship
if ($property->containsCollection()) {
if (!is_array($value)) {
throw new InvalidValueException("Unexpected value type given in property '{$property->getName()}' in entity " . get_called_class() . ", array of {$property->getType()} expected, {$givenType} given.");
}
$this->row->{$column} = $pass !== null ? $this->{$pass}($value) : $value;
return;
}
if ($value !== null and !$value instanceof $type) {
throw new InvalidValueException("Unexpected value type given in property '{$property->getName()}' in entity " . get_called_class() . ", {$property->getType()} expected, {$givenType} given.");
}
$this->row->{$column} = $pass !== null ? $this->{$pass}($value) : $value;
}