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 teohhanhui committed Mar 8, 2016
1 parent f43fed4 commit 0e09ec0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Bridge/NelmioApiDoc/Extractor/ApiDocExtractor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ApiPlatform\Core\Bridge\NelmioApiDoc\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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler;

use ApiPlatform\Core\Bridge\NelmioApiDoc\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

0 comments on commit 0e09ec0

Please sign in to comment.