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\Core\Route; |
||||
| 20 | use Silverback\ApiComponentsBundle\Repository\Core\RouteRepository; |
||||
| 21 | |||||
| 22 | /** |
||||
| 23 | * @author Daniel West <[email protected]> |
||||
| 24 | */ |
||||
| 25 | class RouteStateProvider implements ProviderInterface |
||||
| 26 | { |
||||
| 27 | private const ALREADY_CALLED = 'ROUTE_DATA_PROVIDER_ALREADY_CALLED'; |
||||
| 28 | |||||
| 29 | private RouteRepository $routeRepository; |
||||
| 30 | private ProviderInterface $defaultProvider; |
||||
| 31 | |||||
| 32 | public function __construct(RouteRepository $routeRepository, ProviderInterface $defaultProvider) |
||||
| 33 | { |
||||
| 34 | $this->routeRepository = $routeRepository; |
||||
| 35 | $this->defaultProvider = $defaultProvider; |
||||
| 36 | } |
||||
| 37 | |||||
| 38 | public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null |
||||
| 39 | { |
||||
| 40 | $id = $uriVariables['id']; |
||||
| 41 | |||||
| 42 | $context[self::ALREADY_CALLED] = true; |
||||
| 43 | if (!\is_string($id)) { |
||||
| 44 | return $this->defaultProvider->provide($operation, $uriVariables, $context); |
||||
| 45 | } |
||||
| 46 | |||||
| 47 | return $this->routeRepository->findOneByIdOrPath($id); |
||||
| 48 | } |
||||
| 49 | |||||
| 50 | public function supports(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = []): bool |
||||
|
0 ignored issues
–
show
The parameter
$operationName is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 51 | { |
||||
| 52 | /** @var Operation */ |
||||
| 53 | $operation = $context['operation']; |
||||
| 54 | |||||
| 55 | return Route::class === $resourceClass && !$operation instanceof CollectionOperationInterface && !isset($context[self::ALREADY_CALLED]); |
||||
| 56 | } |
||||
| 57 | } |
||||
| 58 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.