You are here

abstract class AbstractGeometryProvider in Geocoder 8.2

Same name and namespace in other branches
  1. 8.3 modules/geocoder_geofield/src/Geocoder/Provider/AbstractGeometryProvider.php \Drupal\geocoder_geofield\Geocoder\Provider\AbstractGeometryProvider

Provides an abstract file handler to be used by GeoPHP Wrapper.

Hierarchy

Expanded class hierarchy of AbstractGeometryProvider

File

modules/geocoder_geofield/src/Geocoder/Provider/AbstractGeometryProvider.php, line 12

Namespace

Drupal\geocoder_geofield\Geocoder\Provider
View source
abstract class AbstractGeometryProvider implements GeometryProviderInterface {

  /**
   * Geophp interface.
   *
   * @var \Drupal\geofield\GeoPHP\GeoPHPInterface
   */
  protected $geophp;

  /**
   * Geophp Type.
   *
   * @var string
   */
  protected $geophpType = '';

  /**
   * {@inheritdoc}
   */
  public function __construct() {
    $this->geophp = \Drupal::service('geofield.geophp');
  }

  /**
   * {@inheritdoc}
   */
  public function getName() : string {
    return 'geophp_provider';
  }

  /**
   * {@inheritdoc}
   */
  public function geocode($filename) : Geometry {
    if (file_exists($filename)) {
      $geophp_string = file_get_contents($filename);

      /* @var \Geometry $geometry */
      $geometry = $this->geophp
        ->load($geophp_string, $this->geophpType);
      if (!empty($geometry->components) || $geometry instanceof \Geometry) {
        return $geometry;
      }
    }
    throw new NoResult(sprintf('Could not find %s data in file: "%s".', $this->geophpType, basename($filename)));
  }

  /**
   * {@inheritdoc}
   */
  public function reverse($latitude, $longitude) {
    throw new UnsupportedOperation(sprintf('The %s plugin is not able to do reverse geocoding.', $this->geophpType));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractGeometryProvider::$geophp protected property Geophp interface.
AbstractGeometryProvider::$geophpType protected property Geophp Type. 3
AbstractGeometryProvider::geocode public function Geocode a source string. Overrides GeometryProviderInterface::geocode
AbstractGeometryProvider::getName public function Returns the Geometry provider's name. Overrides GeometryProviderInterface::getName 3
AbstractGeometryProvider::reverse public function Reverse ReverseGeocode. Overrides GeometryProviderInterface::reverse
AbstractGeometryProvider::__construct public function