本文整理汇总了PHP中Doctrine\ORM\ORMInvalidArgumentException::invalidAssociation方法的典型用法代码示例。如果您正苦于以下问题:PHP ORMInvalidArgumentException::invalidAssociation方法的具体用法?PHP ORMInvalidArgumentException::invalidAssociation怎么用?PHP ORMInvalidArgumentException::invalidAssociation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\ORMInvalidArgumentException
的用法示例。
在下文中一共展示了ORMInvalidArgumentException::invalidAssociation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cascadePersist
/**
* Cascades the save operation to associated entities.
*
* @param object $entity
* @param array $visited
*
* @return void
*/
private function cascadePersist($entity, array &$visited)
{
$class = $this->em->getClassMetadata(get_class($entity));
$associationMappings = array_filter($class->associationMappings, function ($assoc) {
return $assoc['isCascadePersist'];
});
foreach ($associationMappings as $assoc) {
$relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity);
switch (true) {
case $relatedEntities instanceof PersistentCollection:
// Unwrap so that foreach() does not initialize
$relatedEntities = $relatedEntities->unwrap();
// break; is commented intentionally!
// break; is commented intentionally!
case $relatedEntities instanceof Collection:
case is_array($relatedEntities):
if (($assoc['type'] & ClassMetadata::TO_MANY) <= 0) {
throw ORMInvalidArgumentException::invalidAssociation($this->em->getClassMetadata($assoc['targetEntity']), $assoc, $relatedEntities);
}
foreach ($relatedEntities as $relatedEntity) {
$this->doPersist($relatedEntity, $visited);
}
break;
case $relatedEntities !== null:
if (!$relatedEntities instanceof $assoc['targetEntity']) {
throw ORMInvalidArgumentException::invalidAssociation($this->em->getClassMetadata($assoc['targetEntity']), $assoc, $relatedEntities);
}
$this->doPersist($relatedEntities, $visited);
break;
default:
// Do nothing
}
}
}