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,84 @@
<?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\Form\DataTransformer;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* Transforms between a UserInterface instance and a username string.
*
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
*/
class UserToUsernameTransformer implements DataTransformerInterface
{
/**
* @var UserManagerInterface
*/
protected $userManager;
/**
* UserToUsernameTransformer constructor.
*
* @param UserManagerInterface $userManager
*/
public function __construct(UserManagerInterface $userManager)
{
$this->userManager = $userManager;
}
/**
* Transforms a UserInterface instance into a username string.
*
* @param UserInterface|null $value UserInterface instance
*
* @return string|null Username
*
* @throws UnexpectedTypeException if the given value is not a UserInterface instance
*/
public function transform($value)
{
if (null === $value) {
return;
}
if (!$value instanceof UserInterface) {
throw new UnexpectedTypeException($value, 'FOS\UserBundle\Model\UserInterface');
}
return $value->getUsername();
}
/**
* Transforms a username string into a UserInterface instance.
*
* @param string $value Username
*
* @return UserInterface the corresponding UserInterface instance
*
* @throws UnexpectedTypeException if the given value is not a string
*/
public function reverseTransform($value)
{
if (null === $value || '' === $value) {
return;
}
if (!is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
}
return $this->userManager->findUserByUsername($value);
}
}