当前位置: 首页>>代码示例>>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;未经允许,请勿转载。