I asked a question, it replied by asking me another question:

#3
by mahen23 - opened

๐Ÿ˜ƒ: why i am getting this error:
Compile Error: Declaration of ContainerD4tIYZ5\App_KernelDevDebugContainer::load($file, $lazyLoad = true) must be compatible with Symfony\Component\DependencyInjection\Container::load(string $file): mixed
๐Ÿค–: ```

I am getting this error while updating my Symfony app from 4.4 to 6.1.2. I think it has something to do with the way I am loading services in my AppKernelDevDebugContainer. Here is the relevant code:

protected function loadFromPsr4(ContainerBuilder $container, string $resource, string $type = null)
{
    if (\is_dir($resource)) {
        $resource = new \DirectoryIterator($resource);
        foreach ($resource as $file) {
            if ($file->isDot() || !$file->isFile()) {
                continue;
            }
            $loader = new PhpFileLoader($container, $file->getRealPath());
            $loader->load($file->getFilename());
        }
    } else {
        $loader = new PhpFileLoader($container, $resource);
        $loader->load($resource);
    }
}

public function load(ContainerBuilder $container, string $file, bool $lazyLoad = true)
{
    $this->loadFromPsr4($container, $file, get_class($this));
}

As you can see, I am overloading the load method in AppKernelDevDebugContainer to load services from a specific directory. However, I am not sure how to make this compatible with the changes in Symfony 6.1.2.

Any help would be greatly appreciated!

Sign up or log in to comment