Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 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);
}
}

View File

@@ -0,0 +1,94 @@
<?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;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectRepository;
use FOS\UserBundle\Model\GroupInterface;
use FOS\UserBundle\Model\GroupManager as BaseGroupManager;
class GroupManager extends BaseGroupManager
{
/**
* @var ObjectManager
*/
protected $objectManager;
/**
* @var string
*/
protected $class;
/**
* @var ObjectRepository
*/
protected $repository;
/**
* GroupManager constructor.
*
* @param ObjectManager $om
* @param string $class
*/
public function __construct(ObjectManager $om, $class)
{
$this->objectManager = $om;
$this->repository = $om->getRepository($class);
$metadata = $om->getClassMetadata($class);
$this->class = $metadata->getName();
}
/**
* {@inheritdoc}
*/
public function deleteGroup(GroupInterface $group)
{
$this->objectManager->remove($group);
$this->objectManager->flush();
}
/**
* {@inheritdoc}
*/
public function getClass()
{
return $this->class;
}
/**
* {@inheritdoc}
*/
public function findGroupBy(array $criteria)
{
return $this->repository->findOneBy($criteria);
}
/**
* {@inheritdoc}
*/
public function findGroups()
{
return $this->repository->findAll();
}
/**
* {@inheritdoc}
*/
public function updateGroup(GroupInterface $group, $andFlush = true)
{
$this->objectManager->persist($group);
if ($andFlush) {
$this->objectManager->flush();
}
}
}

View File

@@ -0,0 +1,109 @@
<?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;
use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ORM\EntityManager;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Util\CanonicalFieldsUpdater;
use FOS\UserBundle\Util\PasswordUpdaterInterface;
/**
* Doctrine listener updating the canonical username and password fields.
*
* @author Christophe Coevoet <stof@notk.org>
* @author David Buchmann <mail@davidbu.ch>
*/
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(
'prePersist',
'preUpdate',
);
}
/**
* Pre persist listener based on doctrine common.
*
* @param LifecycleEventArgs $args
*/
public function prePersist(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof UserInterface) {
$this->updateUserFields($object);
}
}
/**
* Pre update listener based on doctrine common.
*
* @param LifecycleEventArgs $args
*/
public function preUpdate(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof UserInterface) {
$this->updateUserFields($object);
$this->recomputeChangeSet($args->getObjectManager(), $object);
}
}
/**
* Updates the user properties.
*
* @param UserInterface $user
*/
private function updateUserFields(UserInterface $user)
{
$this->canonicalFieldsUpdater->updateCanonicalFields($user);
$this->passwordUpdater->hashPassword($user);
}
/**
* Recomputes change set for Doctrine implementations not doing it automatically after the event.
*
* @param ObjectManager $om
* @param UserInterface $user
*/
private function recomputeChangeSet(ObjectManager $om, UserInterface $user)
{
$meta = $om->getClassMetadata(get_class($user));
if ($om instanceof EntityManager) {
$om->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $user);
return;
}
if ($om instanceof DocumentManager) {
$om->getUnitOfWork()->recomputeSingleDocumentChangeSet($meta, $user);
}
}
}

View File

@@ -0,0 +1,116 @@
<?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;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectRepository;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManager as BaseUserManager;
use FOS\UserBundle\Util\CanonicalFieldsUpdater;
use FOS\UserBundle\Util\PasswordUpdaterInterface;
class UserManager extends BaseUserManager
{
/**
* @var ObjectManager
*/
protected $objectManager;
/**
* @var string
*/
private $class;
/**
* Constructor.
*
* @param PasswordUpdaterInterface $passwordUpdater
* @param CanonicalFieldsUpdater $canonicalFieldsUpdater
* @param ObjectManager $om
* @param string $class
*/
public function __construct(PasswordUpdaterInterface $passwordUpdater, CanonicalFieldsUpdater $canonicalFieldsUpdater, ObjectManager $om, $class)
{
parent::__construct($passwordUpdater, $canonicalFieldsUpdater);
$this->objectManager = $om;
$this->class = $class;
}
/**
* {@inheritdoc}
*/
public function deleteUser(UserInterface $user)
{
$this->objectManager->remove($user);
$this->objectManager->flush();
}
/**
* {@inheritdoc}
*/
public function getClass()
{
if (false !== strpos($this->class, ':')) {
$metadata = $this->objectManager->getClassMetadata($this->class);
$this->class = $metadata->getName();
}
return $this->class;
}
/**
* {@inheritdoc}
*/
public function findUserBy(array $criteria)
{
return $this->getRepository()->findOneBy($criteria);
}
/**
* {@inheritdoc}
*/
public function findUsers()
{
return $this->getRepository()->findAll();
}
/**
* {@inheritdoc}
*/
public function reloadUser(UserInterface $user)
{
$this->objectManager->refresh($user);
}
/**
* {@inheritdoc}
*/
public function updateUser(UserInterface $user, $andFlush = true)
{
$this->updateCanonicalFields($user);
$this->updatePassword($user);
$this->objectManager->persist($user);
if ($andFlush) {
$this->objectManager->flush();
}
}
/**
* @return ObjectRepository
*/
protected function getRepository()
{
return $this->objectManager->getRepository($this->getClass());
}
}