本文整理汇总了PHP中Doctrine\ORM\Event\PreUpdateEventArgs::setNewValue方法的典型用法代码示例。如果您正苦于以下问题:PHP PreUpdateEventArgs::setNewValue方法的具体用法?PHP PreUpdateEventArgs::setNewValue怎么用?PHP PreUpdateEventArgs::setNewValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Event\PreUpdateEventArgs
的用法示例。
在下文中一共展示了PreUpdateEventArgs::setNewValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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
*/
public function preUpdate(PreUpdateEventArgs $args)
{
$reflectionClass = new ReflectionClass($args->getEntity());
$properties = $reflectionClass->getProperties();
foreach ($properties as $refProperty) {
$propName = $refProperty->getName();
if ($this->annReader->getPropertyAnnotation($refProperty, self::ENCRYPTED_ANN_NAME) && $args->hasChangedField($propName)) {
$args->setNewValue($propName, $this->encryptor->encrypt($args->getNewValue($propName)));
}
}
}
示例2: preUpdate
public function preUpdate(PreUpdateEventArgs $eventArgs)
{
$user = $eventArgs->getEntity();
if ($user instanceof User) {
if ($eventArgs->hasChangedField('password')) {
$password = $this->encodePassword($user);
$eventArgs->setNewValue('password', $password);
$user->setPassword($password);
}
}
}
示例3: preUpdate
/**
* @param PreUpdateEventArgs $args
*/
public function preUpdate(PreUpdateEventArgs $args)
{
$entity = $args->getEntity();
switch (true) {
case $entity instanceof User:
if ($entity->getPlainPassword()) {
$args->setNewValue('password', $this->encodePlainPassword($entity));
}
break;
}
}
示例4: preUpdate
/**
* PreUpdate event listener
*
* Only computes password change if password is one of file to be changed
*
* @param PreUpdateEventArgs $eventArgs Event args
*/
public function preUpdate(PreUpdateEventArgs $eventArgs)
{
$entity = $eventArgs->getEntity();
if ($this->checkEntityType($entity)) {
if ($eventArgs->hasChangedField('password')) {
$password = $entity->getPassword();
if (!empty($password)) {
$encodedPassword = $this->encryptPassword($password);
$eventArgs->setNewValue('password', $encodedPassword);
}
}
}
}
示例5: preUpdate
public function preUpdate(PreUpdateEventArgs $eventArgs)
{
$eventArgs->setNewValue('name', 'Bob');
}