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


PHP LifecycleEventArgs::getObjectManager方法代码示例

本文整理汇总了PHP中Doctrine\Common\Persistence\Event\LifecycleEventArgs::getObjectManager方法的典型用法代码示例。如果您正苦于以下问题:PHP LifecycleEventArgs::getObjectManager方法的具体用法?PHP LifecycleEventArgs::getObjectManager怎么用?PHP LifecycleEventArgs::getObjectManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Persistence\Event\LifecycleEventArgs的用法示例。


在下文中一共展示了LifecycleEventArgs::getObjectManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: preRemove

 public function preRemove(LifecycleEventArgs $args)
 {
     $entity = $args->getObject();
     if ($entity instanceof Page) {
         $menuElements = $args->getObjectManager()->getRepository('SKCMSCoreBundle:MenuElement')->findBy(['entityClass' => '\\' . get_class($entity), 'entityId' => $entity->getId()]);
         foreach ($menuElements as $menuElement) {
             $args->getObjectManager()->remove($menuElement);
         }
     }
 }
开发者ID:kokmok,项目名称:SKCMS-Core,代码行数:10,代码来源:DeletedEntityFixMenu.php

示例2: postPersist

 /**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getObject();
     if ($entity instanceof Dog || $entity instanceof Member || $entity instanceof Affiliate) {
         if (!$entity->getRegNumber()) {
             $entity->setRegNumber($this->generateRegNumber($entity->getId()));
             $tableName = $args->getObjectManager()->getClassMetadata(get_class($entity))->getTableName();
             $dbConnection = $args->getObjectManager()->getConnection();
             $dbConnection->executeUpdate('UPDATE ' . $tableName . ' SET regNumber = ? WHERE id = ?', array($entity->getRegNumber(), $entity->getId()));
         }
     }
 }
开发者ID:PoetikDragon,项目名称:USCSS,代码行数:15,代码来源:RegNumberSubscriber.php

示例3: 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();
 }
开发者ID:kokmok,项目名称:SKCMS-Admin,代码行数:26,代码来源:OneToManyDeleteListener.php

示例4: 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();
                     }
                 }
             }
         }
     }
 }
开发者ID:ugra92,项目名称:knowledgems,代码行数:36,代码来源:NotificationListener.php

示例5: preUpdate

 /**
  * Pre update
  * PreUpdate event needs to recompute change set
  *
  * @param LifecycleEventArgs $args
  */
 public function preUpdate(LifecycleEventArgs $args)
 {
     $product = $args->getObject();
     if ($product instanceof ProductInterface) {
         $dm = $args->getObjectManager();
         $this->convertMetricValues($dm, $product);
     }
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:14,代码来源:MetricBaseValuesSubscriber.php

示例6: postTruncate

 /**
  * Post-truncate
  *
  * @param \Doctrine\Common\Persistence\Event\LifecyleEventArgs $args
  */
 public function postTruncate(LifecycleEventArgs $args)
 {
     $connection = $args->getObjectManager()->getConnection();
     $platform = $connection->getDatabasePlatform();
     if ($platform instanceof MySqlPlatform) {
         $connection->exec('SET foreign_key_checks = 1;');
     }
 }
开发者ID:Spomky,项目名称:DoctrineDataFixturesExtension,代码行数:13,代码来源:PlatformListener.php

示例7: preUpdate

 /**
  * Pre update listener based on doctrine common
  *
  * @param LifecycleEventArgs $args
  */
 public function preUpdate(LifecycleEventArgs $args)
 {
     $object = $args->getObject();
     if ($object instanceof UserInterface) {
         $this->updateUserFields($object);
         $this->recomputeChangeSet($args->getObjectManager(), $object);
     }
 }
开发者ID:bakie,项目名称:FOSUserBundle,代码行数:13,代码来源:UserListener.php

示例8: updateSlug

 /**
  * @param LifecycleEventArgs $lifecycleEventArgs
  */
 private function updateSlug(LifecycleEventArgs $lifecycleEventArgs)
 {
     $object = $lifecycleEventArgs->getObject();
     $productTranslationRepository = $lifecycleEventArgs->getObjectManager()->getRepository(get_class($object));
     $slug = $this->slugify($object->getName(), $productTranslationRepository);
     $object->setSlug($slug);
     $this->generatedSlugs[] = $slug;
 }
开发者ID:pavelnovitsky,项目名称:Sylius,代码行数:11,代码来源:ProductTranslationSlugEventListener.php

示例9: prePersist

 public function prePersist(LifecycleEventArgs $args)
 {
     $entity = $args->getObject();
     if ($entity instanceof PaymentInterface) {
         $generator = new UuidGenerator();
         $token = $generator->generate($args->getObjectManager(), null);
         $entity->setToken($token);
     }
 }
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:9,代码来源:PaymentDoctrineEventSubscriber.php

示例10: preUpdate

 /**
  * Pre update
  * PreUpdate event needs to recompute change set
  *
  * @param LifecycleEventArgs $args
  */
 public function preUpdate(LifecycleEventArgs $args)
 {
     $object = $args->getObject();
     if ($object instanceof MetricInterface && $object->getUnit()) {
         $this->createMetricBaseValues($object);
         $class = new ClassMetadata($object);
         $args->getObjectManager()->getUnitOfWork()->recomputeSingleDocumentChangeSet($class, $object);
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:15,代码来源:MetricBaseValuesSubscriber.php

示例11: postLoad

 public function postLoad(LifecycleEventArgs $args)
 {
     $object = $args->getObject();
     if ($object instanceof ComponentInterface) {
         $resolver = new Resolver($args->getObjectManager());
         $resolverComponent = new ResolverComponentModelIdentifier($object->getModel(), $object->getIdentifier());
         $object->setData($resolver->resolve($resolverComponent));
     }
 }
开发者ID:undefined-exception-coders,项目名称:DCSNotificationBundle,代码行数:9,代码来源:DoctrineEventListener.php

示例12: deleteChildren

 /**
  * @ORM\PreRemove
  * @param LifecycleEventArgs $args
  * @throws \Exception
  */
 public function deleteChildren(LifecycleEventArgs $args)
 {
     $objectManager = $args->getObjectManager();
     $entityType = $objectManager->getRepository('Comment\\Entity\\EntityType')->findOneByAlias('comment');
     $commentRepository = $objectManager->getRepository('Comment\\Entity\\Comment');
     $comments = $commentRepository->findBy(array('entityType' => $entityType, 'entityId' => $this->getId()));
     foreach ($comments as $comment) {
         $objectManager->remove($comment);
     }
 }
开发者ID:zfury,项目名称:cmf,代码行数:15,代码来源:Comment.php

示例13: prePersist

 public function prePersist(LifecycleEventArgs $args)
 {
     /** @var User $entity */
     $entity = $args->getObject();
     /** @var EntityManager $em */
     $em = $args->getObjectManager();
     if ($entity instanceof User && $entity->getTeamId() && !$entity->getTeam()) {
         /** @var Team $team */
         $team = $em->getRepository('Patgod85TeamBundle:Team')->find($entity->getTeamId());
         $entity->setTeam($team);
     }
 }
开发者ID:patgod85,项目名称:timesheet2,代码行数:12,代码来源:UserEventListener.php

示例14: handleTimestamp

 /**
  * Set the timestamps. If created is NULL then set it. Always
  * set the changed field.
  *
  * @param LifecycleEventArgs $event
  */
 private function handleTimestamp(LifecycleEventArgs $event)
 {
     $entity = $event->getObject();
     if (!$entity instanceof TimestampableInterface) {
         return;
     }
     $meta = $event->getObjectManager()->getClassMetadata(get_class($entity));
     $created = $meta->getFieldValue($entity, self::CREATED_FIELD);
     if (null === $created) {
         $meta->setFieldValue($entity, self::CREATED_FIELD, new \DateTime());
     }
     $meta->setFieldValue($entity, self::CHANGED_FIELD, new \DateTime());
 }
开发者ID:Silwereth,项目名称:sulu,代码行数:19,代码来源:TimestampableSubscriber.php

示例15: clearCache

 protected function clearCache(LifecycleEventArgs $args)
 {
     $entity = $args->getObject();
     $classes = $this->classes;
     foreach ($classes as $class) {
         if ($entity instanceof $class) {
             $this->app['monolog']->debug('clear result cache: ' . $class);
             $cache = $args->getObjectManager()->getConfiguration()->getResultCacheImpl();
             $cache->deleteAll();
             break;
         }
     }
 }
开发者ID:ec-cube,项目名称:ec-cube,代码行数:13,代码来源:ClearCacheEventSubscriber.php


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