本文整理汇总了PHP中Doctrine\Common\Persistence\Event\LifecycleEventArgs::getEntityManager方法的典型用法代码示例。如果您正苦于以下问题:PHP LifecycleEventArgs::getEntityManager方法的具体用法?PHP LifecycleEventArgs::getEntityManager怎么用?PHP LifecycleEventArgs::getEntityManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Event\LifecycleEventArgs
的用法示例。
在下文中一共展示了LifecycleEventArgs::getEntityManager方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postUpdate
/**
* Cette methode sera appelé depuis mon services.yml
* ET reçoie en argument mon evenement Doctrine 2
* @param LifecycleEventArgs $args
*/
public function postUpdate(LifecycleEventArgs $args)
{
// Je récupère mon objet après modification (update)
$entity = $args->getEntity();
$em = $args->getEntityManager();
// récupérer l'Entité Manager
// Si mon objet est un objet de mon entité Product
if ($entity instanceof Product) {
// récupéré le titre de mion produit
$title = $entity->getTitle();
# 2 tableaux avec accents
$a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'Ð', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', '?', '?', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', '?', '?', 'L', 'l', 'N', 'n', 'N', 'n', 'N', 'n', '?', 'O', 'o', 'O', 'o', 'O', 'o', 'Œ', 'œ', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'Š', 'š', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Ÿ', 'Z', 'z', 'Z', 'z', 'Ž', 'ž', '?', 'ƒ', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', '?', '?', '?', '?', '?', '?');
$b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
// slugifier mon titre stocké dans une variable slug
$slug = strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), str_replace($a, $b, $title)));
// setSlug me permet de modifier le slug de mon product
$entity->setSlug($slug);
$em->persist($entity);
//j'enregistre en base de données
$em->flush();
// quand la quantité sera égal à 1
if ($entity->getQuantity() == 1) {
$this->notification->notify($entity->getId(), 'Attention, votre produit ' . $entity->getTitle() . ' a une seule quantité', 'product', 'danger');
} else {
if ($entity->getQuantity() < 5) {
// je notifie la quantité de ce produit
// avec la methode notify()
$this->notification->notify($entity->getId(), 'Attention, votre produit ' . $entity->getTitle() . ' a un stocke bientôt épuisé', 'product', 'warning');
}
}
}
}
示例2: fixOrders
private function fixOrders(LifecycleEventArgs $event)
{
$entity = $event->getEntity();
if (!$entity instanceof \UR\DB\NewBundle\Entity\BasePerson) {
return;
}
$personId = $entity->getId();
$this->LOGGER->debug("Fixing orders for ID: " . $personId);
$em = $event->getEntityManager();
$education = $em->getRepository('NewBundle:Education')->findBy(array('person' => $personId), array('educationOrder' => 'ASC'));
$this->fixArray($em, $education, PersonInformation::EDUCATION);
$honour = $em->getRepository('NewBundle:Honour')->findBy(array('person' => $personId), array('honourOrder' => 'ASC'));
$this->fixArray($em, $honour, PersonInformation::HONOUR);
$property = $em->getRepository('NewBundle:Property')->findBy(array('person' => $personId), array('propertyOrder' => 'ASC'));
$this->fixArray($em, $property, PersonInformation::PROPERTY);
$rank = $em->getRepository('NewBundle:Rank')->findBy(array('person' => $personId), array('rankOrder' => 'ASC'));
$this->fixArray($em, $rank, PersonInformation::RANK);
$religion = $em->getRepository('NewBundle:Religion')->findBy(array('person' => $personId), array('religionOrder' => 'ASC'));
$this->fixArray($em, $religion, PersonInformation::RELIGION);
$roadOfLife = $em->getRepository('NewBundle:RoadOfLife')->findBy(array('person' => $personId), array('roadOfLifeOrder' => 'ASC'));
$this->fixArray($em, $roadOfLife, PersonInformation::ROAD_OF_LIFE);
$status = $em->getRepository('NewBundle:Status')->findBy(array('person' => $personId), array('statusOrder' => 'ASC'));
$this->fixArray($em, $status, PersonInformation::STATUS);
$works = $em->getRepository('NewBundle:Works')->findBy(array('person' => $personId), array('worksOrder' => 'ASC'));
$this->fixArray($em, $works, PersonInformation::WORK);
if ($entity instanceof \UR\DB\NewBundle\Entity\Person) {
$source = $em->getRepository('NewBundle:Source')->findBy(array('person' => $personId), array('sourceOrder' => 'ASC'));
$this->fixArray($em, $source, PersonInformation::SOURCE);
}
$em->flush();
}
示例3: createThread
/**
* @ORM\PostPersist
*/
public function createThread(LifecycleEventArgs $args)
{
if ($this->getThread() === null) {
$em = $args->getEntityManager();
$t = new Thread();
$t->setId('prospect_' . $this->getId());
$this->setThread($t);
$this->getThread()->setPermalink('fake');
$em->persist($t);
$em->flush();
}
}
示例4: prePersist
/**
* @param LifecycleEventArgs $args
*/
public function prePersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
// only act on some "Product" entity
if (!$entity instanceof Personne) {
return;
}
$entityManager = $args->getEntityManager();
// ... do something with the Product
$logger = $this->get('logger');
$logger->addDebug('Doctrine event: personne: ' . $entity->getStatus());
}
示例5: prePersist
public function prePersist(LifecycleEventArgs $eventArgs)
{
$entity = $eventArgs->getObject();
if ($entity instanceof SortableInterface) {
$em = $eventArgs->getEntityManager();
$repo = $em->getRepository($em->getClassMetadata(get_class($entity))->getName());
$config = $repo->getSortableConfiguration();
$setter = 'set' . Parser::camelize($config['position']);
$getter = 'get' . Parser::camelize($config['position']);
if ($entity->{$getter}() === null) {
$entity->{$setter}($repo->getNewOrder($entity, 'sort'));
}
}
}
示例6: saveDateToDB
private function saveDateToDB(LifecycleEventArgs $event)
{
$entity = $event->getEntity();
$em = $event->getEntityManager();
$this->LOGGER->debug("Saving Dates to db for: " . $entity);
switch (get_class($entity)) {
case "UR\\DB\\NewBundle\\Entity\\Date":
return;
case "UR\\DB\\NewBundle\\Entity\\Partner":
case "UR\\DB\\NewBundle\\Entity\\Person":
case "UR\\DB\\NewBundle\\Entity\\Relative":
$this->LOGGER->debug("Found 'person' entity: " . $entity);
//@TODO: Is there sth to do here?
break;
case "UR\\DB\\NewBundle\\Entity\\Baptism":
$this->LOGGER->debug("Found baptism entity");
$this->saveDateReference($em, $entity->getBaptismDate());
break;
case "UR\\DB\\NewBundle\\Entity\\Birth":
$this->LOGGER->debug("Found birth entity");
$this->saveDateReference($em, $entity->getBirthDate());
$this->saveDateReference($em, $entity->getProvenDate());
break;
case "UR\\DB\\NewBundle\\Entity\\Death":
$this->LOGGER->debug("Found death entity");
$this->saveDateReference($em, $entity->getDeathDate());
$this->saveDateReference($em, $entity->getFuneralDate());
break;
case "UR\\DB\\NewBundle\\Entity\\Education":
$this->LOGGER->debug("Found education entity");
$this->saveFromToProvenDates($em, $entity);
$this->saveDateReference($em, $entity->getGraduationDate());
break;
case "UR\\DB\\NewBundle\\Entity\\Honour":
$this->LOGGER->debug("Found honour entity");
$this->saveFromToProvenDates($em, $entity);
break;
case "UR\\DB\\NewBundle\\Entity\\Property":
$this->LOGGER->debug("Found property entity");
$this->saveFromToProvenDates($em, $entity);
break;
case "UR\\DB\\NewBundle\\Entity\\Rank":
$this->LOGGER->debug("Found rank entity");
$this->saveFromToProvenDates($em, $entity);
break;
case "UR\\DB\\NewBundle\\Entity\\Religion":
$this->LOGGER->debug("Found religion entity");
$this->saveFromToProvenDates($em, $entity);
break;
case "UR\\DB\\NewBundle\\Entity\\RoadOfLife":
$this->LOGGER->debug("Found roadOfLife entity");
$this->saveFromToProvenDates($em, $entity);
break;
case "UR\\DB\\NewBundle\\Entity\\Status":
$this->LOGGER->debug("Found status entity");
$this->saveFromToProvenDates($em, $entity);
break;
case "UR\\DB\\NewBundle\\Entity\\Wedding":
$this->LOGGER->debug("Found wedding entity");
$this->saveDateReference($em, $entity->getWeddingDate());
$this->saveDateReference($em, $entity->getBannsDate());
$this->saveDateReference($em, $entity->getBreakupDate());
$this->saveDateReference($em, $entity->getProvenDate());
break;
case "UR\\DB\\NewBundle\\Entity\\Works":
$this->LOGGER->debug("Found works entity");
$this->saveFromToProvenDates($em, $entity);
break;
default:
$this->LOGGER->debug("Nothing to do here");
break;
}
$this->LOGGER->debug("Finished saving Dates to db for: " . $entity);
//NO FLUSH ALLOWED IN PRE UPDATE/ PRE PERSIST!
//http://stackoverflow.com/questions/30576245/infinite-loop-in-doctrine-event-listener-when-trying-to-save-additional-entity
}