Skip to content

Commit

Permalink
Add ApiDocExtractor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime.steinhausser authored and ogizanagi committed Oct 29, 2015
1 parent a8b2c05 commit 1ecaed0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DependencyInjection/Compiler/NelmioSupportPass.php
Expand Up @@ -11,6 +11,7 @@

namespace Dunglas\ApiBundle\DependencyInjection\Compiler;

use Dunglas\ApiBundle\Nelmio\Extractor\ApiDocExtractor;
use Nelmio\ApiDocBundle\DependencyInjection\RegisterExtractorParsersPass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -37,6 +38,7 @@ public function process(ContainerBuilder $container)
$container->removeDefinition('nelmio_api_doc.parser.dunglas_api_parser');

$apiDocExtractorDefinition = $container->getDefinition('nelmio_api_doc.extractor.api_doc_extractor');
$apiDocExtractorDefinition->setClass(ApiDocExtractor::class);
/** @var Reference[] $annotationsProviderReferences */
$annotationsProviderReferences = $apiDocExtractorDefinition->getArgument(6);

Expand Down
37 changes: 37 additions & 0 deletions Nelmio/Extractor/ApiDocExtractor.php
@@ -0,0 +1,37 @@
<?php

namespace Dunglas\ApiBundle\Nelmio\Extractor;

use Doctrine\Common\Util\ClassUtils;
use Nelmio\ApiDocBundle\Extractor\ApiDocExtractor as BaseApiDocExtractor;
use Symfony\Component\HttpFoundation\Request;

class ApiDocExtractor extends BaseApiDocExtractor
{
public function getReflectionMethod($controller)
{
$reflectionMethod = parent::getReflectionMethod($controller);
if (null !== $reflectionMethod) {
return $reflectionMethod;
}

if ($this->container->has($controller)) {
$this->container->enterScope('request');
$this->container->set('request', new Request(), 'request');
$class = ClassUtils::getRealClass(get_class($this->container->get($controller)));
$this->container->leaveScope('request');
if (!isset($method) && method_exists($class, '__invoke')) {
$method = '__invoke';
}
}

if (isset($class) && isset($method)) {
try {
return new \ReflectionMethod($class, $method);
} catch (\ReflectionException $e) {
}
}

return;
}
}

0 comments on commit 1ecaed0

Please sign in to comment.