Skip to content

Conversation

@falkenhawk
Copy link
Member

Use sourceCache if isSupported check passes, otherwise proceed without cache and do not throw an exception

  • so that php-di does not break if there is any problem with apcu - instead of having to wrap ContainerBuilder::build() with try...catch block

…t cache and do not throw an exception

- so that php-di does not break if there is any problem with apcu - instead of having to wrap ContainerBuilder::build() with try...catch block
@falkenhawk falkenhawk requested a review from a team April 26, 2019 15:19
@falkenhawk falkenhawk self-assigned this Apr 26, 2019
Copy link
Member

@milanorszagh milanorszagh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.
Was there a reason why we wanted to throw an exception in this case before?

@falkenhawk
Copy link
Member Author

@milanorszagh the original PHP-DI throws the exception, and I'd prefer it not to

if (!SourceCache::isSupported()) {
throw new \Exception('APCu is not enabled, PHP-DI cannot use it as a cache');
}
// use cache if isSupported check passes, otherwise proceed without cache and do not throw an exception
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change but if there was an exception before then this change may break BC because someone may expect this exception for some cases...
I mean that exception was throwing when someone was trying to use APCu cache without enabled php extension. The new version just skipping the cache layer.
Maybe we should notify users somehow about that:

trigger_error("You're trying to use APCu that is not available", E_USER_WARNING);

Of course adding such message still will break BC

Copy link
Member Author

@falkenhawk falkenhawk Apr 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, since this is a BC I see small chances for it to be merged into original repo. But still it might be more convenient to just leave sourceCache turned on and expect the things to work (without cache), even if apcu breaks - the project should not crash in such case - and it should not be required to wrap $container->build() with try...catch in every implementation

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

Successfully merging this pull request may close these issues.

3 participants