当前位置: 首页>>代码示例>>PHP>>正文


PHP ORMInvalidArgumentException::invalidAssociation方法代码示例

本文整理汇总了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
         }
     }
 }
开发者ID:SylvainSimon,项目名称:Metinify,代码行数:42,代码来源:UnitOfWork.php


注:本文中的Doctrine\ORM\ORMInvalidArgumentException::invalidAssociation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。