2016-06-30 23:30:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2016-12-29 12:09:26 +01:00
|
|
|
* This file is part of the NelmioApiDocBundle package.
|
2016-06-30 23:30:37 +02:00
|
|
|
*
|
2016-12-29 12:09:26 +01:00
|
|
|
* (c) Nelmio
|
2016-06-30 23:30:37 +02:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2016-12-29 12:09:26 +01:00
|
|
|
namespace Nelmio\ApiDocBundle\RouteDescriber;
|
2016-06-30 23:30:37 +02:00
|
|
|
|
2020-05-28 13:19:11 +02:00
|
|
|
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
|
|
|
|
use OpenApi\Annotations as OA;
|
|
|
|
use OpenApi\Annotations\OpenApi;
|
2016-06-30 23:30:37 +02:00
|
|
|
use Symfony\Component\Routing\Route;
|
|
|
|
|
2016-07-15 00:40:30 +02:00
|
|
|
trait RouteDescriberTrait
|
2016-06-30 23:30:37 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*
|
2020-05-28 13:19:11 +02:00
|
|
|
* @return OA\Operation[]
|
2016-06-30 23:30:37 +02:00
|
|
|
*/
|
2020-05-28 13:19:11 +02:00
|
|
|
private function getOperations(OpenApi $api, Route $route): array
|
2016-06-30 23:30:37 +02:00
|
|
|
{
|
2018-01-26 07:37:03 +01:00
|
|
|
$operations = [];
|
2020-05-28 13:19:11 +02:00
|
|
|
$path = Util::getPath($api, $this->normalizePath($route->getPath()));
|
|
|
|
$methods = $route->getMethods() ?: Util::OPERATIONS;
|
2016-06-30 23:30:37 +02:00
|
|
|
foreach ($methods as $method) {
|
|
|
|
$method = strtolower($method);
|
2020-05-28 13:19:11 +02:00
|
|
|
if (!in_array($method, Util::OPERATIONS)) {
|
2016-06-30 23:30:37 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-05-28 13:19:11 +02:00
|
|
|
$operations[] = Util::getOperation($path, $method);
|
2016-06-30 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $operations;
|
|
|
|
}
|
2016-08-01 19:58:57 +02:00
|
|
|
|
2017-03-17 19:37:41 +01:00
|
|
|
private function normalizePath(string $path): string
|
2016-08-01 19:58:57 +02:00
|
|
|
{
|
2017-12-17 10:44:07 +01:00
|
|
|
if ('.{_format}' === substr($path, -10)) {
|
2016-08-01 19:58:57 +02:00
|
|
|
$path = substr($path, 0, -10);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $path;
|
|
|
|
}
|
2016-06-30 23:30:37 +02:00
|
|
|
}
|