omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
260 stars 114 forks source link

ORMAdapter problem with EntityManager overriding #324

Closed Nilofar closed 6 months ago

Nilofar commented 9 months ago

Hello,

Can you properly type this code in the ORMAdapter by adding the EntityManagerInterface type to the $manager attribute and to the afterConfiguration method in order to replace the test "$manager instanceof EntityManager"?

Indeed, if we try to override the manager with a decorated manager, the test $manager instanceof EntityManager fails and throws an exception.

But it works correctly by adding an instanceof EntityManagerInterface and it's more SOLID to test an Interface.

class ORMAdapter extends AbstractAdapter
{
    private ManagerRegistry $registry;
    protected EntityManagerInterface $manager;
    protected ClassMetadata $metadata;

....
}
/**
     * @param ORMOptions $options
     */
    protected function afterConfiguration(array $options): void
    {
        // Enable automated mode or just get the general default entity manager
        $manager = $this->registry->getManagerForClass($options['entity']);
        if (!$manager instanceof EntityManagerInterface) {
            throw new InvalidConfigurationException(sprintf('Doctrine has no valid entity manager for entity "%s", is it correctly imported and referenced?', $options['entity']));
        }
....
}
curry684 commented 9 months ago

@shades684 seems to make sense right?

github-actions[bot] commented 7 months ago

Stale issue message