You are here

AddressText.php in Geocoder 8.2

Same filename and directory in other branches
  1. 8.3 src/Plugin/Geocoder/Dumper/AddressText.php

File

src/Plugin/Geocoder/Dumper/AddressText.php
View source
<?php

namespace Drupal\geocoder\Plugin\Geocoder\Dumper;

use Drupal\geocoder\DumperBase;
use Geocoder\Model\Address;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\geocoder\FormatterPluginManager;

/**
 * Provides an address string geocoder dumper plugin.
 *
 * @GeocoderDumper(
 *   id = "addresstext",
 *   name = "Address string"
 * )
 */
class AddressText extends DumperBase {

  /**
   * The Geocoder formatter plugin manager service.
   *
   * @var \Drupal\geocoder\FormatterPluginManager
   */
  protected $geocoderFormatterPluginManager;

  /**
   * The Geocoder formatter.
   *
   * @var \Drupal\geocoder\Plugin\Geocoder\Formatter\FormatterInterface
   */
  protected $geocoderFormatter;

  /**
   * Constructs an AddressText Dumper.
   *
   * @param array $configuration
   *   The configuration.
   * @param string $plugin_id
   *   The plugin ID for the migration process to do.
   * @param mixed $plugin_definition
   *   The configuration for the plugin.
   * @param \Drupal\geocoder\FormatterPluginManager $geocoder_formatter_plugin_manager
   *   The geocoder formatter plugin manager service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, FormatterPluginManager $geocoder_formatter_plugin_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->geocoderFormatterPluginManager = $geocoder_formatter_plugin_manager;
    $this->geocoderFormatter = $this->geocoderFormatterPluginManager
      ->createInstance('default_formatted_address');
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('plugin.manager.geocoder.formatter'));
  }

  /**
   * {@inheritdoc}
   */
  public function dump(Address $address) {
    return $this->geocoderFormatter
      ->format($address);
  }

}

Classes

Namesort descending Description
AddressText Provides an address string geocoder dumper plugin.