private function PersistentObject::add in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/doctrine/common/lib/Doctrine/Common/Persistence/PersistentObject.php \Doctrine\Common\Persistence\PersistentObject::add()
Adds an object to a collection.
Parameters
string $field:
array $args:
Return value
void
Throws
\BadMethodCallException
\InvalidArgumentException
1 call to PersistentObject::add()
- 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 191
Class
- PersistentObject
- PersistentObject base class that implements getter/setter methods for all mapped fields and associations by overriding __call.
Namespace
Doctrine\Common\PersistenceCode
private function add($field, $args) {
$this
->initializeDoctrine();
if ($this->cm
->hasAssociation($field) && $this->cm
->isCollectionValuedAssociation($field)) {
$targetClass = $this->cm
->getAssociationTargetClass($field);
if (!$args[0] instanceof $targetClass) {
throw new \InvalidArgumentException("Expected persistent object of type '" . $targetClass . "'");
}
if (!$this->{$field} instanceof Collection) {
$this->{$field} = new ArrayCollection($this->{$field} ?: array());
}
$this->{$field}
->add($args[0]);
$this
->completeOwningSide($field, $targetClass, $args[0]);
}
else {
throw new \BadMethodCallException("There is no method add" . $field . "() on " . $this->cm
->getName());
}
}