Merge pull request #1557 from maxhelias/deprecation

Remove deprecated notice about controller_name_converter
This commit is contained in:
Guilhem Niot 2019-11-21 18:16:01 +01:00 committed by GitHub
commit e9cdde1355
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 5 deletions

View File

@ -180,6 +180,18 @@ final class NelmioApiDocExtension extends Extension implements PrependExtensionI
// Import the base configuration
$container->getDefinition('nelmio_api_doc.describers.config')->replaceArgument(0, $config['documentation']);
// Compatibility Symfony
$controllerNameConverter = null;
if ($container->hasDefinition('.legacy_controller_name_converter')) { // 4.4
$controllerNameConverter = $container->getDefinition('.legacy_controller_name_converter');
} elseif ($container->hasDefinition('controller_name_converter')) { // < 4.4
$controllerNameConverter = $container->getDefinition('controller_name_converter');
}
if (null !== $controllerNameConverter) {
$container->getDefinition('nelmio_api_doc.controller_reflector')->setArgument(1, $controllerNameConverter);
}
}
private function findNameAliases(array $names, string $area): array

View File

@ -19,7 +19,6 @@
<service id="nelmio_api_doc.controller_reflector" class="Nelmio\ApiDocBundle\Util\ControllerReflector" public="false">
<argument type="service" id="service_container" />
<argument type="service" id="controller_name_converter" />
</service>
<!-- Describers -->

View File

@ -26,10 +26,13 @@ class ControllerReflector
private $controllers = [];
public function __construct(ContainerInterface $container, ControllerNameParser $controllerNameParser)
public function __construct(ContainerInterface $container)
{
$this->container = $container;
$this->controllerNameParser = $controllerNameParser;
if (1 < \func_num_args() && func_get_arg(1) instanceof ControllerNameParser) {
$this->controllerNameParser = func_get_arg(1);
}
}
/**
@ -79,8 +82,16 @@ class ControllerReflector
return $this->controllers[$controller];
}
if (false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
$controller = $this->controllerNameParser->parse($controller);
if ($this->controllerNameParser && false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
$deprecatedNotation = $controller;
try {
$controller = $this->controllerNameParser->parse($controller);
@trigger_error(sprintf('Referencing controllers with %s is deprecated since Symfony 4.1, use "%s" instead.', $deprecatedNotation, $controller), E_USER_DEPRECATED);
} catch (\InvalidArgumentException $e) {
// unable to optimize unknown notation
}
}
if (preg_match('#(.+)::([\w]+)#', $controller, $matches)) {