components-web-app /
api-components-bundle
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the Silverback API Components Bundle Project |
||
| 5 | * |
||
| 6 | * (c) Daniel West <[email protected]> |
||
| 7 | * |
||
| 8 | * For the full copyright and license information, please view the LICENSE |
||
| 9 | * file that was distributed with this source code. |
||
| 10 | */ |
||
| 11 | |||
| 12 | declare(strict_types=1); |
||
| 13 | |||
| 14 | namespace Silverback\ApiComponentsBundle\DataProvider\StateProvider; |
||
| 15 | |||
| 16 | use ApiPlatform\Metadata\CollectionOperationInterface; |
||
| 17 | use ApiPlatform\Metadata\Operation; |
||
| 18 | use ApiPlatform\State\ProviderInterface; |
||
| 19 | use Silverback\ApiComponentsBundle\Entity\User\AbstractUser; |
||
| 20 | use Silverback\ApiComponentsBundle\Repository\User\UserRepositoryInterface; |
||
| 21 | use Symfony\Component\HttpFoundation\RequestStack; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @author Daniel West <[email protected]> |
||
| 25 | */ |
||
| 26 | class UserStateProvider implements ProviderInterface |
||
| 27 | { |
||
| 28 | private UserRepositoryInterface $userRepository; |
||
| 29 | private RequestStack $requestStack; |
||
| 30 | |||
| 31 | public function __construct(UserRepositoryInterface $userRepository, RequestStack $requestStack) |
||
| 32 | { |
||
| 33 | $this->userRepository = $userRepository; |
||
| 34 | $this->requestStack = $requestStack; |
||
| 35 | } |
||
| 36 | |||
| 37 | public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null |
||
| 38 | { |
||
| 39 | $request = $this->requestStack->getCurrentRequest(); |
||
| 40 | if (!$request || !($id = $request->attributes->get('id'))) { |
||
| 41 | return null; |
||
| 42 | } |
||
| 43 | |||
| 44 | return $this->userRepository->loadUserByIdentifier($id); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function supports(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = []): bool |
||
|
0 ignored issues
–
show
|
|||
| 48 | { |
||
| 49 | /** @var Operation */ |
||
| 50 | $operation = $context['operation']; |
||
| 51 | |||
| 52 | return 'me' === $operationName && !$operation instanceof CollectionOperationInterface && |
||
| 53 | is_a($resourceClass, AbstractUser::class, true); |
||
| 54 | } |
||
| 55 | } |
||
| 56 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.