Skip to content

Refactor providers to leverage ResultFactories - fix #232 #233

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

Merged

Conversation

toin0u
Copy link
Member

@toin0u toin0u commented May 14, 2013

  • FreeGeoIpProvider
  • HostIpProvider
  • IpInfoDbProvider
  • YahooProvider (REMOVED)
  • GoogleMapsProvider
  • GoogleMapsBusinessProvider
  • BingMapsProvider
  • OpenStreetMapsProvider
  • CloudMadeProvider
  • GeoipProvider
  • MapQuestProvider
  • OIORestProvider
  • GeocoderCaProvider
  • GeocoderUsProvider
  • IGNOpenLSProvider
  • DataScienceToolkitProvider
  • YandexProvider
  • GeoPluginProvider
  • GeoIPsProvider
  • MaxMindProvider
  • MaxMindBinaryProvider
  • GeonamesProvider
  • IpGeoBaseProvider
  • BaiduProvider
  • TomTomProvider
  • ArcGISOnlineProvider

@willdurand @Baachi What do you think ?

@willdurand
Copy link
Member

Looks good to me.

One question though, should I consider this as a BC break? Or people don't use providers in a standalone way?
Depending on the answer, it may imply a new major release.

@toin0u
Copy link
Member Author

toin0u commented May 15, 2013

When all providers will be rewritten, they will return all results so DefaultResultFactory with returns the first one and MultilpleResultFactory all of them. It will not be a BC break because the DefaultResultFactory is the one by default. But I guess it can be a major release anyway :)

@willdurand
Copy link
Member

well, I won't bump a new major release just for fun. I was talking about using providers without the result factories, which could be a BC break in that case.

@toin0u
Copy link
Member Author

toin0u commented May 15, 2013

Oh yes I see now. I never used providers without factories. Well, in this case, it will be a BC break !

@toin0u
Copy link
Member Author

toin0u commented May 20, 2013

@willdurand @baashi All providers are rewitten (except YahooProvider see #230). Tests are also updated.

I just ran the test suite. Some tests are skipped or incomplete:

screenshot 2013-05-20 a 18 03 59

@willdurand
Copy link
Member

Alright, so let's remove the Yahoo provider first.

The maxromanovsky/php-maxmind-geoip lib is annoying. If they don't fix their stuff by using function_exists() to define functions only if they don't exist, we will drop the provider that integrates this awful lib.

@willdurand
Copy link
Member

I think one commit would be enough btw.

@toin0u
Copy link
Member Author

toin0u commented May 20, 2013

I agree it's annoying :(

Ok I'll remove YahooProvider and squash commits.

@willdurand
Copy link
Member

@toin0u make a commit for the providers, and another one for the Yahoo provider removal

@toin0u
Copy link
Member Author

toin0u commented May 20, 2013

@willdurand Rebased and squashed :) And there is an other PR for Yahoo provider.

@toin0u
Copy link
Member Author

toin0u commented May 20, 2013

Test is fixed by #237

} else {
$data = $json->geonames;

if (!isset($data) || empty($data)) {
Copy link
Member

Choose a reason for hiding this comment

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

isset isn't needed here.

@toin0u
Copy link
Member Author

toin0u commented May 21, 2013

Thanks for the review :) I'm not able to fix it right now, I'll do it tonight I think.

@Baachi
Copy link
Member

Baachi commented May 21, 2013

No problem. Thanks for the PR and your awesome work 👍

@toin0u
Copy link
Member Author

toin0u commented May 21, 2013

Thanks for your comment :) 👍

@willdurand
Copy link
Member

Looks good to me. WDYT?

*
* @return array
*/
protected function getResultArray(\Traversable $data)
Copy link
Contributor

Choose a reason for hiding this comment

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

The typehint looks weird. You are never traversing the data (so Traversable on it is useless) but you are accessing properties (not part of the interface)

Copy link
Member Author

Choose a reason for hiding this comment

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

Mmm you're right. So do you recommend to not use any typehint here ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would typehint \SimpleXmlElement

btw @willdurand, is it intended to use \SimpleXmlElement in some providers and DOMDocument in some others ?

Copy link
Member

Choose a reason for hiding this comment

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

No it's not. Just a matter of choice from many contributors.

Copy link
Member Author

Choose a reason for hiding this comment

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

@stof Thanks I'll update this.

@toin0u
Copy link
Member Author

toin0u commented May 22, 2013

I'll make the last updates suggested by @stof and @Baachi asap :)

@toin0u
Copy link
Member Author

toin0u commented May 22, 2013

It should be ok now :)

screenshot 2013-05-22 a 17 33 37

@willdurand
Copy link
Member

What are the 13 skipped tests and the incomplete one?

@toin0u
Copy link
Member Author

toin0u commented May 22, 2013

It's like this comment #233 (comment)

Maybe you want me to rebase ? I can do it but it will be little bit later.

@willdurand
Copy link
Member

No. I want to know if the maxmind-lib issue is fixed.

@toin0u
Copy link
Member Author

toin0u commented May 22, 2013

I understand.

Just for info, I ran the test suite with the last version of php-maxming-geoip which removed the autoloading from composer https://github.com/maxromanovsky/php-maxmind-geoip/issues/5#issuecomment-18193859

  • GeocoderUsProvider: timeout too long
  • MaxMindBinaryProvider: skipped because functions geoip_open and/or GeoIP_record_by_addr are not existing.
  • YahooProvider

screenshot 2013-05-22 a 22 59 21

@willdurand
Copy link
Member

this is annoying. I'm thinking about removing this lib..

@toin0u
Copy link
Member Author

toin0u commented May 22, 2013

I understand..

@toin0u
Copy link
Member Author

toin0u commented May 22, 2013

Mmm the problem is not only with redeclaring existing functions but also the set of define statements in geoip.inc file... https://github.com/maxromanovsky/php-maxmind-geoip/blob/master/geoip.inc#L23-L71

The origin of the lib is here I guess: https://github.com/maxmind/geoip-api-php

@willdurand
Copy link
Member

IMO we a need a better lib to include this provider.

+1000

@toin0u
Copy link
Member Author

toin0u commented May 24, 2013

@willdurand :)
@Baachi @makasim What do you guys think about that ?

@makasim
Copy link
Contributor

makasim commented May 25, 2013

I hoped it could be posible to keep their "not so good code" out of Geocoder. As I see it is not true.

I would try to open issues on maxmind official repo. I would even do some PRs with fixes If they be really active and positve on required changes (function_exist\defined const checks or maybe renaming functions). I dont think I will be able to do it till monday.

@toin0u
Copy link
Member Author

toin0u commented May 26, 2013

@makasim I understand you as well.. I think your provider is good but the library which your provider depends on should be improved to avoid problems. I'm pretty sure that @willdurand @Baachi agree with me. Maybe you can keep us in touch about your PRs and so on..

@makasim
Copy link
Contributor

makasim commented May 27, 2013

Maybe you can keep us in touch about your PRs and so on.

sure

@Baachi
Copy link
Member

Baachi commented May 27, 2013

Why we don't use the offical library?

@makasim
Copy link
Contributor

makasim commented May 27, 2013

Why we don't use the offical library?

I haven't found it

@Baachi
Copy link
Member

Baachi commented May 27, 2013

I prefer the offical driver. I found this driver http://maxmind.github.io/GeoIP2-php/ . The driver looks really good, he supports the webclient and local database. But the driver is for geoIP2, i don't know if there is a big difference between geoIP and geoIP2.

@makasim
Copy link
Contributor

makasim commented May 27, 2013

I prefer the offical driver. I found this driver http://maxmind.github.io/GeoIP2-php/ . The driver looks really good, he supports the webclient and local database. But the driver is for geoIP2, i don't know if there is a big difference between geoIP and geoIP2.

Indeed it looks much more better, but as stated on this page they do not add support of dowloadable databases, they dont even published them.

In the future, this distribution will also provide the same API for the GeoIP2 downloadable databases. These databases have not yet been released as a downloadable product.
Downloadable databases for GeoIP2 are not yet available. However, when they are, they will use our new MaxMind DB format. Once the databases are released, we will provide additional details on their use on this dev site.

@makasim
Copy link
Contributor

makasim commented May 27, 2013

Apperantly GeoipProvider and MaxMindBinaryProvider are both use maxmind's database as source. I would prefer to go with MaxMindBinaryProvider, since the extension is not supported any more (since 2011). As the extension is not updated more then a year it could not match the php lib of current version.

This should be done:

@makasim
Copy link
Contributor

makasim commented May 27, 2013

@Baachi
Copy link
Member

Baachi commented May 27, 2013

Ah i don't saw these sentences, sorry.
But i see that this library is currently alpha, include this library can cause some issues. So we should not require this library.
And yes we should drop the support for the pecl extensions and use the official library instead.

Remove the GeoIPProvider is a BC break, we can only mark it as deprecated.

@willdurand WDYT?

@willdurand
Copy link
Member

it's ok to remove it as of 2.0.0.

@@ -20,6 +20,11 @@
class ArcGISOnlineProvider extends AbstractProvider implements ProviderInterface
{
/**
* @var integer
*/
const MAX_RESULTS = 5;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a special reason why this value is immutable (for this and other providers)? Should be a mutable property, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

@havvg There isn't a special reason. I just thought it's "enough" to have 5 results as maximum.. We can make this property mutable if everybody agree.

@willdurand
Copy link
Member

Maybe it could be a new argument in the geocoder() method, WDYT?

@toin0u
Copy link
Member Author

toin0u commented May 27, 2013

I agree - it's indeed the best place even if some providers don't return many results.

@havvg
Copy link
Contributor

havvg commented May 27, 2013

Hmm.. I'm not sure on this. It would require adding a parameter to the ProviderInterface::getGeocodedData and ProviderInterface::getReversedData for a behavior that is not supported by all providers. So I would rather go for a simple setter/getter (should be distinguished by an interface) and maybe a Geocoder::limit(?) method wrapping it if available:

$geocoder = new \Geocoder\Geocoder($provider);
// add some providers ..

$results = $geocoder
    ->using('bing_maps')
    ->limit(5)
    ->reverse([ 48.8630462, 2.3882487 ])
;

@toin0u
Copy link
Member Author

toin0u commented May 27, 2013

@willdurand @havvg I think we almost agree ;) Maybe Geocoder::limit is better than Geocoder::setMaxResults though..

@makasim
Copy link
Contributor

makasim commented May 28, 2013

The PR with composer support was merged, it autoload's files (as it was in maxromanovsky's lib) but it also has conflict section with ext-geoip: "*". I think I should do the changes in a separate PR? v1?

@willdurand
Copy link
Member

@makasim actually the lib should not conflict. It would be easy to declare functions/constants only if they don't exist.

@makasim
Copy link
Contributor

makasim commented May 28, 2013

@makasim actually the lib should not conflict. It would be easy to declare functions/constants only if they don't exist.

no it is not easy. The extension is not up to date and could be differ (last updated 2011) from current version of the lib (v1.13). So we cannot rely on the extension in all cases. Also if we declare function/constans check it would silently fallback to use the extension and if there is an error a developer would have to spent more time to investigate it. I dont see nothing against marking the ext as conflict. It is not official ext and it does seem like maintened.

@willdurand
Copy link
Member

@makasim ok, I created a 1.7.0 version with a new dependency to geoip/geoip. We won't remove any MaxMind provider by now.

willdurand added a commit that referenced this pull request May 28, 2013
Refactor providers to leverage ResultFactories - fix #232
@willdurand willdurand merged commit 7dadc1c into geocoder-php:master May 28, 2013
@willdurand
Copy link
Member

So I merged this PR into the master (which is 2.0.0-dev). Let's see how to set the limit now, and we will ready for a 2.0.0 release.

@willdurand
Copy link
Member

oh and thank you @toin0u for your awesome work!

@toin0u
Copy link
Member Author

toin0u commented May 28, 2013

You're welcome!

@toin0u toin0u deleted the RefactorProvidersResultFactories branch May 28, 2013 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants