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


PHP LifecycleEventArgs::getEntityManager方法代码示例

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


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

示例1: postPersist

 /**
  * postPersist
  *
  * @param LifecycleEventArgs $event
  */
 public function postPersist(LifecycleEventArgs $event)
 {
     //When the parent is created, the resource is load
     if ($event->getObject() == $this->context) {
         if ($this->accessor->isReadable($this->context, $this->property) && ($resource = $this->accessor->getValue($this->context, $this->property))) {
             if ($resource instanceof ResourceObjectInterface) {
                 $resource = $this->loader->load($this->context, $this->property, $this->file);
                 //to avoid bubbling with the preUpdate
                 //$this->context = null;
                 $event->getEntityManager()->flush($resource);
             }
         }
     } else {
         $meta = $event->getEntityManager()->getClassMetadata(get_class($this->context));
         $identifier = $meta->getSingleIdentifierColumnName();
         //when the parent exists but the resource is created
         if ($meta->getFieldValue($this->context, $identifier)) {
             if ($this->accessor->isReadable($this->context, $this->property) && $event->getObject() == $this->accessor->getValue($this->context, $this->property)) {
                 if (($resource = $event->getObject()) && $resource instanceof ResourceObjectInterface) {
                     $this->loader->load($this->context, $this->property, $this->file);
                     //to avoid bubbling with the preUpdate
                     //$this->context = null;
                     $event->getEntityManager()->flush($resource);
                 }
             }
         }
     }
 }
开发者ID:rafrsr,项目名称:resource-bundle,代码行数:33,代码来源:ResourceLoaderListener.php

示例2: prePersist

 public function prePersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     $classHierarchyMetadata = $this->metadataFactory->getMetadataForClass(get_class($entity));
     $classMetadata = $classHierarchyMetadata->classMetadata[get_class($entity)];
     foreach ($classMetadata->propertyMetadata as $propertyMetadata) {
         switch ($propertyMetadata->type) {
             case 'odm':
                 $dm = $this->doctrine->getManager($propertyMetadata->targetManager);
                 // Copied following two lines from Doctrine\ORM\Mapping\ClassMetadataFactory
                 list($namespaceAlias, $simpleClassName) = explode(':', $propertyMetadata->targetObject);
                 $realClassName = $dm->getConfiguration()->getDocumentNamespace($namespaceAlias) . '\\' . $simpleClassName;
                 /**
                  * @var \Doctrine\Common\Persistence\Mapping\ClassMetadata $documentMetaData
                  */
                 $documentMetaData = $dm->getClassMetadata($realClassName);
                 $document = $propertyMetadata->getValue($entity);
                 if (is_null($document)) {
                     continue;
                 }
                 $idValues = $documentMetaData->getIdentifierValues($document);
                 $propertyMetadata->setValue($entity, serialize($idValues));
                 $class = $args->getEntityManager()->getClassMetadata(get_class($entity));
                 $args->getEntityManager()->getUnitOfWork()->recomputeSingleEntityChangeSet($class, $entity);
                 break;
             case 'mongodb':
                 throw new \Exception('MongoDB is not yet implemented');
                 break;
             default:
                 break;
         }
     }
 }
开发者ID:netvlies,项目名称:doctrinebridgebundle,代码行数:33,代码来源:EntityListener.php

示例3: postPersist

 public function postPersist(LifecycleEventArgs $args)
 {
     $obj = $args->getEntity();
     // On veut envoyer un email que pour les entités Application
     if ($obj instanceof Article) {
         $article = $obj;
         $em = $args->getEntityManager();
         $news = new News();
         $news->setType("article");
         $news->setArticle($article);
         $news->createAbstract($article->getContent());
         $em->persist($news);
         $em->flush();
         //On flush pour créer l'id du content
     }
     if ($obj instanceof Playlist) {
         $playlist = $obj;
         $em = $args->getEntityManager();
         $news = new News();
         $news->setType("playlist");
         $news->setPlaylist($playlist);
         $news->createAbstract("");
         $em->persist($news);
         $em->flush();
         //On flush pour créer l'id du content
     }
     return;
 }
开发者ID:jleveau,项目名称:Le_Cerf_Vert,代码行数:28,代码来源:NewsCreator.php

示例4: prePersist

 /**
  * @param LifecycleEventArgs $args
  */
 public function prePersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if (!$this->isContactEntity($entity)) {
         return;
     }
     /** @var Contact $entity */
     $this->setCreatedProperties($entity, $args->getEntityManager());
     $this->setUpdatedProperties($entity, $args->getEntityManager());
 }
开发者ID:dairdr,项目名称:crm,代码行数:13,代码来源:ContactListener.php

示例5: prePersist

 public function prePersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof Vacancy) {
         $encoder = new UrlEncoder($args->getEntityManager());
         $entity->setUrlId($encoder->encode($entity, $entity->getTitle()));
     } else {
         if ($entity instanceof Organisation) {
             $encoder = new UrlEncoder($args->getEntityManager());
             $entity->setUrlId($encoder->encode($entity, $entity->getName()));
         }
     }
 }
开发者ID:howest-wsde,项目名称:VrijwilligersTool,代码行数:13,代码来源:UrlListener.php

示例6: prePersist

 /**
  * @param LifecycleEventArgs $args
  */
 public function prePersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if (!$this->isActivityListEntity($entity)) {
         return;
     }
     /** @var ActivityList $entity */
     if (!$entity->getCreatedAt()) {
         $this->setCreatedProperties($entity, $args->getEntityManager());
     }
     if (!$entity->getUpdatedAt()) {
         $this->setUpdatedProperties($entity, $args->getEntityManager());
     }
 }
开发者ID:northdakota,项目名称:platform,代码行数:17,代码来源:ActivityListChangesListener.php

示例7: postPersist

 /**
  * @param LifecycleEventArgs $event
  */
 public function postPersist(LifecycleEventArgs $event)
 {
     if (!$this->enabled) {
         return;
     }
     $this->loggableManager->handlePostPersist($event->getEntity(), $event->getEntityManager());
 }
开发者ID:Maksold,项目名称:platform,代码行数:10,代码来源:EntityListener.php

示例8: preRemove

 public function preRemove(LifecycleEventArgs $eventArgs)
 {
     $entity = $eventArgs->getEntity();
     if ($entity instanceof $this->objectClass) {
         $this->scheduleForRemoval($entity, $eventArgs->getEntityManager());
     }
 }
开发者ID:camdram,项目名称:sphinx-realtime-bundle,代码行数:7,代码来源:Listener.php

示例9: postPersist

 /**
  * Este escucha permite esteblecer el consecutivo de las entidades 
  * al momento de ser almacenadas en base de datos
  * @author Cesar Giraldo <cesargiraldo1108@gmail.com> 23/12/2015
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     $className = get_class($entity);
     $entityManager = $args->getEntityManager();
     $reflectedClass = new \ReflectionClass($className);
     if ($reflectedClass->hasProperty('consecutive')) {
         $consecutive = null;
         $enabledEntity = false;
         if ($entity instanceof Entity\Item) {
             $enabledEntity = true;
             //buscamos la cantidad de items que tiene creado un proyecto para asignar el consecutivo
             $project = $entity->getProject();
             $consecutive = $project->getLastItemConsecutive() + 1;
             $project->setLastItemConsecutive($consecutive);
             $entityManager->persist($project);
         } elseif ($entity instanceof Entity\Sprint) {
             $enabledEntity = true;
             //buscamos la cantidad de items que tiene creado un proyecto para asignar el consecutivo
             $project = $entity->getProject();
             $consecutive = $project->getLastSprintConsecutive() + 1;
             $project->setLastSprintConsecutive($consecutive);
             $entityManager->persist($project);
         }
         if ($enabledEntity) {
             if ($consecutive != null) {
                 $entity->setConsecutive($consecutive);
             } else {
                 $entity->setConsecutive(1);
             }
             $entityManager->flush();
         }
     }
 }
开发者ID:cesar-giraldo,项目名称:agile-scrum,代码行数:40,代码来源:Indexer.php

示例10: postPersist

 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     $entityManager = $args->getEntityManager();
     if ($entity instanceof Attachment) {
         //var_dump($entity); exit();
         if (null === $entity->getFile()) {
             return;
         }
         $id = sprintf('%010d', $entity->getId());
         $path = $entity->getStoragePath() . substr($id, 6, 4) . '/' . substr($id, 2, 4) . '/' . $id;
         $filename = $entity->getId() . '.' . $entity->getFile()->guessExtension();
         if (!file_exists($path)) {
             mkdir($path, 0777, true);
         }
         $entity->setFullpath($path . '/' . $filename);
         $entity->getFile()->move($path, $filename);
         $entity->setFile(null);
         /*
         $changelog = new Changelog();
         $changelog->setTable($entityManager->getClassMetadata('ProductsBundle:Product')->getTableName());
         $changelog->setAction('U');
         $changelog->setRecordId($entity->getId());
         $changelog->setUser($this->userCallable->getCurrentUser()->getId());
         $changelog->setRecordData($entity->jsonSerialize());
         */
         $entityManager->flush();
     }
 }
开发者ID:mishki-svami,项目名称:pa-core,代码行数:29,代码来源:AttachmentUpdater.php

示例11: preUpdate

 /**
  * @param LifecycleEventArgs $args
  */
 public function preUpdate(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof NodeTranslation) {
         $this->setSlugWhenEmpty($entity, $args->getEntityManager());
     }
 }
开发者ID:headonkeyboard,项目名称:KunstmaanBundlesCMS,代码行数:10,代码来源:NodeTranslationListener.php

示例12: checkBadWords

 /**
  * @param LifecycleEventArgs $args
  * @return bool
  * @throws \Exception
  */
 public function checkBadWords(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if (!$entity instanceof BadWordDetectorInterface) {
         return true;
     }
     $badWords = $args->getEntityManager()->getRepository('RenowazeBundle:BadWord')->findAll();
     /** @var BadWordDetector $annotationParams */
     $annotationParams = $this->reader->getClassAnnotation(new \ReflectionClass($entity), 'RenowazeBundle\\Annotation\\BadWordDetector');
     foreach ($annotationParams->fields as $field) {
         $methodName = 'get' . ucfirst($field);
         if (!method_exists($entity, $methodName)) {
             throw new \Exception(sprintf('Field "%s" not found in entity "%s"', $methodName, get_class($entity)));
         }
         /** @var BadWord $badWord */
         foreach ($badWords as $badWord) {
             if (strpos($entity->{$methodName}(), $badWord->getWord()) !== false) {
                 $entity->setHasBadWords(true);
                 return true;
             }
         }
     }
     $entity->setHasBadWords(false);
     return true;
 }
开发者ID:reggin,项目名称:BadWordExtension,代码行数:30,代码来源:BadWordDetectorDriver.php

示例13: process

 /**
  * @param LifecycleEventArgs $event
  */
 protected function process(LifecycleEventArgs $event)
 {
     /** @var Page $page */
     $page = $event->getEntity();
     if (!$this->isApplicable($page)) {
         return;
     }
     $expectedRoute = 'orob2b_cms_page_view';
     $expectedParameters = ['id' => $page->getId()];
     foreach ($page->getSlugs() as $slug) {
         $actualRoute = $slug->getRouteName();
         $actualParameters = $slug->getRouteParameters();
         $changeSet = [];
         if ($actualRoute !== $expectedRoute) {
             $slug->setRouteName($expectedRoute);
             $changeSet['routeName'] = [$actualRoute, $expectedRoute];
         }
         if ($actualParameters !== $expectedParameters) {
             $slug->setRouteParameters($expectedParameters);
             $changeSet['routeParameters'] = [$actualParameters, $expectedParameters];
         }
         if ($changeSet) {
             $unitOfWork = $event->getEntityManager()->getUnitOfWork();
             $unitOfWork->scheduleExtraUpdate($slug, $changeSet);
         }
     }
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:30,代码来源:PageSlugListener.php

示例14: checkRelations

 protected function checkRelations(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     $entityManager = $args->getEntityManager();
     $entityName = (new \ReflectionClass($entity))->getShortName();
     if (in_array($entityManager->getClassMetadata(get_class($entity))->name, $this->excludedEntities)) {
         return;
     }
     $mappings = $entityManager->getClassMetadata(get_class($entity))->getAssociationMappings();
     foreach ($mappings as $mapping) {
         if ($mapping['type'] === ClassMetadataInfo::ONE_TO_MANY || $mapping['type'] === ClassMetadataInfo::MANY_TO_MANY) {
             $targetEntityMeta = $entityManager->getClassMetadata($mapping['targetEntity']);
             if ($targetEntityMeta->reflClass->getParentClass()) {
                 if (in_array($targetEntityMeta->reflClass->getParentClass()->name, $this->ignoredEntities)) {
                     continue;
                 }
             }
             $accessor = PropertyAccess::createPropertyAccessor();
             $value = $accessor->getValue($entity, $mapping['fieldName']);
             if (count($value) === 0) {
                 continue;
             }
             $exception = new HasRelationException();
             $exception->setEntityName($entityName);
             $exception->setEntity($entity);
             $exception->setMapping($mapping);
             throw $exception;
         }
     }
 }
开发者ID:beyzakokcan,项目名称:ojs,代码行数:30,代码来源:SoftDeleteListener.php

示例15: preRemove

 /**
  * Pre remove event handler
  *
  * @param LifecycleEventArgs $args
  */
 public function preRemove(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     $classMetadata = $args->getEntityManager()->getClassMetadata(get_class($entity));
     $identifiers = $classMetadata->getIdentifierValues($entity);
     $this->inventory->setIdentifiers($entity, $identifiers);
 }
开发者ID:Tom32i,项目名称:symfony-event-demo,代码行数:12,代码来源:DoctrineSubscriber.php


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