You are here

private function PersistentObject::set in Plug 7

Sets a persistent fields value.

Parameters

string $field:

array $args:

Return value

void

Throws

\BadMethodCallException When no persistent field exists by that name.

\InvalidArgumentException When the wrong target object type is passed to an association.

1 call to PersistentObject::set()
PersistentObject::__call in lib/doctrine/common/lib/Doctrine/Common/Persistence/PersistentObject.php
Magic methods.

File

lib/doctrine/common/lib/Doctrine/Common/Persistence/PersistentObject.php, line 120

Class

PersistentObject
PersistentObject base class that implements getter/setter methods for all mapped fields and associations by overriding __call.

Namespace

Doctrine\Common\Persistence

Code

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() . "'");
    }
  }
}