-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
7 additions
and
12 deletions.
There are no files selected for viewing
19 changes: 7 additions & 12 deletions
19
src/State/UserStateProcessor.php → src/State/User/UserStateProcessor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,27 @@ | ||
<?php | ||
|
||
namespace App\State; | ||
namespace App\State\User; | ||
|
||
use ApiPlatform\Doctrine\Common\State\PersistProcessor; | ||
use ApiPlatform\Metadata as API; | ||
use ApiPlatform\State\ProcessorInterface; | ||
use App\Entity\User; | ||
use Symfony\Component\DependencyInjection\Attribute\AsDecorator; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; | ||
|
||
#[AsDecorator('api_platform.doctrine.orm.state.persist_processor')] | ||
class UserStateProcessor implements ProcessorInterface | ||
{ | ||
public function __construct( | ||
#[Autowire(service: PersistProcessor::class)] | ||
private ProcessorInterface $innerProcessor, | ||
private UserPasswordHasherInterface $userPasswordHasher, | ||
) {} | ||
|
||
/** | ||
* @return T2 | ||
* @param UserApiResource $data | ||
* @return UserApiResource | ||
*/ | ||
public function process(mixed $data, API\Operation $operation, array $uriVariables = [], array $context = []) | ||
{ | ||
if ($data instanceof User && $data->getPlainPassword()) { | ||
$data->setPassword( | ||
$this->userPasswordHasher->hashPassword($data, $data->getPlainPassword()) | ||
); | ||
} | ||
|
||
return $this->innerProcessor->process($data, $operation, $uriVariables, $context); | ||
return $data; | ||
} | ||
} |