-
Notifications
You must be signed in to change notification settings - Fork 89
Zend\ServiceManager\Factory\FactoryInterface does not use Psr\Container\ContainerInterface yet #184
Comments
psr-11.md says this is coming in v4. Makes sense - it's a BC break - but an over-eager search-and-replace at work broke lots of stuff for me ;) |
Ok, then I guess this should include a warning: http://zendframework.github.io/zend-expressive/reference/migration/to-v2/#psr-11-support |
Added an issue for |
Note; probably an assumption (at least on my side) but I'd expect |
Just a couple notes:
Thus, the migration path is to:
When it comes to abstract factories, I'd argue you should likely try not to use them. They are one of the configuration types that are non-portable between different containers. Consider using the zend-servicemanager v4 will implement PSR-11 directly, and the various interfaces consuming a container will typehint against it as well. Most likely, we will allow v4 within Expressive as well as v3 once it is released, as the consumer aspects will be the same. (That said, we may do something different with aliases and invokables for v4; if we do, we'll have a v3 minor release that provides forwards compatibility, just as we did when prepping v3.) |
Encountered this as well when trying to use PHP-DI as a DIC. PHP-DI already uses PSR-11, while https://github.com/zendframework/zend-servicemanager/blob/release-2.7.11/src/AbstractPluginManager.php#L12 does not, causing an error.
This should do the trick, any plans for https://github.com/zendframework/zend-servicemanager/blob/dev-4.0/src/AbstractPluginManager.php#L10 See elie29/zend-di-config#25 for a complete description |
@holtkamp if you need compatibility with libraries that still use Interop Container you can decorate your PSR container: <?php
declare(strict_types=1);
namespace App;
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface as PsrContainer;
class InteropContainerDecorator implements ContainerInterface
{
/** @var PsrContainer */
private $container;
public function __construct(PsrContainer $container)
{
$this->container = $container;
}
public function get($id)
{
return $this->container->get($id);
}
public function has($id)
{
return $this->container->has($id);
}
} And register it as with a factory: return [
'dependencies' => [
'aliases' => [
\Interop\Container\ContainerInterface::class => \App\InteropContainerDecorator::class,
],
],
]; |
Thanks for the suggestions, tried a bit and this seems not to work. Apparently
For now using an fork of class Container implements \Psr\Container\ContainerInterface, \Interop\Container\ContainerInterface, FactoryInterface, InvokerInterface {
/* rest of code */
} A minor new release of ZendServiceManager which also accepts a PSR-11 container would be nice. |
Oh, you're right. I think the bug is here Because So, you can use zend-view HelperPluginManager only with zend-servicemanager. The only thing you can do at this moment is to try to use the decorated container and create your factory to instantiate the HelperPluginManager. |
You can add in the container an alias from interop container to Psr container without the need of decorator. |
@elie29 with PHP-DI 6.0 the container only implements the Psr container, while zend-view and other services (zend-hydrator for me) requires the interop container. Just an alias is not enough. The decorator allowed me to use an interop container for factories that requires an interop container, but in this case I think is more a bug of |
@thomasvargiu thanks for the effort and ideas! @elie29 yeah, tried that in 'aliases' => [
// Fully\Qualified\ClassOrInterfaceName::class => Fully\Qualified\ClassName::class,
//\Interop\Container\ContainerInterface::class => \Psr\Container\ContainerInterface::class,
\Psr\Container\ContainerInterface::class => \Interop\Container\ContainerInterface::class,
], Hower it seems that What did function is to use the PHP-DI ContainerBuilder->wrapContainer() functionality and use the namespace Zend\DI\Config;
use App\InteropContainerDecorator;
use DI\ContainerBuilder;
use Psr\Container\ContainerInterface;
use Zend\DI\Config\ConfigInterface;
class ContainerFactory
{
public function __invoke(ConfigInterface $config): ContainerInterface
{
$builder = new ContainerBuilder();
$config->configureContainer($builder);
$wrapperContainer = new InteropContainerDecorator();
$builder->wrapContainer($wrapperContainer);
$psrContainer = $builder->build();
$wrapperContainer->setPsrContainer($psrContainer);
return $wrapperContainer;
}
} But that is quite specific to https://github.com/elie29/zend-di-config, I think for now I should leave this and wait for a update to ZendServiceManager to actually use PSR-11. |
You can kick off the container in the front controller so it is ready before other dependencies. However, phpdi is Psr compliant but not interop. So we need to wait for zend service v4 |
@elie29 indeed. Another option would be to add support for "PHP-DI wrapContainer functionality" in https://github.com/elie29/zend-di-config However to me this seems like a waste of time 😄 . I am still in the orientation phase of adopting Zend Expressive with PHP-DI, so this is not a big issue for me. Will be patient 👍 |
@holtkamp I have been using zend expressive with twig and Json repsonse for almost 2 years. And I have no issues with php di v6 |
@holtkamp PHP-DI 6.0 was released on February XD The problem is when some factory requires an interop container (that extends psr container from v1.2), but if you use a non interop compatible container, you can't inject it to that factory. So:
If someone want to use old libraries that requires an interop container they should decorate its container to make it compatible. But probably we are going out of topic here. |
#184 (comment) #184 (comment)
I agree, let's leave this rest for now 😄. I think I will submit an issue + PR to also "allow" a |
The last release of https://github.com/elie29/zend-di-config supports Interop Container in order to be used with zend view. |
So, 3 days ago the Please no hack or new library etc. Walkarounds are ot useful for a problem, which exists since more than 2 years. |
What would you suggest as a (backward compatible) solution? |
@dpauli We will be doing a new major release that targets the final specification; it has to be a major release, though, because it changes signatures for any code that extends our classes or implements our interfaces. (I mean, the actual signature remains the same, it's the inheritance tree that changes, but PHP doesn't make a distinction there.) This will not happen until we transition to Laminas (which is soon). We've not done it sooner as it affects any components that provide plugin managers as well, which means those will also require new major versions. As such, it's a non-trivial change for both our libraries and our end-users. |
This repository has been closed and moved to laminas/laminas-servicemanager; a new issue has been opened at laminas/laminas-servicemanager#18. |
I want to make my factories to use
Psr\Container\ContainerInterface
in anZend\Expressive
project. But theZend\ServiceManager\Factory\FactoryInterface
does not usePsr\Container\ContainerInterface
yet.What are the plans about this?
The text was updated successfully, but these errors were encountered: