-
Notifications
You must be signed in to change notification settings - Fork 522
Allow locale change with chain #408
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
Conversation
@@ -38,6 +40,9 @@ public function geocode($address) | |||
{ | |||
$exceptions = []; | |||
foreach ($this->providers as $provider) { | |||
if($provider instanceof LocaleAwareProvider && $this->getLocale() !== null){ |
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.
Could you please use the coding standards of this project?
- 1 space before
(
null !== ...
rather than the other way around
Does it make sense to check whether locale is null? It does not really matter IMO.
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.
What if registered providers are configured with a locale?
ping @Baachi
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.
@willdurand This should not be a problem, because the chainprovider delegate each call.
Change the locale dynamicaly isn't supported yet. And in my opinion, such functionality made this code more complex.
If someone need this functionality, just create more than one provider like provider_de, provider_en
and so on.
I think the Geocoder
class should be decide which provider should be used not the provider itself. A provider should be invisible for the end user. And if someone really need this functionality, here you go we are in OOP so extend the class.
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.
Problem is when using GeocoderBundle.
For exemple, I got a default locale for Bing Map
providers:
bing_maps:
api_key: ~
locale: fr_FR
I'd like some times set a different locale, but if not, it should use the default one, not erase the default by null
ah right, then fix CS and I'll merge this PR :) |
Done ! Sorry for this mistake. |
@@ -38,6 +40,9 @@ public function geocode($address) | |||
{ | |||
$exceptions = []; | |||
foreach ($this->providers as $provider) { | |||
if ($provider instanceof LocaleAwareProvider && $this->getLocale() !== null){ | |||
$provider->setLocale($this->getLocale()); |
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.
This can lead to an logical error, see this example:
$bing = new BingMaps($http, 'secret', 'de_DE'); // note the locale here
$chain = new Chain([$bing]);
$geocoder = new Geocoder();
$geocoder->registerProvider($bing);
$geocoder->registerProvider($chain);
$geocoder->geocode('Paris'); // Will now use de_DE locale
$chain->setLocale('en_US') // Chain now use en_US
$geocoder->use('chain')->geocoder('Paris'); // I get en_US results
$geocoder->geocode('Paris'); // I expect the locale is de_DE, but it will be en_US because the chain provider will override them.
I would suggest to clone the provider or set the original locale back.
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.
👍
👍 |
@AntoineLemaire could you please squash your commits? |
Fix coding standards Prevent logical error #408 (comment)
Done ! Thanks |
Thank you very much for your contribution! |
\o/ |
Need to change the locale dynamically in PHP for after use it with the CacheProvider of GeocoderBundle