Fix deprecations (#8)

* fix symfony deprecations
This commit is contained in:
Alexey 2022-10-07 15:32:38 +03:00 committed by GitHub
parent 8d699084aa
commit d8b5ab9f71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 45 deletions

View File

@ -12,14 +12,16 @@
namespace Nelmio\ApiDocBundle\Command; namespace Nelmio\ApiDocBundle\Command;
use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
class DumpCommand extends ContainerAwareCommand class DumpCommand extends Command implements ContainerAwareInterface
{ {
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
/** /**
* @var array * @var array
*/ */
@ -47,20 +49,20 @@ class DumpCommand extends ContainerAwareCommand
$format = $input->getOption('format'); $format = $input->getOption('format');
$view = $input->getOption('view'); $view = $input->getOption('view');
$routeCollection = $this->getContainer()->get('router')->getRouteCollection(); $routeCollection = $this->container->get('router')->getRouteCollection();
if ($format == 'json') { if ($format == 'json') {
$formatter = $this->getContainer()->get('nelmio_api_doc.formatter.simple_formatter'); $formatter = $this->container->get('nelmio_api_doc.formatter.simple_formatter');
} else { } else {
if (!in_array($format, $this->availableFormats)) { if (!in_array($format, $this->availableFormats)) {
throw new \RuntimeException(sprintf('Format "%s" not supported.', $format)); throw new \RuntimeException(sprintf('Format "%s" not supported.', $format));
} }
$formatter = $this->getContainer()->get(sprintf('nelmio_api_doc.formatter.%s_formatter', $format)); $formatter = $this->container->get(sprintf('nelmio_api_doc.formatter.%s_formatter', $format));
} }
if ($input->hasOption('locale')) { if ($input->hasOption('locale')) {
$this->getContainer()->get('translator')->setLocale($input->getOption('locale')); $this->container->get('translator')->setLocale($input->getOption('locale'));
} }
if ($input->hasOption('api-version')) { if ($input->hasOption('api-version')) {
@ -71,12 +73,12 @@ class DumpCommand extends ContainerAwareCommand
$formatter->setEnableSandbox(false); $formatter->setEnableSandbox(false);
} }
if ('html' === $format && method_exists($this->getContainer(), 'enterScope')) { if ('html' === $format && method_exists($this->container, 'enterScope')) {
$this->getContainer()->enterScope('request'); $this->container->enterScope('request');
$this->getContainer()->set('request', new Request(), 'request'); $this->container->set('request', new Request(), 'request');
} }
$extractor = $this->getContainer()->get('nelmio_api_doc.extractor.api_doc_extractor'); $extractor = $this->container->get('nelmio_api_doc.extractor.api_doc_extractor');
$extractedDoc = $input->hasOption('api-version') ? $extractedDoc = $input->hasOption('api-version') ?
$extractor->allForVersion($input->getOption('api-version'), $view) : $extractor->allForVersion($input->getOption('api-version'), $view) :
$extractor->all($view); $extractor->all($view);
@ -88,5 +90,7 @@ class DumpCommand extends ContainerAwareCommand
} else { } else {
$output->writeln($formattedDoc, OutputInterface::OUTPUT_RAW); $output->writeln($formattedDoc, OutputInterface::OUTPUT_RAW);
} }
return 0;
} }
} }

View File

@ -34,7 +34,7 @@ class AnnotationsProviderCompilerPass implements CompilerPassInterface
$container $container
->getDefinition('nelmio_api_doc.extractor.api_doc_extractor') ->getDefinition('nelmio_api_doc.extractor.api_doc_extractor')
->replaceArgument(6, $annotationsProviders) ->replaceArgument(5, $annotationsProviders)
; ;
} }
} }

View File

@ -29,6 +29,6 @@ class ExtractorHandlerCompilerPass implements CompilerPassInterface
$container $container
->getDefinition('nelmio_api_doc.extractor.api_doc_extractor') ->getDefinition('nelmio_api_doc.extractor.api_doc_extractor')
->replaceArgument(5, $handlers); ->replaceArgument(4, $handlers);
} }
} }

View File

@ -48,11 +48,6 @@ class ApiDocExtractor
*/ */
private $commentExtractor; private $commentExtractor;
/**
* @var ControllerNameParser
*/
protected $controllerNameParser;
/** /**
* @var ParserInterface[] * @var ParserInterface[]
*/ */
@ -68,13 +63,12 @@ class ApiDocExtractor
*/ */
protected $annotationsProviders; protected $annotationsProviders;
public function __construct(ContainerInterface $container, RouterInterface $router, Reader $reader, DocCommentExtractor $commentExtractor, ControllerNameParser $controllerNameParser, array $handlers, array $annotationsProviders) public function __construct(ContainerInterface $container, RouterInterface $router, Reader $reader, DocCommentExtractor $commentExtractor, array $handlers, array $annotationsProviders)
{ {
$this->container = $container; $this->container = $container;
$this->router = $router; $this->router = $router;
$this->reader = $reader; $this->reader = $reader;
$this->commentExtractor = $commentExtractor; $this->commentExtractor = $commentExtractor;
$this->controllerNameParser = $controllerNameParser;
$this->handlers = $handlers; $this->handlers = $handlers;
$this->annotationsProviders = $annotationsProviders; $this->annotationsProviders = $annotationsProviders;
} }
@ -227,9 +221,9 @@ class ApiDocExtractor
*/ */
public function getReflectionMethod($controller) public function getReflectionMethod($controller)
{ {
if (false === strpos($controller, '::') && 2 === substr_count($controller, ':')) { // if (false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
$controller = $this->controllerNameParser->parse($controller); // $controller = $this->controllerNameParser->parse($controller);
} // }
if (preg_match('#(.+)::([\w]+)#', $controller, $matches)) { if (preg_match('#(.+)::([\w]+)#', $controller, $matches)) {
$class = $matches[1]; $class = $matches[1];

View File

@ -60,8 +60,8 @@ class DescriptionFormTypeExtension extends AbstractTypeExtension
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getExtendedType() public static function getExtendedTypes(): iterable
{ {
return LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\FormType'); return [LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\FormType')];
} }
} }

View File

@ -1,4 +1,4 @@
nelmio_api_doc_index: nelmio_api_doc_index:
path: /{view} path: /{view}
defaults: { _controller: NelmioApiDocBundle:ApiDoc:index, view: 'default' } defaults: { _controller: Nelmio\ApiDocBundle\Controller\ApiDocController::indexAction, view: 'default' }
methods: [GET] methods: [GET]

View File

@ -31,7 +31,6 @@
<argument type="service" id="router" /> <argument type="service" id="router" />
<argument type="service" id="annotation_reader" /> <argument type="service" id="annotation_reader" />
<argument type="service" id="nelmio_api_doc.doc_comment_extractor" /> <argument type="service" id="nelmio_api_doc.doc_comment_extractor" />
<argument type="service" id="nelmio_api_doc.controller_name_parser" />
<argument type="collection" /> <argument type="collection" />
<argument type="collection" /> <argument type="collection" />
</service> </service>

View File

@ -16,9 +16,9 @@
], ],
"require": { "require": {
"php": ">=7.1", "php": ">=7.1",
"symfony/twig-bundle": "~2.3|~3.0|~4.0", "symfony/twig-bundle": "~2.3|~3.0|~4.0|~5.0",
"symfony/framework-bundle": "~2.3|~3.0|~4.0", "symfony/framework-bundle": "~2.3|~3.0|~4.0|~5.0",
"symfony/console": "~2.3|~3.0|~4.0", "symfony/console": "~2.3|~3.0|~4.0|~5.0",
"michelf/php-markdown": "~1.4" "michelf/php-markdown": "~1.4"
}, },
"conflict": { "conflict": {
@ -27,22 +27,6 @@
"twig/twig": "<1.12", "twig/twig": "<1.12",
"symfony/symfony": "~2.7.8" "symfony/symfony": "~2.7.8"
}, },
"require-dev": {
"symfony/css-selector": "~2.3|~3.0|~4.0",
"symfony/browser-kit": "~2.3|~3.0|~4.0",
"symfony/validator": "~2.3|~3.0|~4.0",
"symfony/yaml": "~2.3|~3.0|~4.0",
"symfony/form": "~2.3|~3.0|~4.0",
"symfony/finder": "~2.3|~3.0|~4.0",
"symfony/serializer": "~2.7|~3.0|~4.0",
"doctrine/orm": "~2.3",
"doctrine/doctrine-bundle": "~1.5",
"friendsofsymfony/rest-bundle": "~1.0|~2.0",
"jms/serializer-bundle": ">=0.11",
"dunglas/api-bundle": "~1.0",
"sensio/framework-extra-bundle": "~3.0",
"symfony/phpunit-bridge": "~2.7|~3.0|~4.0"
},
"suggest": { "suggest": {
"symfony/form": "For using form definitions as input.", "symfony/form": "For using form definitions as input.",
"symfony/validator": "For making use of validator information in the doc.", "symfony/validator": "For making use of validator information in the doc.",