I have a Symfony project and I’m trying to get a list of available commands in my controller, so I tried to execute the list
-command (together with --format=xml
) to achieve that.
I used the code listed here to run a command from a controller but end up with the error “Not passing a connection provider as the first constructor argument is deprecated”.
This is the code:
$application = new Application($kernel); $application->setAutoExit(false); $input = new ArrayInput(['command' => 'list', '--format' => 'xml']); $output = new BufferedOutput(); $application->run($input, $output); $content = $output->fetch();
The mentioned error occurs in vendordoctrinedballibDoctrineDBALToolsConsoleCommandRunSqlCommand.php
. Here’s the complete trace:
[ "exception" => ErrorException { #message: "User Deprecated: Not passing a connection provider as the first constructor argument is deprecated" #code: 0 #file: "C:xampphtdocs_shopfloorshopfloorlistvendordoctrinedballibDoctrineDBALToolsConsoleCommandRunSqlCommand.php" #line: 44 #severity: E_USER_DEPRECATED trace: { C:xampphtdocs_shopfloorshopfloorlistvendordoctrinedballibDoctrineDBALToolsConsoleCommandRunSqlCommand.php:44 { …} C:xampphtdocs_shopfloorshopfloorlistvarcachedevContainer54qfFMqgetDoctrine_QuerySqlCommandService.php:24 { Container54qfFMqgetDoctrine_QuerySqlCommandService::do($container, $lazyLoad = true) › › $container->privates['doctrine.query_sql_command'] = $instance = new DoctrineBundleDoctrineBundleCommandProxyRunSqlDoctrineCommand(); › } C:xampphtdocs_shopfloorshopfloorlistvarcachedevContainer54qfFMqApp_KernelDevDebugContainer.php:609 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonydependency-injectionContainer.php:441 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonydependency-injectionArgumentServiceLocator.php:40 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleCommandLoaderContainerCommandLoader.php:45 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleApplication.php:527 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleApplication.php:723 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyframework-bundleConsoleApplication.php:142 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleDescriptorApplicationDescription.php:91 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleDescriptorApplicationDescription.php:68 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleDescriptorXmlDescriptor.php:97 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleDescriptorXmlDescriptor.php:155 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleDescriptorDescriptor.php:55 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleHelperDescriptorHelper.php:65 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleCommandListCommand.php:75 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleCommandCommand.php:258 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleApplication.php:938 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyframework-bundleConsoleApplication.php:99 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleApplication.php:266 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyframework-bundleConsoleApplication.php:82 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyconsoleApplication.php:142 { …} C:xampphtdocs_shopfloorshopfloorlistsrcControllerAdminController.php:134 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyhttp-kernelHttpKernel.php:157 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyhttp-kernelHttpKernel.php:79 { …} C:xampphtdocs_shopfloorshopfloorlistvendorsymfonyhttp-kernelKernel.php:196 { …} C:xampphtdocs_shopfloorshopfloorlistpublicindex.php:29 { …} } } ]
Strange enough running “bin/console list” (or just “bin/console”) with or without the format set to XML will not show the error, also running any other command from my controller with the above code will work just fine.
I’m using Symfony 5.1.7 with Doctrine-bundle 2.1, I already tried downgrading doctrine/persistence to 1.x as 2.x showed some issues with some libraries, all to no avail.
Advertisement
Answer
I fixed this issue by re-declaring the command in my project with the proper argument:
doctrine.query_sql_command: class: DoctrineDBALToolsConsoleCommandRunSqlCommand arguments: - '@DoctrineBundleDoctrineBundleDbalManagerRegistryAwareConnectionProvider' tags: - { name: console.command, command: doctrine:query:sql }