php-fig / container

MIT License
9.93k stars 52 forks source link

Replacement for container-interop #37

Open boesing opened 3 years ago

boesing commented 3 years ago

Hey there,

I am working on https://github.com/laminas/laminas-servicemanager/pull/96 and realized that it would be quite simple to fully replace the abandoned package container-interop/container-interop by using some composer magic:

https://github.com/laminas/laminas-servicemanager/pull/96/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R87 https://github.com/laminas/laminas-servicemanager/pull/96/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R52 https://github.com/laminas/laminas-servicemanager/pull/96/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R61


When adding the autoload file to the autoloader like this, all packages type-hinting against the container-interop interfaces will still work and thus, no one will get composer warnings of the abandoned package container-interop/container-interop anymore.

<?php

declare(strict_types=1);

use Interop\Container\Containerinterface as InteropContainerInterface;
use Interop\Container\Exception\ContainerException as InteropContainerException;
use Interop\Container\Exception\NotFoundException as InteropNotFoundException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

class_alias(ContainerInterface::class, InteropContainerInterface::class);
class_alias(ContainerExceptionInterface::class, InteropContainerException::class);
class_alias(NotFoundExceptionInterface::class, InteropNotFoundException::class);

In v1.2.0, container-interop only extends the PSR-Interfaces and has no own methods.


Is this something which would be considered by this component? I know its not the usual way of handling such problems but I'd say it would be "cleaner" in this component than in the laminas/laminas-servicemanager component.

Feedback welcome. If this is not something you want to do in this package, feel free to close this issue as invalid.

mnapoli commented 3 years ago

Hey, that's clever and that sounds good to me.

This could be included in psr/container?

boesing commented 3 years ago

Yes. Just the same way I've done it in laminas/laminas-servicemanager. This wont work with psr/container v2 due to upstream implementations but for 1.2.0 of psr/container this would work.

Imho, if a project enables support for psr/container v2, they wont be able to use container-interop/container-interop anyways until they migrate their own implementations. So having this replacement available in 1.2.0 of this library would totally drop installations for container-interop/container-interop once and for all.

boesing commented 3 years ago

@mnapoli I could create a PoC PR so you guys can decide if this is something you want to do.

mnapoli commented 3 years ago

đź‘Ť for me