You are here

protected function ProviderBase::process in Geocoder 8.2

Same name and namespace in other branches
  1. 8.3 src/ProviderBase.php \Drupal\geocoder\ProviderBase::process()

Provides a helper callback for geocode() and reverse().

Parameters

string $method: The method: 'geocode' or 'reverse'.

array $data: An array with data to be processed. When geocoding, it contains only one item with the string. When reversing, contains 2 items: the latitude and the longitude.

Return value

\Geocoder\Model\AddressCollection|\Geometry|null The Address, NULL otherwise.

2 calls to ProviderBase::process()
ProviderBase::geocode in src/ProviderBase.php
Geocode a source string.
ProviderBase::reverse in src/ProviderBase.php
Reverse geocode latitude and longitude.

File

src/ProviderBase.php, line 90

Class

ProviderBase
Provides a base class for providers using handlers.

Namespace

Drupal\geocoder

Code

protected function process($method, array $data) {
  if ($caching = $this->configFactory
    ->get('geocoder.settings')
    ->get('cache')) {

    // Try to retrieve from cache first.
    $cid = $this
      ->getCacheId($method, $data);
    if ($cache = $this->cacheBackend
      ->get($cid)) {
      return $cache->data;
    }
  }

  // Call the processor.
  $processor = $method == 'geocode' ? 'doGeocode' : 'doReverse';
  $value = call_user_func_array([
    $this,
    $processor,
  ], $data);
  if ($caching) {

    // Cache the result.
    $this->cacheBackend
      ->set($cid, $value);
  }
  return $value;
}