當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。