zend-expressive icon indicating copy to clipboard operation
zend-expressive copied to clipboard

Several selectable DI Containers do not implement Interop\Container, causing an error in Zend Expressive 3

Open olger01 opened this issue 6 years ago • 2 comments

I set up a fresh installation of Zend Expressive 3 through the composer create-project command, and selected the following options:

  • Modular installation type
  • Symfony DI Container
  • FastRoute router
  • Zend-view template engine
  • Whoops error handler

Without adjusting anything within the project and accessing the project in my local development environment I'm faced with the following error:

Fatal error: Uncaught Zend\ServiceManager\Exception\InvalidArgumentException: Zend\ServiceManager\AbstractPluginManager expects a ConfigInterface or ContainerInterface instance as the first argument; received Symfony\Component\DependencyInjection\ContainerBuilder in /var/www/zend-expressive-skeleton/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php:59 Stack trace: #0 /var/www/zend-expressive-skeleton/vendor/zendframework/zend-view/src/HelperPluginManager.php(253): Zend\ServiceManager\AbstractPluginManager->__construct(Object(Symfony\Component\DependencyInjection\ContainerBuilder), Array) #1 /var/www/zend-expressive-skeleton/vendor/zendframework/zend-expressive-zendviewrenderer/src/HelperPluginManagerFactory.php(20): Zend\View\HelperPluginManager->__construct(Object(Symfony\Component\DependencyInjection\ContainerBuilder)) #2 /var/www/zend-expressive-skeleton/vendor/jsoumelidis/zend-sf-di-config/src/CallbackFactory.php(94): Zend\Expressive\ZendView\HelperPluginManagerFactory->__invoke(Object(Symfony\Com in /var/www/zend-expressive-skeleton/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php on line 59

The problem seems to be that the application can not be instantiated as AbstractPluginManager (by extension by the HelperPluginManager) expects an instance of Interop\Container while Symfony\Component\DependencyInjection\ContainerBuilder does not implement this, but rather implements the Psr\Container\ContainerInterface directly.

This same problem also happens with both Pimple and Auryn, also selectable DI Containers. When I set up the project with the same modules, but select the default Zend DI Container it works just fine out of the box. I expected to see the same result when choosing the Symfony DI Container, Pimple, or Auryn in the configuration options, as the create project wizard leads me to believe these are supported DI Containers.

Some additional information, according to composer.lock:

  • zendframework/zend-expressive-skeleton version: 3.0.4
  • symfony/dependency-injection version: v4.0.7
  • container-interop/container-interop: 1.2.0

As a side note: I do not fully understand why the AbstractPluginManager expects an instance of Interop\Container since this is an interface which has been deprecated over a year ago in favour of the PSR-11 Container interface. DI Containers like Symfony, Pimple and Auryn have clearly already caught up with this. As Zend Expressive 3 is so new I expect it to use the PSR-11 interface for the best compatibility with up to date DI Containers.

olger01 avatar Apr 03 '18 13:04 olger01

DI Containers like Symfony, Pimple and Auryn have clearly already caught up with this. As Zend Expressive 3 is so new I expect it to use the PSR-11 interface for the best compatibility with up to date DI Containers.

zend-servicemanager uses PSR-11 as well. However the AbstractPluginManager is still not compatible with psr-11 containers. If I am not misstaken, it says that zend-view requires zend-servicemanager. Until it is compatible, the solution is to use zend-servicemanager as the main container instead of symfony di or use twig or plates as the template renderer.

geerteltink avatar Apr 03 '18 14:04 geerteltink

This repository has been closed and moved to mezzio/mezzio; a new issue has been opened at https://github.com/mezzio/mezzio/issues/9.

weierophinney avatar Dec 31 '19 20:12 weierophinney