This repository holds all interfaces related to PSR-11 (Container Interface).

Overview

Container interface

This repository holds all interfaces related to PSR-11 (Container Interface).

Note that this is not a Container implementation of its own. It is merely abstractions that describe the components of a Dependency Injection Container.

The installable package and implementations are listed on Packagist.

Comments
  • Adds parameter typehints to ContainerInterface

    Adds parameter typehints to ContainerInterface

    This patch bumps the minimum supported PHP version to 7.2 and adds parameter typehints to ContainerInterface, as the first step towards adding explicit typehints based on the specification.

    See https://www.php-fig.org/blog/2019/10/upgrading-psr-interfaces/

    opened by weierophinney 25
  • Replace `container-interop/container-interop` v1.2.0

    Replace `container-interop/container-interop` v1.2.0

    NOTE

    Since there is no 1.2.x branch, this PR targets 1.1.x.

    Description

    With v1.2.0 container-interop/container-interop which was released in 02/2017, the package was abandoned. It fully complies with psr/container. Replacing it while keeping BC by adding class_alias will help upstream projects to finally get rid of container-interop/container-interop dependencies.

    Closes #37

    opened by boesing 18
  • The exception is not implementing Throwable

    The exception is not implementing Throwable

    Here is the history:

    Version 1.0.0

    The extension interface did not extend \Throwable

    Version 1.1.0

    The extension interface did extend \Throwable

    Version 1.1.1

    The extension interface did not extend \Throwable.

    [..] as it leads to inheritance issues when child classes implement the Throwable interface in addition to ContainerInterface under PHP versions prior to 7.4.

    Version 2.0.0

    The extension interface did extend \Throwable as it should since it is a new major release and we don't need to consider edge cases with the BC layer.

    Version 2.0.1

    The extension interface does not extend \Throwable.

    Removes extension of Throwable in the ContainerExceptionInterface to prevent issues under PHP versions < 7.4, where having a concrete instance extend Throwable as well as ContainerExceptionInterface can lead to E_FATAL.


    Except for adding 3 type hints, these are the only changes in this repository. How can I, as an open source maintainer, reliably depend on this package? Or how can I, as a user that like static analyses, know what exception to catch? Catching NotFoundExceptionInterface or ContainerExceptionInterface is technically not valid.

    I understand that there was things nobody could expect when releasing 1.1.0. But in my opinion it was a misstake releasing 1.1.1 and 2.0.1. It is way better being predictable and slightly wrong.

    Im not seeking to put blame nor do I require an explanation

    I just want us to be aware of this and focus on 2 things moving forward:

    1. Better and longer review processes. It was just a few hours between 1.1.0 and 1.1.1. I doubt there was a chance for a public review and to consider the consequences.
    2. Version 3 must extend \Throwable
    opened by Nyholm 17
  • Adding type-hints and extending Throwable for exception interfaces

    Adding type-hints and extending Throwable for exception interfaces

    Starting with PHP 7.2, parameter type widening allows us to omit type-hint in implementations.

    This gives us a unique opportunity: we are now able to create a ContainerInterface that has scalar type-hints while retaining compatibility with all implementations. Since usage of scalar type-hints is one of the most requested features of PSR-11, we can fulfill that demand.

    We can do this only from PHP 7.2. This PR proposes to:

    • bump package version to 1.1
    • bump minimum PHP version to 7.2
    • add type hints to get and has

    Composer will do its job and solve dependencies by itself. If PHP < 7.2 is used, it will install psr/container 1.0.x. If PHP 7.2+ is used, it will bump the version to psr/container 1.1.x.

    Users running composer with PHP 7.1 and composer update --ignore-platform-reqs (I know some!) will certainly have a surprise, so we might want to write a blog post somewhere explaining what to do before merging this.

    As a side effect, since we now are using PHP 7, we can rewrite the ContainerExceptionInterface to extend Throwable. This is a best practice as it prevents using this interface on anything but an Exception.

    This PR does not add a "bool" return type on has as this would introduce a compatibility break that is not worth bumping to a major version (this would split the PHP ecosystem in 2 and we don't want to do that).

    Closes #19 Closes #12

    opened by moufmouf 17
  • Add return type hints

    Add return type hints

    This patch builds on #27 and requires a release of ~~2.0.0~~1.1.0 before merging.

    The patch adds a return type hint to ContainerInterface::has(), per the already documented specification, in preparation for a ~~v3~~v2 release. No other methods were eligible, as they specified mixed.

    See https://www.php-fig.org/blog/2019/10/upgrading-psr-interfaces/

    opened by weierophinney 16
  • Make ContainerExceptionInterface extend Throwable where it is available

    Make ContainerExceptionInterface extend Throwable where it is available

    I've run into some static analysis issues because the ContainerExceptionInterface provides no guarantee that it's actually throwable (or catchable more specifically).

    I understand making it extend Throwable would break BC, so I think this would be the ideal middle ground, providing the benefit of stricter typing only where it's available.

    opened by ErikBooij 16
  • PHP version requirement was changed in a patch version (1.1.2)

    PHP version requirement was changed in a patch version (1.1.2)

    Hi,

    In version 1.1.1, PHP version requirement was the following:

    "php": ">=7.2.0"
    

    In version 1.1.2, it was changed to the following:

    "php": ">=7.4.0"
    

    What happens if there is a critical security issue that is fixed in a future release (e.g. 1.1.3)? Projects based on PHP <=7.3 won't be able to upgrade.

    If the reason is that PHP 7.3 will soon be EOL, debian buster uses it and is still maintained (EOL date 2022-08).

    Thanks

    wontfix 
    opened by guvra 13
  • Fatal error with v1.1.0 and PHP 7.2 / 7.3

    Fatal error with v1.1.0 and PHP 7.2 / 7.3

    upgrade to version 1.1 broken many sites:(


    Edit by @mnapoli

    Here is the exception message:

    PHP Fatal error: Class Symfony\Component\DependencyInjection\Exception\ExceptionInterface cannot implement previously implemented interface Throwable in vendor/symfony/dependency-injection/Exception/ExceptionInterface.php on line 22

    opened by axzx 13
  • Purpose of this PSR is moot?

    Purpose of this PSR is moot?

    Since this PSR discourage the service locator pattern, thereby making it so that libraries don't interact with the container, how does this PSR promote interoperability?

    It seems to me that interoperability for libraries is achieved if library authors simply request interfaces in their constructor?

    opened by frodeborli 11
  • Templated container

    Templated container

    Hi,

    What do you think about templating the container interface?

    Roughly https://psalm.dev/r/41be1515c2, but perhaps using vendor specific prefixes for param/return :)

    opened by ro0NL 10
  • Prepare version 2.0.0 of container interface with enabled strict types.

    Prepare version 2.0.0 of container interface with enabled strict types.

    I want to propose to start discussion about moving the version to the next major with enabled typehints, so all new libraries and frameworks could rely on more stable and type-hinted interface.

    opened by lisachenko 9
  • Question: Why there is no set method?

    Question: Why there is no set method?

    Stupid question: why doesn't the interface provide a "set" method? I wonder what the use case for the interface is if I can't rely on a contract about how objects can be stored in the container?

    See similar question on SO at https://stackoverflow.com/q/61504435/6161354.

    Thanks for clarifying.

    opened by tbreuss 3
  • Replacement for container-interop

    Replacement for container-interop

    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.

    opened by boesing 4
  • Add `ContainerException::getContainer()`

    Add `ContainerException::getContainer()`

    It's seems rather weird that an exception which relates to a container has no means of retrieving the container instance. I suggest adding getContainer() to ContainerExceptionInterface, which would return ContainerInterface|null, just in case there really somehow isn't a container associated with it for some reason.

    opened by XedinUnknown 2
  • Have Dummy/Test Container for testing purposes?

    Have Dummy/Test Container for testing purposes?

    PSR Logger has a Null Logger which can be used easily for testing purposes.

    Is there any thought about creating a Dummy/Test/Null container for the same reasons?

    opened by gmponos 2
Releases(2.0.2)
  • 2.0.2(Nov 5, 2021)

    Added

    • This release reverts the removal of the previous patch, re-adding the extension of Throwable by Psr\Container\ContainerExceptionInterface; to avoid issues, PHP >= 7.4 is now required
    Source code(tar.gz)
    Source code(zip)
  • 1.1.2(Nov 5, 2021)

    Added

    • This release reverts the removal of the previous patch, re-adding the extension of Throwable by Psr\Container\ContainerExceptionInterface; to avoid issues, PHP >= 7.4 is now required
    Source code(tar.gz)
    Source code(zip)
  • 2.0.1(Nov 5, 2021)

    Removed

    • This release removes the extension of Throwable by Psr\Container\ContainerInterface, as it leads to inheritance issues when child classes implement the Throwable interface in addition to ContainerInterface under PHP versions prior to 7.4.
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0(Mar 5, 2021)

  • 1.1.1(Mar 5, 2021)

    Removed

    • This release removes the extension of Throwable by Psr\Container\ContainerInterface, as it leads to inheritance issues when child classes implement the Throwable interface in addition to ContainerInterface under PHP versions prior to 7.4.
    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Mar 5, 2021)

    Changed

    • This release modifies Psr\Container\ContainerExceptionInterface to extend the Throwable interface, ensuring that any implementation can actually be thrown as an exception type (the original intention of the specification).

    • This release adds the string typehint to the $id argument of each of the Psr\Container\ContainerInterface::get() and Psr\Container\ContainerInterface::has() methods. These were previously documented in the annotations and specification, and are added to the interfaces as part of the PSR-11 type additions errata.

    Removed

    • This release removes support for PHP versions prior to 7.2.0.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Feb 14, 2017)

Owner
PHP-FIG
PHP-FIG
DI Container (PSR-11)

My DI Container It's my own implementation PSR-11 Container Interface. Installation composer require scruwi/container Init $container = new Container(

null 4 Mar 15, 2022
💎 Flexible, compiled and full-featured Dependency Injection Container with perfectly usable autowiring and support for all new PHP 7 features.

Nette Dependency Injection (DI) Introduction Purpose of the Dependecy Injection (DI) is to free classes from the responsibility for obtaining objects

Nette Foundation 781 Dec 15, 2022
A small PHP dependency injection container

Pimple Caution! Pimple is now closed for changes. No new features will be added and no cosmetic changes will be accepted either. The only accepted cha

Silex 2.6k Dec 29, 2022
The dependency injection container for humans

layout home PHP-DI is a dependency injection container meant to be practical, powerful, and framework-agnostic. Read more on the website: php-di.org G

null 2.4k Jan 4, 2023
Small but powerful dependency injection container

Container (Dependency Injection) This package is compliant with PSR-1, PSR-2, PSR-4 and PSR-11. If you notice compliance oversights, please send a pat

The League of Extraordinary Packages 779 Dec 30, 2022
🚀 PHP Service Container with fast and cachable dependency injection.

ClanCats Container A PHP Service Container featuring a simple meta-language with fast and compilable dependency injection. Requires PHP >= 7.0 Pros: M

ClanCats 28 Apr 13, 2022
Twittee is the smallest, and still useful, Dependency Injection Container in PHP

What is Twittee? Twittee is the smallest, and still useful, Dependency Injection Container in PHP; it is also probably one of the first public softwar

null 133 Dec 5, 2022
Extensible DI container for Symfony2

This package contains an implementation of the Symfony 2 DI container that can be extended using other DI containers (from other frameworks).

TheCodingMachine 1 Apr 2, 2014
Yii Dependency Injection PSR-11 compatible

Yii Dependency Injection PSR-11 compatible dependency injection container that is able to instantiate and configure classes resolving dependencies. Fe

Yii Software 161 Nov 10, 2022
Adapters for PHP framework containers to an interoperable interface

Acclimate - Container Adapters Get Acclimated! Use any third-party dependency injection containers and service locators in your code by adapting them

Acclimate Container 215 Dec 16, 2022
PSR Log - This repository holds all interfaces/classes/traits related to PSR-3.

PSR Log This repository holds all interfaces/classes/traits related to PSR-3. Note that this is not a logger of its own. It is merely an interface tha

PHP-FIG 10.1k Jan 3, 2023
This repository holds the code and script for the Symfony5 Tutorials on SymfonyCasts.

Tutorials, Friendship & Symfony5 Well hi there! This repository holds the code and script for the Symfony5 Tutorials on SymfonyCasts. Setup If you've

null 1 Nov 20, 2021
A simple and flexible PHP middleware dispatcher based on PSR-7, PSR-11, and PSR-15

Woohoo Labs. Harmony Woohoo Labs. Harmony is a PSR-15 compatible middleware dispatcher. Harmony was born to be a totally flexible and almost invisible

Woohoo Labs. 153 Sep 5, 2022
A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package.

Net A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package. Features: No hard dependencies; Favours

Minibase 16 Jun 7, 2022
A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package.

Net A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package. Features: No hard dependencies; Favours

Minibase 16 Jun 7, 2022
Auto-generated Interface and Repository file via Repository pattern in Laravel

Auto-generated Repository Pattern in Laravel A repository is a separation between a domain and a persistent layer. The repository provides a collectio

Ngo Dinh Cuong 11 Aug 15, 2022
PSR-11 compatible Dependency Injection Container for PHP.

bitexpert/disco This package provides a PSR-11 compatible, annotation-based dependency injection container. Have a look at the disco-demos project to

bitExpert AG 137 Sep 29, 2022
DI Container (PSR-11)

My DI Container It's my own implementation PSR-11 Container Interface. Installation composer require scruwi/container Init $container = new Container(

null 4 Mar 15, 2022
Database Repository / PHP Repository / Laravel Repository

Database Repository / PHP Repository / Laravel Repository Installation Use following command to add this package to composer development requirement.

Bakery 6 Dec 21, 2022
💎 Flexible, compiled and full-featured Dependency Injection Container with perfectly usable autowiring and support for all new PHP 7 features.

Nette Dependency Injection (DI) Introduction Purpose of the Dependecy Injection (DI) is to free classes from the responsibility for obtaining objects

Nette Foundation 781 Dec 15, 2022