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

Registry::container()->get($id) throws an exception if the interface cannot be found #5072

Open
Jefferson49 opened this issue Dec 8, 2024 · 2 comments

Comments

@Jefferson49
Copy link
Contributor

Observed with webtrees 2.2.1

The newly added Registry::container()->get($id) throws an exception if the interface cannot be found:

ReflectionException: Class "Cissee\WebtreesExt\MoreI18N" does not exist in C:\wamp64\www\webtrees\app\Container.php:81
Stack trace:
#0 C:\wamp64\www\webtrees\app\Container.php(81): ReflectionClass->__construct('Cissee\\Webtrees...')
#1 C:\wamp64\www\webtrees\app\Container.php(58): Fisharebest\Webtrees\Container->make('Cissee\\Webtrees...') 

Shouldn't this exception be caught and get($id) could return null instead?

@fisharebest
Copy link
Owner

I think throwing an exception is the correct action.

The container specification lists specific exceptions that should be thrown.

return null instead?

Containers can contain any type of object - including NULL. At present, we only store objects in it, but this could always change.

@Jefferson49
Copy link
Contributor Author

o.k., I understand; thanks for providing the background! I did not know that a detailed specification is available.

My take away from the specification is that Registry::container()->get($id) should keep throwing an exception if the interface is not found. However, the specific exception should be: NotFoundExceptionInterface. In my example - which is not representative - a ReflectionException was thrown.

I recognized that webtrees already has a NotFoundInContainerException, which implements the proposed NotFoundExceptionInterface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants