本文整理汇总了PHP中Doctrine\ORM\Event\PreUpdateEventArgs::getObject方法的典型用法代码示例。如果您正苦于以下问题:PHP PreUpdateEventArgs::getObject方法的具体用法?PHP PreUpdateEventArgs::getObject怎么用?PHP PreUpdateEventArgs::getObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Event\PreUpdateEventArgs
的用法示例。
在下文中一共展示了PreUpdateEventArgs::getObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preUpdate
public function preUpdate(PreUpdateEventArgs $eventArgs)
{
$this->object = $eventArgs->getObject();
$class = str_replace("Proxies\\__CG__\\", "", get_class($this->object));
if (!array_key_exists($class, $this->actions)) {
return;
}
$this->logger->debug("[NormalizeListener] Entering NormalizeListener for « preUpdate » event");
$this->normalizeFields();
}
示例2: 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"));
}
}
}
}
}
示例3: preUpdate
/**
* Gets called before updates
*
* @param PreUpdateEventArgs $eventArgs
*/
public function preUpdate(PreUpdateEventArgs $eventArgs)
{
$entity = $eventArgs->getObject();
// If it's a Taggable entity, mark the entity to be saved
if ($this->isEntitySupported($this->getReflClass($entity))) {
$this->addEntityToSave($entity);
}
}