Sets a persistent fields value.
string $field:
array $args:
void
\BadMethodCallException - When no persistent field exists by that name.
\InvalidArgumentException - When the wrong target object type is passed to an association
private function set($field, $args) {
$this
->initializeDoctrine();
if ($this->cm
->hasField($field) && !$this->cm
->isIdentifier($field)) {
$this->{$field} = $args[0];
}
else {
if ($this->cm
->hasAssociation($field) && $this->cm
->isSingleValuedAssociation($field)) {
$targetClass = $this->cm
->getAssociationTargetClass($field);
if (!$args[0] instanceof $targetClass && $args[0] !== null) {
throw new \InvalidArgumentException("Expected persistent object of type '" . $targetClass . "'");
}
$this->{$field} = $args[0];
$this
->completeOwningSide($field, $targetClass, $args[0]);
}
else {
throw new \BadMethodCallException("no field with name '" . $field . "' exists on '" . $this->cm
->getName() . "'");
}
}
}