本文整理匯總了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');
}