NelmioApiDocBundle/Extractor/Routing/PhpDocExtractor.php
Ener-Getick 6770e9e809
Fix CS
2016-07-14 23:52:01 +02:00

59 lines
1.8 KiB
PHP

<?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.
*/
namespace EXSyst\Bundle\ApiDocBundle\Extractor\Routing;
use phpDocumentor\Reflection\DocBlockFactory;
use phpDocumentor\Reflection\DocBlockFactoryInterface;
use gossi\swagger\Swagger;
use Symfony\Component\Routing\Route;
class PhpDocExtractor implements RouteExtractorInterface
{
use RouteExtractorTrait;
private $docBlockFactory;
public function __construct(DocBlockFactoryInterface $docBlockFactory = null)
{
if (null === $docBlockFactory) {
$docBlockFactory = DocBlockFactory::createInstance();
}
$this->docBlockFactory = $docBlockFactory;
}
public function extractIn(Swagger $api, Route $route, \ReflectionMethod $reflectionMethod)
{
$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) {
$operation->setSummary($docBlock->getSummary());
$operation->setDescription((string) $docBlock->getDescription());
$operation->setDeprecated($operation->getDeprecated() || $docBlock->hasTag('deprecated'));
}
if (null !== $classDocBlock) {
$operation->setDeprecated($operation->getDeprecated() || $classDocBlock->hasTag('deprecated'));
}
}
}
}