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

Use Expressive Skeleton installer with PHP-DI results in error? #25

Closed
holtkamp opened this issue Oct 27, 2018 · 10 comments
Closed

Use Expressive Skeleton installer with PHP-DI results in error? #25

holtkamp opened this issue Oct 27, 2018 · 10 comments
Assignees
Labels
easy-pick good first issue Good for newcomers question Further information is requested

Comments

@holtkamp
Copy link
Contributor

holtkamp commented Oct 27, 2018

I have some experience with PHP-DI and now try to use it with Zend Expressive.

When using composer create-project zendframework/zend-expressive-skeleton expressive-project and selecting PHP-DI as DependencyInjectionContainer, the default installation seems to result in an error:

composer serve => then open gives:

Fatal error: Uncaught Zend\ServiceManager\Exception\InvalidArgumentException: Zend\ServiceManager\AbstractPluginManager expects a ConfigInterface or ContainerInterface instance as the first argument; received DI\Container in /user/project/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php:59 Stack trace: #0 /user/project/vendor/zendframework/zend-view/src/HelperPluginManager.php(253): Zend\ServiceManager\AbstractPluginManager->__construct(Object(DI\Container), Array) #1 /user/project/vendor/zendframework/zend-expressive-zendviewrenderer/src/HelperPluginManagerFactory.php(20): Zend\View\HelperPluginManager->__construct(Object(DI\Container)) #2 [internal function]: Zend\Expressive\ZendView\HelperPluginManagerFactory->__invoke(Object(DI\Container)) #3 /user/project/ in /user/project/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php on line 59

I tried the instructions at https://github.com/elie29/zend-di-config#using-with-expressive

apparently Interop\Container\ContainerInterface is required by Zend\ServiceManager\AbstractPluginManager::__construct(), while the PHP-DI container implements Psr\Container\ContainerInterface.

but am kind of stuck here... Any suggestions? Are the involved libraries still compatible?

Should Zend Expressive switch the the PSR-11 approach?

https://github.com/container-interop/container-interop

Projects consuming container-interop interfaces are very strongly encouraged to directly type-hint on PSR-11 interfaces, in order to be compatible with PSR-11 containers that are not compatible with container-interop.

@elie29
Copy link
Owner

elie29 commented Oct 28, 2018

Thank you for your feedback.

I am using PHP-DI with zend framework and zend expressive with no issues. However, you may need container-interop as suggested by zend expressive if you want to use lazy or Abstract Factory.

I tried now the installation with composer serve and everything works correctly:

image

@elie29 elie29 added the question Further information is requested label Oct 28, 2018
@holtkamp
Copy link
Contributor Author

@elie29 thanks for the swift response. Will try again coming week and report back here. Probably I did something wrong 😉

@holtkamp
Copy link
Contributor Author

It seems related to my preference to use zend-view as template engine:

Which template engine do you want to use?
  [1] Plates
  [2] Twig
  [3] zend-view installs zend-servicemanager
  [n] None of the above

This involves zend-servicemanager, which uses Interop\Container\ContainerInterface in Zend\ServiceManager\AbstractPluginManager::__construct(), at https://github.com/zendframework/zend-servicemanager/blob/release-2.7.11/src/AbstractPluginManager.php#L12

While the PHP-DI container implements Psr\Container\ContainerInterface, see https://github.com/PHP-DI/PHP-DI/blob/6.0.5/src/Container.php#L29

Workarounds:

Not sure whether a solution exists other then "waiting" zend-servicemanager v4...

@elie29
Copy link
Owner

elie29 commented Oct 28, 2018

@holtkamp thank you for the report.

I don't really use zend_view. However, zend-view involves zend-service-manager whose uses obsoleted interop-container.

Second, zend service acts as a container so I don't see the interest of using many containers in the same project.

I will close this issue as it is not related to this package we should wait zend service upgrade.

@elie29 elie29 closed this as completed Oct 28, 2018
@thomasvargiu
Copy link

You need to decorate your PSR container for Interop container compatibility, see this comment

@elie29
Copy link
Owner

elie29 commented Oct 29, 2018

No need for a decorator. Aliasing with Psr container is enough

@elie29
Copy link
Owner

elie29 commented Oct 31, 2018

Until zend service manager release version 4, we have to wrap DI\Container by implementing Interop\Container\ContainerInterface

@elie29
Copy link
Owner

elie29 commented Oct 31, 2018

@holtkamp I released a new version with the wrapper would you please test https://github.com/elie29/zend-di-config/releases/tag/v3.0.9

@elie29 elie29 closed this as completed Oct 31, 2018
@holtkamp
Copy link
Contributor Author

holtkamp commented Nov 1, 2018

@elie29 works perfectly! Very elegant approach, compliments 👍

@elie29
Copy link
Owner

elie29 commented Nov 1, 2018

@holtkamp thank you for testing the version. We can promote it now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy-pick good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants