for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Silverback API Components Bundle Project
*
* (c) Daniel West <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Silverback\ApiComponentsBundle\DataProvider\Item;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use Silverback\ApiComponentsBundle\Entity\User\AbstractUser;
use Silverback\ApiComponentsBundle\Repository\User\UserRepositoryInterface;
/**
* @author Daniel West <[email protected]>
class UserDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface
{
private UserRepositoryInterface $userRepository;
public function __construct(UserRepositoryInterface $userRepository)
$this->userRepository = $userRepository;
}
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
return 'me' === $operationName &&
is_a($resourceClass, AbstractUser::class, true);
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = [])
return $this->userRepository->loadUserByUsername($id);