-
Notifications
You must be signed in to change notification settings - Fork 523
[WIP] Extend #357 #359
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
Merged
[WIP] Extend #357 #359
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,8 @@ | |
|
|
||
| namespace Geocoder\Provider; | ||
|
|
||
| use Geocoder\ProviderBasedGeocoder; | ||
| use Geocoder\Geocoder; | ||
| use Geocoder\Model\AddressFactory; | ||
| use Ivory\HttpAdapter\HttpAdapterInterface; | ||
|
|
||
| /** | ||
|
|
@@ -21,90 +22,53 @@ abstract class AbstractProvider | |
| /** | ||
| * @var HttpAdapterInterface | ||
| */ | ||
| protected $adapter; | ||
| private $adapter; | ||
|
|
||
| /** | ||
| * @var string | ||
| * @var AddressFactory | ||
| */ | ||
| protected $locale; | ||
| private $factory; | ||
|
|
||
| /** | ||
| * @var integer | ||
| */ | ||
| protected $maxResults = ProviderBasedGeocoder::MAX_RESULTS; | ||
| private $limit = Provider::MAX_RESULTS; | ||
|
|
||
| /** | ||
| * @param HttpAdapterInterface $adapter An HTTP adapter. | ||
| * @param string $locale A locale (optional). | ||
| * @param HttpAdapterInterface $adapter An HTTP adapter | ||
| */ | ||
| public function __construct(HttpAdapterInterface $adapter, $locale = null) | ||
| { | ||
| $this->setAdapter($adapter); | ||
| $this->setLocale($locale); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the HTTP adapter. | ||
| * | ||
| * @return HttpAdapterInterface | ||
| */ | ||
| public function getAdapter() | ||
| { | ||
| return $this->adapter; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the HTTP adapter to be used for further requests. | ||
| * | ||
| * @param HttpAdapterInterface $adapter | ||
| * | ||
| * @return AbstractProvider | ||
| */ | ||
| public function setAdapter($adapter) | ||
| public function __construct(HttpAdapterInterface $adapter) | ||
| { | ||
| $this->adapter = $adapter; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the configured locale or null. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getLocale() | ||
| { | ||
| return $this->locale; | ||
| $this->factory = new AddressFactory(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function setLocale($locale = null) | ||
| public function limit($limit) | ||
| { | ||
| $this->locale = $locale; | ||
| $this->limit = $limit; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function setMaxResults($maxResults) | ||
| public function getLimit() | ||
| { | ||
| $this->maxResults = $maxResults; | ||
|
|
||
| return $this; | ||
| return $this->limit; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the maximum of wished results. | ||
| * Returns the HTTP adapter. | ||
| * | ||
| * @return integer | ||
| * @return HttpAdapterInterface | ||
| */ | ||
| public function getMaxResults() | ||
| public function getAdapter() | ||
| { | ||
| return $this->maxResults; | ||
| return $this->adapter; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -114,10 +78,15 @@ public function getMaxResults() | |
| */ | ||
| protected function getDefaults() | ||
| { | ||
| return array( | ||
| return [ | ||
| 'latitude' => null, | ||
| 'longitude' => null, | ||
| 'bounds' => null, | ||
| 'bounds' => [ | ||
| 'south' => null, | ||
| 'west' => null, | ||
| 'north' => null, | ||
| 'east' => null, | ||
| ], | ||
| 'streetNumber' => null, | ||
| 'streetName' => null, | ||
| 'locality' => null, | ||
|
|
@@ -130,7 +99,7 @@ protected function getDefaults() | |
| 'country' => null, | ||
| 'countryCode' => null, | ||
| 'timezone' => null, | ||
| ); | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -140,23 +109,25 @@ protected function getDefaults() | |
| */ | ||
| protected function getLocalhostDefaults() | ||
| { | ||
| return array( | ||
| return [ | ||
| 'locality' => 'localhost', | ||
| 'region' => 'localhost', | ||
| 'county' => 'localhost', | ||
| 'country' => 'localhost', | ||
| ); | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @param array $results | ||
| * @param array $data An array of data. | ||
| * | ||
| * @return array | ||
| * @return \Geocoder\Model\Address[] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The FQCN is not needed here ;) |
||
| */ | ||
| protected function fixEncoding(array $results) | ||
| protected function returnResults(array $data = []) | ||
| { | ||
| return array_map(function ($value) { | ||
| return is_string($value) ? utf8_encode($value) : $value; | ||
| }, $results); | ||
| if (0 < $this->getLimit()) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to throw an exception, if |
||
| $data = array_slice($data, 0, $this->getLimit()); | ||
| } | ||
|
|
||
| return $this->factory->createFromArray($data); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There is a dot to much.