Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create IConventions alias when the class does not exist #272

Closed
ghost opened this issue Mar 3, 2021 · 1 comment
Closed

Create IConventions alias when the class does not exist #272

ghost opened this issue Mar 3, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 3, 2021

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);
}
@dg
Copy link
Member

dg commented Mar 3, 2021

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant