Skip to content

Conversation

@willdurand
Copy link
Member

This PR is based on @MattKetmo's work. His initial idea was a sort of eye-opener to me, hence this PR.

I removed useless methods in the AbstractProvider. I believe we could have a AbstractLocaleAwareProvider too. The LocaleAwareProvider interface does not make much sense at this point, I'd drop it.

The ProviderBasedGeocoder should be an aggregator or proxy.

The codebase is getting more and more readable and clean.

Edit: I chose to keep the LocaleAwareProvider interface as it is a pretty common use case.

Copy link
Contributor

Choose a reason for hiding this comment

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

The FQCN is not needed here ;)

@willdurand willdurand force-pushed the issue-357 branch 3 times, most recently from b8d76a9 to 65768bb Compare November 2, 2014 23:28
@willdurand willdurand added this to the 3.0.0 milestone Nov 2, 2014
@willdurand
Copy link
Member Author

More work in progress pushed.

Copy link
Member

Choose a reason for hiding this comment

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

There is a dot to much.

@Baachi
Copy link
Member

Baachi commented Nov 3, 2014

Really cool work! Looking forward!

@giosh94mhz
Copy link
Contributor

You're doing a great job @willdurand . I have a minor suggestion.

The constructor of an AbstractProvider require an instance of HttpAdapterInterface, which doesn't really make sense when creating "local provider" (GeoIP db, Geonames imported in Doctrine, Apache local extensions and so on). Also, the adapter is never really used in the AbstractProvider class, so.. why not drop it? This will allow better subclassing.

Then, to avoid code duplication, you may just use a simple trait in the subclasses which add setAdapter/getAdapter.

@willdurand
Copy link
Member Author

Thank you!

As for the AbstractProvider, it is a common class for most providers, as most of them depend on a HTTP API. It is not useful for all providers. I'll see how to fix this after this PR :-)

@Baachi
Copy link
Member

Baachi commented Nov 3, 2014

@willdurand as you bump the php version to 5.4, why not add a HttpAdapterTrait to all providers which use the http protocol?

@willdurand
Copy link
Member Author

To be honest, I don't like traits.

@giosh94mhz
Copy link
Contributor

@willdurand I agree with you that traits are not that cool, but are a decent alternative of having a complex hierarchy (in this case by having two abstract class AbstractProvider and AbstractHttpProvider) or a lot of code getter/setter code-duplication. I like the idea of HttpAdapterTrait, but maybe I am biased since I love the "C++ way" :)

@Baachi
Copy link
Member

Baachi commented Nov 3, 2014

@willdurand Yeah, traits are not the best OOP way, but it would be the easiest way. If you have a better option, let me know :)

@MattKetmo
Copy link
Contributor

Traits are cool, but I neither don't like them for constructors.
IMO having AbstractProvider + AbstractHttpProvider extends AbstractProvider is 👍.

@giosh94mhz
Copy link
Contributor

@MattKetmo I never meant for constructors: that would be really odd 8-/. Just for protected property + setter/getter...

@Baachi
Copy link
Member

Baachi commented Nov 3, 2014

I agree with @giosh94mhz . The trait should be a client property with the needed accessors.

@MattKetmo
Copy link
Contributor

Indeed, I didn't read your last phrase about the setAdapter/getAdapter.
But then I'm -1 on this since non-nullable attributes should be passed through the constructor.

@giosh94mhz
Copy link
Contributor

@MattKetmo maybe you're right. Since this is geocoder (not geocoder-bundle, which has DI), using setter/getter imply that the dependency is optional; this doesn't really make sense for remote-providers (I smell "if-null-throw" sanity checks). Do you agree @Baachi ?
So, I also 👍 to AbstractProvider + AbstractHttpProvider extends AbstractProvider.

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to throw an exception, if getLimit returns a value lower than 0.

@Baachi
Copy link
Member

Baachi commented Nov 5, 2014

@giosh94mhz Yeah i agree with you. So lets create an AbstractHttpProvider if @willdurand agrees.

This PR is based on @MattKetmo's work. His initial idea was a sort of
eye-opener to me, hence this PR.

I removed useless methods in the AbstractProvider. I believe we could
have a AbstractLocaleAwareProvider too. The LocaleAwareProvider
interface does not make much sense at this point, I'd drop it.

The ProviderBasedGeocoder should be an aggregator or proxy.

The codebase is getting more and more readable and clean.

Edit: I chose to keep the LocaleAwareProvider interface as it is a
pretty common use case.
@willdurand
Copy link
Member Author

Ok so I finished most of the work here, but some tests are failing because we have to rewrite them. I am going to merge it right now.

Then, @Baachi @toin0u I'd love your help on fixing the test suite. It is a matter of rewriting test cases, because results were array-based, and now we have an Address class.

willdurand added a commit that referenced this pull request Nov 23, 2014
@willdurand willdurand merged commit 8dd71cf into master Nov 23, 2014
@willdurand willdurand deleted the issue-357 branch November 23, 2014 16:51
@willdurand
Copy link
Member Author

Anyone willing to contribute the AbstractHttpProvider class?

willdurand added a commit that referenced this pull request Dec 6, 2014
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.

6 participants