-
Notifications
You must be signed in to change notification settings - Fork 379
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
[Loader] [Locator] FileSystemLocator service must not be shared #875
[Loader] [Locator] FileSystemLocator service must not be shared #875
Conversation
cfff97d
to
3e2a117
Compare
3e2a117
to
0695ad0
Compare
return new Reference( | ||
sprintf('liip_imagine.binary.locator.%s', $reference), | ||
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, | ||
SymfonyFramework::hasDefinitionSharedToggle() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The third argument (strict) was removed in symfony 3.0.
Should we use an switch like
if (symfony 2.x) {
return new Reference(
sprintf('liip_imagine.binary.locator.%s', $reference),
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
false
);
return new Reference(sprintf('liip_imagine.binary.locator.%s', $config['locator']);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I left it like this is because that will always be true for Symfony >=2.8
, and therefore it doesn't matter that it's ignored. We only care about it when it is false
on Symfony <2.8
. Otherwise, the extra parameter can be, and is, safely ignored (the PHP interpreter allows and ignores any extra parameters). Do you really think it's necessary to add a switch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good morning @robfrawley, not an easy question. You are right, the code is fine.
I would prefer a feature switch at the moment and remove it in future (maybe 2.0) when at least symfony 2.8 will be supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok; ammended the code to the following:
$name = sprintf('liip_imagine.binary.locator.%s', $reference);
if (SymfonyFramework::hasDefinitionSharedToggle()) {
return new Reference($name);
}
return new Reference($name, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
I didn't use a version toggle, as I want to use the exact mechanism that requires a non-strict reference, which can be found here. Also, I want to avoid a direct dependency on the Symfony kernel in-code for now.
ba03e11
to
45c057c
Compare
Hi @robfrawley thank you for this PR that actually fix our problem too Do you think it is going to be merged soon? Many thanks :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely fine with this PR, and loving the feature toggling. Will make it much easier to reduce breakage of BC!
@noniagriconomie It's excellent to hear that this PR resolves any issues you were encountering with this bundle! With regard to the rollout of this bugfix, I'll merge this PR into As for the next stable release, I am shooting for this coming weekend. There a two additional PRs (which I will be posting shortly) that I would like to include in the upcoming release; those are the main reason for the short delay. At the latest, by Monday 2017-02-27 you will be able to require a stable version constraint and benefit from this fix via the @antoligy Thanks for allotting the time to provide feedback; it always feels wrong to merge PRs without some form of peer-review. :-) As always, much appreciated. |
fine, waiting the publication of v1.7.3 then :) |
This PR adds a compiler pass that gathers the
Locator
services and makes them not shared, causing the Symfony container to instantiate new objects each time they are requested (instead of the default behavior of re-using the first instance created).This solves a bug introduced in
1.7.2
that causes those who use multipleFileSystemLoader
definitions to only have their last path registered. Functional tests have been added to ensure a similar regression does not occur in the future.Additionally, when the
*Locator
classes were implemented, exceptions originating from Symfony'sOptionsResolver
were ignored; this PR adds a try/catch block to theFileSystemLocator::setOptions()
method and throws an exception originating from theLiip
namespace so users don't have to worry about catching external dependencies' exceptions.Note: This PR should not be merged into the
2.0
branch. The special handling seen in this PR is only required because the1.0
branch supports both Symfony<2.8
and>=2.8
. These versions require different mechanisms for achieving non-shared services (with<2.8
requiring "prototype" scoping and>=2.8
allowing the service to be simply defined as "not shared"). The2.0
branch can achieve the same intent of this PR by simpy addingshared="false"
to the locator service definitions.