/** * Collects the parameters for inserting/deleting on the join table in the order * of the join table columns as specified in ManyToManyMapping#joinTableColumns. * * @param $coll * @param $element * @return array */ private function _collectJoinTableColumnParameters(PersistentCollection $coll, $element) { $params = array(); $mapping = $coll->getMapping(); $isComposite = count($mapping['joinTableColumns']) > 2; $identifier1 = $this->_uow->getEntityIdentifier($coll->getOwner()); $identifier2 = $this->_uow->getEntityIdentifier($element); if ($isComposite) { $class1 = $this->_em->getClassMetadata(get_class($coll->getOwner())); $class2 = $coll->getTypeClass(); } foreach ($mapping['joinTableColumns'] as $joinTableColumn) { if (isset($mapping['relationToSourceKeyColumns'][$joinTableColumn])) { if ($isComposite) { if ($class1->containsForeignIdentifier) { $params[] = $identifier1[$class1->getFieldForColumn($mapping['relationToSourceKeyColumns'][$joinTableColumn])]; } else { $params[] = $identifier1[$class1->fieldNames[$mapping['relationToSourceKeyColumns'][$joinTableColumn]]]; } } else { $params[] = array_pop($identifier1); } } else { if ($isComposite) { if ($class2->containsForeignIdentifier) { $params[] = $identifier2[$class2->getFieldForColumn($mapping['relationToTargetKeyColumns'][$joinTableColumn])]; } else { $params[] = $identifier2[$class2->fieldNames[$mapping['relationToTargetKeyColumns'][$joinTableColumn]]]; } } else { $params[] = array_pop($identifier2); } } } return $params; }
/** * Collects the parameters for inserting/deleting on the join table in the order * of the join table columns as specified in ManyToManyMapping#joinTableColumns. * * @param \Doctrine\ORM\PersistentCollection $coll * @param object $element * * @return array */ private function collectJoinTableColumnParameters(PersistentCollection $coll, $element) { $params = array(); $mapping = $coll->getMapping(); $isComposite = count($mapping['joinTableColumns']) > 2; $identifier1 = $this->uow->getEntityIdentifier($coll->getOwner()); $identifier2 = $this->uow->getEntityIdentifier($element); if ($isComposite) { $class1 = $this->em->getClassMetadata(get_class($coll->getOwner())); $class2 = $coll->getTypeClass(); } foreach ($mapping['joinTableColumns'] as $joinTableColumn) { $isRelationToSource = isset($mapping['relationToSourceKeyColumns'][$joinTableColumn]); if (!$isComposite) { $params[] = $isRelationToSource ? array_pop($identifier1) : array_pop($identifier2); continue; } if ($isRelationToSource) { $params[] = $identifier1[$class1->getFieldForColumn($mapping['relationToSourceKeyColumns'][$joinTableColumn])]; continue; } $params[] = $identifier2[$class2->getFieldForColumn($mapping['relationToTargetKeyColumns'][$joinTableColumn])]; } return $params; }
/** * Gets the real fully-qualified class name of the given object (even if its a proxy). * * @param string|object|array|PersistentCollection $object * @return string * @throws RuntimeException */ public function getClassName($object) { if ($object instanceof PersistentCollection) { $className = $object->getTypeClass()->getName(); } elseif (is_string($object)) { $className = ClassUtils::getRealClass($object); } elseif (is_object($object)) { $className = ClassUtils::getClass($object); } elseif (is_array($object) && count($object) && is_object(reset($object))) { $className = ClassUtils::getClass(reset($object)); } else { $className = $object; } if (!is_string($className)) { throw new RuntimeException(sprintf('ConfigProvider::getClassName expects Object, ' . 'PersistentCollection, array of entities or string. "%s" given', gettype($className))); } return $className; }