You are here

private function PersistentObject::set in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/doctrine/common/lib/Doctrine/Common/Persistence/PersistentObject.php \Doctrine\Common\Persistence\PersistentObject::set()

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 vendor/doctrine/common/lib/Doctrine/Common/Persistence/PersistentObject.php
Magic methods.

File

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