Различия
Показаны различия между двумя версиями страницы.
Следующая версия | Предыдущая версия | ||
php:symfony:user [2024/04/15 21:01] – создано mirocow | php:symfony:user [2024/04/16 00:26] (текущий) – mirocow | ||
---|---|---|---|
Строка 2: | Строка 2: | ||
====== User / UserRepository ====== | ====== User / UserRepository ====== | ||
+ | |||
+ | ===== User + Repository ===== | ||
<code php> | <code php> | ||
Строка 27: | Строка 29: | ||
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface | class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface | ||
{ | { | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Preprocessor в методе PATH / POST ===== | ||
+ | |||
+ | src/ | ||
+ | <code php> | ||
+ | <?php | ||
+ | |||
+ | namespace App\Entity; | ||
+ | |||
+ | use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; | ||
+ | use ApiPlatform\Metadata\ApiFilter; | ||
+ | use ApiPlatform\Metadata\ApiResource; | ||
+ | use ApiPlatform\Metadata\Get; | ||
+ | use ApiPlatform\Metadata\GetCollection; | ||
+ | use ApiPlatform\Metadata\Patch; | ||
+ | use ApiPlatform\Metadata\Post; | ||
+ | use App\Repository\UserRepository; | ||
+ | use App\State\UserHashPasswordProcessor; | ||
+ | use App\State\UserStateProcessor; | ||
+ | use Doctrine\Common\Collections\ArrayCollection; | ||
+ | use Doctrine\Common\Collections\Collection; | ||
+ | use Doctrine\DBAL\Types\Types; | ||
+ | use Doctrine\ORM\Mapping as ORM; | ||
+ | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; | ||
+ | use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; | ||
+ | use Symfony\Component\Security\Core\User\UserInterface; | ||
+ | use Symfony\Component\Serializer\Annotation\Groups; | ||
+ | use Symfony\Component\Serializer\Annotation\SerializedName; | ||
+ | |||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | operations: [ | ||
+ | new Get(), | ||
+ | new GetCollection(), | ||
+ | new Post( | ||
+ | denormalizationContext: | ||
+ | processor: UserStateProcessor:: | ||
+ | ), | ||
+ | new Patch( | ||
+ | denormalizationContext: | ||
+ | processor: UserHashPasswordProcessor:: | ||
+ | ) | ||
+ | ], | ||
+ | normalizationContext: | ||
+ | |||
+ | )] | ||
+ | class User implements UserInterface, | ||
+ | { | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | src/ | ||
+ | <code php> | ||
+ | <?php | ||
+ | |||
+ | namespace App\State; | ||
+ | |||
+ | use ApiPlatform\Doctrine\Common\State\PersistProcessor; | ||
+ | use ApiPlatform\Metadata\Operation; | ||
+ | use ApiPlatform\State\ProcessorInterface; | ||
+ | use App\Entity\User; | ||
+ | use Symfony\Bundle\SecurityBundle\Security; | ||
+ | use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
+ | use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; | ||
+ | |||
+ | class UserHashPasswordProcessor implements ProcessorInterface | ||
+ | { | ||
+ | public function __construct( | ||
+ | # | ||
+ | private readonly UserPasswordHasherInterface $userPasswordHasher, | ||
+ | ) | ||
+ | { | ||
+ | } | ||
+ | |||
+ | public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void | ||
+ | { | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | | ||
+ | } | ||
} | } | ||
</ | </ |