php-fig / container Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hello. I have been following PR #20 and I see that the exception interfaces will extend Throwable
in it, along with the breaking changes with type-hints. However, the static code analyser phpstan is now reporting that the exception interface is not a subtype of Throwable as its an error:
PHPDoc tag @throws with type Psr\Container\ContainerExceptionInterface is not subtype of Throwable
Is there a possibility to fix this outside of PR #20 ? I'm not familiar with any bylaws of FIG and what the possibilities are.
According to the PSR, get
will
throws an exception if the identifier is not known to the container.
Given a call to the container $container->get(Foo::class);
and the fact that Some\Package\Foo
is instantiable (it's a concrete class), should the container resolve it or throw NotFoundException? Of course, the scenario to be discussed is only of interest in case Foo::class
has not been registered in the container before (it's unknown to the container), otherwise the question would be stupid.
namespace Some\Package;
class Foo
{
}
I am currently trying to pull this package in via composer like so:
composer require psr/container
from:
https://packagist.org/packages/psr/container#dev-master
But I am gettingt the following error:
Problem 1
│ - The requested package psr/container could not be found in any version, there may be a typo in the pa
│ckage name.
│
│Potential causes:
│ - A typo in the package name
│ - The package is not available in a stable-enough version according to your minimum-stability setting
│ see https://getcomposer.org/doc/04-schema.md#minimum-stability for more details.
Is there something wrong here? I can pull in other packages fine.
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.
There's no '-Interface' suffix in other PSRs with exception interfaces.
Should PSR-11 follow those PSRs?
I've read through a bunch of topics on container-interop and here that you guys talked A LOT about auto-wiring. Unfortunately the issue keeps popping up on Laravel because we decided that the container only returns true
on has
if objects are explicitly bound. One of the editors himself pointed it out here laravel/ideas#803.
One thing I did not find in the discussions was usage
instead of implementations
and it's likely that you guys can point me to the right direction.
Suppose the following usage:
if ($container->has($identity)) {
try {
$concrete = $container->get($identity);
//
} catch (Psr\Container\ContainerExceptionInterface $e) {
// This will never be a NotFoundExceptionInterface
}
} else {
// Not Found
}
Although a NotFoundException will never be thrown, a ContainerExceptionInterface can still be thrown. How much value did has
added here versus the following:
try {
$concrete = $container->get($identity);
//
} catch (Psr\Container\ContainerExceptionInterface $e) {
if ($e instanceof NotFoundExceptionInterface) {
// Not Found
}
}
My point being: When using $container->get($identity);
, a try-catch is basically a must-have and the value of has
can still be achieved, if desired. What am I missing that makes me think has
do more harm than good?
The spec uses it, the code does not. Is this being debated or has a decision already been taken about whether to add this suffix or not?
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?
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.
It should be possible to support PSR-11 using:
<?php
class Container extends \Psr\Container\ContainerInterface {
public function get(string $id)
{
// ...
}
public function has(string $id)
{
// ...
}
}
Any ideas?
Hey there,
I am working on laminas/laminas-servicemanager#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.
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
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.
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
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?
When running Static-Analysis like Psalm, they will report an invalid catch statement:
InvalidCatch: Class/interface Psr\Container\NotFoundExceptionInterface cannot be caught
This happens because the Interfaces do not extend Throwable
. This is correct since classes that do not implement Throwable
cannot be used with throw
: https://3v4l.org/NNDeW
What about to have this interface?
With this we can do lazy passing the container to a service like the Psr\Log\LoggerAwareInterface
This is literally a backward compatibility break and should never happen in a patch release.
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 :)
Here is the history:
The extension interface did not extend \Throwable
The extension interface did extend \Throwable
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.
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.
The extension interface does not extend \Throwable
.
Removes extension of
Throwable
in theContainerExceptionInterface
to prevent issues under PHP versions < 7.4, where having a concrete instance extendThrowable
as well asContainerExceptionInterface
can lead toE_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.
I just want us to be aware of this and focus on 2 things moving forward:
\Throwable
Hi,
I'm unable to understand why this package psr/container require PHP 7.4.0 as its just collection on some interfaces. I think it should require not more than php: >=5.4.0
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.