2016-07-13 23:05:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the ApiDocBundle package.
|
|
|
|
*
|
|
|
|
* (c) EXSyst
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2016-07-15 00:40:30 +02:00
|
|
|
namespace EXSyst\Bundle\ApiDocBundle\RouteDescriber;
|
2016-07-13 23:05:14 +02:00
|
|
|
|
2016-08-01 19:58:57 +02:00
|
|
|
use EXSyst\Component\Swagger\Swagger;
|
2016-07-13 23:05:14 +02:00
|
|
|
use phpDocumentor\Reflection\DocBlockFactory;
|
|
|
|
use phpDocumentor\Reflection\DocBlockFactoryInterface;
|
|
|
|
use Symfony\Component\Routing\Route;
|
|
|
|
|
2016-07-15 00:40:30 +02:00
|
|
|
class PhpDocDescriber implements RouteDescriberInterface
|
2016-07-13 23:05:14 +02:00
|
|
|
{
|
2016-07-15 00:40:30 +02:00
|
|
|
use RouteDescriberTrait;
|
2016-07-13 23:05:14 +02:00
|
|
|
|
|
|
|
private $docBlockFactory;
|
|
|
|
|
|
|
|
public function __construct(DocBlockFactoryInterface $docBlockFactory = null)
|
|
|
|
{
|
|
|
|
if (null === $docBlockFactory) {
|
|
|
|
$docBlockFactory = DocBlockFactory::createInstance();
|
|
|
|
}
|
|
|
|
$this->docBlockFactory = $docBlockFactory;
|
|
|
|
}
|
|
|
|
|
2016-07-15 00:40:30 +02:00
|
|
|
public function describe(Swagger $api, Route $route, \ReflectionMethod $reflectionMethod)
|
2016-07-13 23:05:14 +02:00
|
|
|
{
|
|
|
|
$classDocBlock = null;
|
|
|
|
$docBlock = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$classDocBlock = $this->docBlockFactory->create($reflectionMethod->getDeclaringClass());
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$docBlock = $this->docBlockFactory->create($reflectionMethod);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->getOperations($api, $route) as $operation) {
|
|
|
|
if (null !== $docBlock) {
|
2016-08-04 22:27:10 +02:00
|
|
|
if (null === $operation->getSummary() && '' !== $docBlock->getSummary()) {
|
|
|
|
$operation->setSummary($docBlock->getSummary());
|
|
|
|
}
|
|
|
|
if (null === $operation->getDescription() && '' !== (string) $docBlock->getDescription()) {
|
|
|
|
$operation->setDescription((string) $docBlock->getDescription());
|
|
|
|
}
|
2016-08-01 19:58:57 +02:00
|
|
|
if ($docBlock->hasTag('deprecated')) {
|
|
|
|
$operation->setDeprecated(true);
|
|
|
|
}
|
2016-07-13 23:05:14 +02:00
|
|
|
}
|
|
|
|
if (null !== $classDocBlock) {
|
2016-08-01 19:58:57 +02:00
|
|
|
if ($classDocBlock->hasTag('deprecated')) {
|
|
|
|
$operation->setDeprecated(true);
|
|
|
|
}
|
2016-07-13 23:05:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|