本文整理汇总了PHP中Doctrine\ORM\EntityManagerInterface::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::merge方法的具体用法?PHP EntityManagerInterface::merge怎么用?PHP EntityManagerInterface::merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::merge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getReference
/**
* {@inheritDoc}
*/
public function getReference($name, $property = null)
{
if (isset($this->objectsCache[$name])) {
try {
$reference = $this->entityManager->merge($this->objectsCache[$name]);
} catch (\Exception $e) {
var_dump($e->getMessage());
var_dump($this->objectsCache[$name]);
exit;
}
} else {
if (isset($this->references[$name])) {
$reference = $this->references[$name];
} else {
throw new \UnexpectedValueException('Reference ' . $name . ' is not defined');
}
}
if ($property !== null) {
if (property_exists($reference, $property)) {
$prop = new \ReflectionProperty($reference, $property);
if ($prop->isPublic()) {
return $reference->{$property};
}
}
$getter = 'get' . ucfirst($property);
if (method_exists($reference, $getter) && is_callable(array($reference, $getter))) {
return $reference->{$getter}();
}
throw new \UnexpectedValueException('Property ' . $property . ' is not defined for reference ' . $name);
}
return $reference;
}
示例2: saveCountries
/**
* @param array $countries
*/
public function saveCountries($countries)
{
foreach ($countries as $country) {
if ($this->em->find('MainBundle:Country', $country->getCodeCountry())) {
$this->em->merge($country);
} else {
$this->em->persist($country);
}
}
$this->em->flush();
}
示例3: prepare
private function prepare($data)
{
$metaDataClass = $this->entityManager->getClassMetadata(get_class($data));
$assocFields = $metaDataClass->getAssociationMappings();
foreach ($assocFields as $assoc) {
$relatedEntities = $metaDataClass->reflFields[$assoc['fieldName']]->getValue($data);
if ($relatedEntities instanceof Collection) {
if ($relatedEntities === $metaDataClass->reflFields[$assoc['fieldName']]->getValue($data)) {
continue;
}
if ($relatedEntities instanceof PersistentCollection) {
// Unwrap so that foreach() does not initialize
$relatedEntities = $relatedEntities->unwrap();
}
foreach ($relatedEntities as $relatedEntity) {
$relatedEntitiesState = $this->entityManager->getUnitOfWork()->getEntityState($relatedEntities);
if ($relatedEntitiesState === UnitOfWork::STATE_DETACHED) {
$metaDataClass->setFieldValue($data, $assoc['fieldName'], $this->entityManager->merge($relatedEntity));
}
}
} else {
if ($relatedEntities !== null) {
$relatedEntitiesState = $this->entityManager->getUnitOfWork()->getEntityState($relatedEntities);
if ($relatedEntitiesState === UnitOfWork::STATE_DETACHED) {
$metaDataClass->setFieldValue($data, $assoc['fieldName'], $this->entityManager->merge($relatedEntities));
}
}
}
}
}
示例4: saveSections
/**
* @param array $sections
*/
public function saveSections($sections)
{
foreach ($sections as $section) {
$oldSection = $this->sectionFetcher->getSection($section->getCodeSection());
if (!$oldSection) {
$this->em->persist($section);
$this->em->flush();
} else {
$section->setGuide($oldSection->getGuide());
$section->setToken($oldSection->getToken());
$section->setLogoUrl($oldSection->getLogoUrl());
$section->setAddedAt($oldSection->getAddedAt());
$section->setActivated($oldSection->isActivated());
$section->setUpdatedAt();
$this->em->merge($section);
$this->em->flush();
}
}
}
示例5: merge
private function merge(Article $article)
{
$this->em->merge($article);
}
示例6: mergeAndPersist
public function mergeAndPersist(EntityManagerInterface $entityManager)
{
$settings = $entityManager->merge($this);
$entityManager->persist($settings);
return $settings;
}
示例7: mergeAndPersist
public function mergeAndPersist(EntityManagerInterface $entityManager)
{
$tempOptions = array();
foreach ($this->list->getOptions() as $option) {
if (!$option->getSelectAttributeOptionID()) {
$tempOptions[] = $option;
$this->list->getOptions()->removeElement($option);
}
}
$settings = $entityManager->merge($this);
foreach ($tempOptions as $option) {
$option->setOptionList($settings->list);
$settings->list->getOptions()->add($option);
}
$entityManager->persist($settings);
return $settings;
}
示例8: delete
/**
* @param $entity
* @return mixed
*/
public function delete($entity)
{
$entity = $this->entityManager->merge($entity);
$this->entityManager->remove($entity);
$this->entityManager->flush();
}