本文整理汇总了PHP中Doctrine\Common\Persistence\Event\LifecycleEventArgs类的典型用法代码示例。如果您正苦于以下问题:PHP LifecycleEventArgs类的具体用法?PHP LifecycleEventArgs怎么用?PHP LifecycleEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LifecycleEventArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preUpdate
public function preUpdate(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof User) {
$this->updatePassword($entity);
}
}
示例2: postRemove
public function postRemove(LifecycleEventArgs $event)
{
$object = $event->getObject();
$reflection = new \ReflectionClass($object);
$message = sprintf('%s deleted', $reflection->getShortName());
$this->logger->notice($message, $this->getContext($object));
}
示例3: prePersist
public function prePersist(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof FileInterface) {
$object->upload();
}
}
示例4: PostUpdate
public function PostUpdate(LifecycleEventArgs $args)
{
$entity = $args->getObject();
$em = $args->getObjectManager();
$classMetaData = $em->getClassMetadata(get_class($entity));
foreach ($classMetaData->associationMappings as $associationMappingKey => $associationMappingDatas) {
if ($associationMappingDatas['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::ONE_TO_MANY) {
$repo = $em->getRepository($associationMappingDatas['targetEntity']);
$associated = $repo->findBy([$associationMappingDatas['mappedBy'] => $entity]);
$newAssociated = call_user_func([$entity, 'get' . ucfirst($associationMappingKey)]);
$changed = false;
foreach ($associated as $associatedEntity) {
if (!$newAssociated->contains($associatedEntity)) {
$changed = true;
$em->remove($associatedEntity);
}
}
if ($changed) {
$em->flush();
}
//
}
}
// dump($classMetaData);
// die();
}
示例5: updateRoute
protected function updateRoute(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof MenuInterface) {
$object->setRouter($this->router);
}
}
示例6: postPersist
/**
* @param EventArgs|LifecycleEventArgs $args
*/
public function postPersist(LifecycleEventArgs $args)
{
$entity = $args->getObject();
$em = $args->getObjectManager();
if ($entity instanceof Comment) {
if ($entity->getArticleId() != null) {
if ($entity->getUserId()->getId() != $entity->getArticleId()->getUserId()->getId()) {
$n = new Notification();
$n->setUser($entity->getUserId())->setArticle($entity->getArticleId());
$em->persist($n);
$em->flush();
}
} else {
if ($entity->getVideoId() != null) {
if ($entity->getUserId()->getId() != $entity->getVideoId()->getUserId()->getId()) {
$n = new Notification();
$n->setUser($entity->getUserId())->setVideo($entity->getVideoId());
$em->persist($n);
$em->flush();
}
} else {
if ($entity->getLinkId() != null) {
if ($entity->getUserId()->getId() != $entity->getLinkId()->getUserId()->getId()) {
$n = new Notification();
$n->setUser($entity->getUserId())->setLink($entity->getLinkId());
$em->persist($n);
$em->flush();
}
}
}
}
}
}
示例7: preUpdate
/**
* Pre update
* PreUpdate event needs to recompute change set
*
* @param LifecycleEventArgs $args
*/
public function preUpdate(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof AbstractMetric && $object->getUnit()) {
$this->createMetricBaseValues($object);
}
}
示例8:
function it_applies_during_pre_update_on_timestampable_object(LifecycleEventArgs $args, TimestampableInterface $object)
{
$args->getObject()->willReturn($object);
$object->setCreated()->shouldNotBeCalled();
$object->setUpdated(Argument::type('\\DateTime'))->shouldBeCalled();
$this->preUpdate($args);
}
示例9: preUpdate
public function preUpdate(LifecycleEventArgs $args)
{
$entity = $args->getObject();
if (method_exists($entity, 'setUpdateDate')) {
$entity->setUpdateDate(new \DateTime());
}
}
示例10: preRemove
/**
* Removes image file
* @param LifecycleEventArgs $event
*/
public function preRemove(LifecycleEventArgs $event)
{
$entity = $event->getEntity();
if ($entity instanceof ImageInterface) {
$this->uploader->remove($entity);
}
}
示例11: preUpdate
/**
* @param LifecycleEventArgs $eventArgs
*/
public function preUpdate(LifecycleEventArgs $eventArgs)
{
$object = $eventArgs->getObject();
if ($this->isSluggable($object)) {
$this->updateSlug($object);
}
}
示例12: postUpdate
/**
* Control object dms
*
* @param LifecycleEventArgs $args
*/
public function postUpdate(LifecycleEventArgs $args)
{
$entity = $args->getObject();
if ($entity instanceof GedableInterface) {
$this->manageNodeTree($entity->getGedTree());
}
}
示例13: preUpdate
/**
* Pre update listener based on doctrine commons, overwrite to update
* the changeset in the UoW and to handle non-common event argument
* class.
*
* @param LifecycleEventArgs $args weak typed to allow overwriting
*/
public function preUpdate($args)
{
$object = $args->getObject();
if ($object instanceof UserInterface) {
$this->updateUserFields($object);
}
}
示例14:
function it_marks_indexed_product_values_outdated_after_loading_a_value(LifecycleEventArgs $args, ProductValueInterface $value, ProductInterface $entity)
{
$args->getObject()->willReturn($value);
$value->getEntity()->willReturn($entity);
$entity->markIndexedValuesOutdated()->shouldBeCalled();
$this->postLoad($args);
}
示例15: 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();
}