-
-
Notifications
You must be signed in to change notification settings - Fork 110
Description
Version: 3.1.1
Bug Description
I would like to use Nette Database 3.1.1 in Symfony 5.2.3. My PHP version is 8.0.
When I try to create a database connection in a command I get the following error.
"The autoloader expected class "Nette\Database\IConventions" to be defined in file "/var/www/html/vendor/composer/../nette/database/src/compatibility-intf.php". The file was found but the class was not in it, the class name or namespace probably has a typo."
Steps To Reproduce
- Create a Symfony project
- Create a command
- Try to use Connection like in the following code
<?php
declare(strict_types=1);
namespace App\Command;
use Nette\Database\Connection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class TestCommand extends Command
{
protected static $defaultName = 'app:test';
protected static $defaultDescription = 'Add a short description for your command';
protected function configure()
{
$this->setDescription(self::$defaultDescription);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$database = new Connection(
'mysql:host=127.0.0.1;dbname=test',
'test',
'xxx'
);
return Command::SUCCESS;
}
}Possible Solution
As suggested on StackOverflow (https://stackoverflow.com/questions/66458897/nette-database-not-working-in-symfony-5-2-command) the IConventions alias in "compatibility-intf.php" should be created when the IConventions class does not exist, not when the ISupplementalDriver class does not exits.
So instead of
} elseif (!interface_exists(ISupplementalDriver::class)) {
class_alias(Driver::class, ISupplementalDriver::class);
class_alias(Conventions::class, IConventions::class);
}it should be
if (!interface_exists(ISupplementalDriver::class)) {
class_alias(Driver::class, ISupplementalDriver::class);
}
if (!interface_exists(IConventions::class)) {
class_alias(Conventions::class, IConventions::class);
}