An error occurred while loading the file. Please try again.
-
Guillaume Perréal authored
L'export en JSON-schema est confié à des normalizers symfony. La génération des URI est confiée à des classes spécifiques.
113ed110
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 2019 IRSTEA
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License and the GNU
* Lesser General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
namespace Irstea\ApiMetadata\Bridge\Symfony\Bundle\Controller;
use Irstea\ApiMetadata\Factory\Operation\OperationFactoryInterface;
use Irstea\ApiMetadata\Factory\Type\TypeFactoryInterface;
use Irstea\ApiMetadata\Service\ResourceMapInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\SerializerInterface;
/**
* Class OperationController.
*/
class OperationController extends AbstractController
{
/**
* @var OperationFactoryInterface
*/
private $operationFactory;
/**
* OperationListAction constructor.
*
* @param ResourceMapInterface $resourceMap
* @param TypeFactoryInterface $typeFactory
* @param SerializerInterface $serializer
* @param OperationFactoryInterface $operationFactory
*/
public function __construct(
ResourceMapInterface $resourceMap,
TypeFactoryInterface $typeFactory,
SerializerInterface $serializer,
OperationFactoryInterface $operationFactory
) {
parent::__construct($resourceMap, $typeFactory, $serializer);
$this->operationFactory = $operationFactory;
}
/**
* @param string $shortName
* @param string $type
* @param string $name
*
* @return Response
*/
public function item(string $shortName, string $type, string $name): Response
{
[$className, $ctx] = $this->setupContext($shortName);
$operation = $this->operationFactory->create($className, $type, $name, $ctx);
return $this->createResponse($operation, $ctx);
}
7172737475767778798081828384858687888990
/**
* @param string $shortName
*
* @return Response
*/
public function collection(string $shortName): Response
{
[$className, $ctx] = $this->setupContext($shortName);
$operations = [];
foreach ($this->operationFactory->enumerate($className, $ctx) as $key => $operation) {
$operations[$key] = $operation;
}
return $this->createResponse($operations, $ctx);
}
}