當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PreUpdateEventArgs::getObjectManager方法代碼示例

本文整理匯總了PHP中Doctrine\ORM\Event\PreUpdateEventArgs::getObjectManager方法的典型用法代碼示例。如果您正苦於以下問題:PHP PreUpdateEventArgs::getObjectManager方法的具體用法?PHP PreUpdateEventArgs::getObjectManager怎麽用?PHP PreUpdateEventArgs::getObjectManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ORM\Event\PreUpdateEventArgs的用法示例。


在下文中一共展示了PreUpdateEventArgs::getObjectManager方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: preUpdate

 public function preUpdate(Show $show, PreUpdateEventArgs $event)
 {
     $this->updateFields($show, $event->getObjectManager());
     $em = $event->getObjectManager();
     $uow = $em->getUnitOfWork();
     $meta = $em->getClassMetadata(get_class($show));
     $uow->recomputeSingleEntityChangeSet($meta, $show);
     //ensure all the associated performances are also saved
     $performanceMeta = $em->getClassMetadata('ActsCamdramBundle:Performance');
     foreach ($show->getPerformances() as $performance) {
         $performance->setShow($show);
         $uow->recomputeSingleEntityChangeSet($performanceMeta, $performance);
     }
     $this->sendChangeEmails($show, $event);
 }
開發者ID:dstansby,項目名稱:camdram,代碼行數:15,代碼來源:ShowListener.php

示例2: preUpdate

 /**
  * @ORM\PreUpdate()
  */
 public function preUpdate(PreUpdateEventArgs $event)
 {
     $this->dealWithAtLeastOneTranslation($event->getObjectManager());
 }
開發者ID:claroline,項目名稱:distribution,代碼行數:7,代碼來源:Badge.php

示例3: preUpdate

 /**
  * Listen a preUpdate lifecycle event. Checking and encrypt entities fields
  * which have @Encrypted annotation. Using changesets to avoid preUpdate event
  * restrictions
  * 
  * @param LifecycleEventArgs $args 
  * 
  * @return void
  * @access public
  * @author etienne de Longeaux <etienne.delongeaux@gmail.com>
  */
 public function preUpdate(PreUpdateEventArgs $args)
 {
     if ($this->_update_enabled == true) {
         $entity = $args->getEntity();
         $em = $args->getEntityManager();
         $uow = $em->getUnitOfWork();
         $reflectionClass = new ReflectionClass($args->getEntity());
         $properties = $reflectionClass->getProperties();
         $className = get_class($entity);
         foreach ($properties as $refProperty) {
             foreach ($this->options as $key => $encrypter) {
                 if (isset($encrypter['encryptor_annotation_name']) && isset($encrypter['encryptor_class']) && isset($encrypter['encryptor_options'])) {
                     $this->encryptor = $this->getEncryptorService($key);
                     if ($this->annReader->getPropertyAnnotation($refProperty, $encrypter['encryptor_annotation_name'])) {
                         // we have annotation and if it decrypt operation, we must avoid duble decryption
                         $propName = $refProperty->getName();
                         // we encrypt the field
                         if ($refProperty->isPublic()) {
                             $entity->{$propName} = $this->encryptor->encrypt($refProperty->getValue());
                         } else {
                             $methodName = \Sfynx\ToolBundle\Util\PiStringManager::capitalize($propName);
                             if ($reflectionClass->hasMethod($getter = 'get' . $methodName) && $reflectionClass->hasMethod($setter = 'set' . $methodName)) {
                                 // we get the locale value
                                 $locale = false;
                                 $om = $args->getObjectManager();
                                 $object = $args->getObject();
                                 $meta = $om->getClassMetadata(get_class($object));
                                 $config = $this->getConfiguration($om, $meta->name);
                                 if (isset($config['fields'])) {
                                     $locale = $this->getTranslatableLocale($object, $meta);
                                 }
                                 // we set the encrypt value
                                 $currentPropValue = $entity->{$getter}();
                                 if (!empty($currentPropValue)) {
                                     $currentPropValue = $this->encryptor->encrypt($currentPropValue);
                                 }
                                 // we set locale value
                                 if ($locale) {
                                     //                                        if ($locale == $this->locale) {
                                     //                                            $entity->$setter($currentPropValue);
                                     //                                        }
                                     $entity->{$setter}($currentPropValue);
                                     $entity->translate($locale)->{$setter}($currentPropValue);
                                     //$uow->persist($entity);
                                     //$uow->computeChangeSets();
                                 }
                             } else {
                                 throw new \RuntimeException(sprintf("Property %s isn't public and doesn't has getter/setter"));
                             }
                         }
                     }
                 } else {
                     throw new \RuntimeException(sprintf("encrypter is not correctly configured"));
                 }
             }
         }
     }
 }
開發者ID:pigroupe,項目名稱:SfynxEncryptBundle,代碼行數:69,代碼來源:EncryptSubscriber.php


注:本文中的Doctrine\ORM\Event\PreUpdateEventArgs::getObjectManager方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。