NelmioApiDocBundle/RouteDescriber/RouteDescriberTrait.php

53 lines
1.2 KiB
PHP
Raw Normal View History

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
2016-08-01 19:58:57 +02:00
use EXSyst\Component\Swagger\Operation;
use EXSyst\Component\Swagger\Swagger;
2016-06-30 23:30:37 +02:00
use Symfony\Component\Routing\Route;
/**
* @internal
*/
2016-07-15 00:40:30 +02:00
trait RouteDescriberTrait
2016-06-30 23:30:37 +02:00
{
/**
* @internal
*
* @return Operation[]
*/
2017-03-17 19:37:41 +01:00
private function getOperations(Swagger $api, Route $route): array
2016-06-30 23:30:37 +02:00
{
2016-08-01 19:58:57 +02:00
$path = $api->getPaths()->get($this->normalizePath($route->getPath()));
2016-06-30 23:30:37 +02:00
$methods = $route->getMethods() ?: Swagger::$METHODS;
foreach ($methods as $method) {
$method = strtolower($method);
if (!in_array($method, Swagger::$METHODS)) {
continue;
}
$operations[] = $path->getOperation($method);
}
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
{
if (substr($path, -10) === '.{_format}') {
$path = substr($path, 0, -10);
}
return $path;
}
2016-06-30 23:30:37 +02:00
}