This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Doctrine\CouchDB;
use Doctrine\Common\EventSubscriber;
use Doctrine\ODM\CouchDB\Event;
use Doctrine\ODM\CouchDB\Event\LifecycleEventArgs;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Util\CanonicalFieldsUpdater;
use FOS\UserBundle\Util\PasswordUpdaterInterface;
class UserListener implements EventSubscriber
{
private $passwordUpdater;
private $canonicalFieldsUpdater;
public function __construct(PasswordUpdaterInterface $passwordUpdater, CanonicalFieldsUpdater $canonicalFieldsUpdater)
{
$this->passwordUpdater = $passwordUpdater;
$this->canonicalFieldsUpdater = $canonicalFieldsUpdater;
}
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
{
return array(
Event::prePersist,
Event::preUpdate,
);
}
/**
* @param LifecycleEventArgs $args
*/
public function prePersist(LifecycleEventArgs $args)
{
$object = $args->getDocument();
if ($object instanceof UserInterface) {
$this->updateUserFields($object);
}
}
/**
* @param LifecycleEventArgs $args
*/
public function preUpdate(LifecycleEventArgs $args)
{
$object = $args->getDocument();
if ($object instanceof UserInterface) {
$this->updateUserFields($object);
}
}
/**
* Updates the user properties.
*
* @param UserInterface $user
*/
private function updateUserFields(UserInterface $user)
{
$this->canonicalFieldsUpdater->updateCanonicalFields($user);
$this->passwordUpdater->hashPassword($user);
}
}