You are here

class ChainCountryResolver in Price 2.0.x

Same name and namespace in other branches
  1. 8 src/Resolver/ChainCountryResolver.php \Drupal\price\Resolver\ChainCountryResolver
  2. 3.x src/Resolver/ChainCountryResolver.php \Drupal\price\Resolver\ChainCountryResolver
  3. 2.x src/Resolver/ChainCountryResolver.php \Drupal\price\Resolver\ChainCountryResolver
  4. 3.0.x src/Resolver/ChainCountryResolver.php \Drupal\price\Resolver\ChainCountryResolver

Default implementation of the chain country resolver.

Hierarchy

Expanded class hierarchy of ChainCountryResolver

1 string reference to 'ChainCountryResolver'
price.services.yml in ./price.services.yml
price.services.yml
1 service uses ChainCountryResolver
price.chain_country_resolver in ./price.services.yml
Drupal\price\Resolver\ChainCountryResolver

File

src/Resolver/ChainCountryResolver.php, line 8

Namespace

Drupal\price\Resolver
View source
class ChainCountryResolver implements ChainCountryResolverInterface {

  /**
   * The resolvers.
   *
   * @var \Drupal\price\Resolver\CountryResolverInterface[]
   */
  protected $resolvers = [];

  /**
   * Constructs a new ChainCountryResolver object.
   *
   * @param \Drupal\price\Resolver\CountryResolverInterface[] $resolvers
   *   The resolvers.
   */
  public function __construct(array $resolvers = []) {
    $this->resolvers = $resolvers;
  }

  /**
   * {@inheritdoc}
   */
  public function addResolver(CountryResolverInterface $resolver) {
    $this->resolvers[] = $resolver;
  }

  /**
   * {@inheritdoc}
   */
  public function getResolvers() {
    return $this->resolvers;
  }

  /**
   * {@inheritdoc}
   */
  public function resolve() {
    foreach ($this->resolvers as $resolver) {
      $result = $resolver
        ->resolve();
      if ($result) {
        return $result;
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ChainCountryResolver::$resolvers protected property The resolvers.
ChainCountryResolver::addResolver public function Adds a resolver. Overrides ChainCountryResolverInterface::addResolver
ChainCountryResolver::getResolvers public function Gets all added resolvers. Overrides ChainCountryResolverInterface::getResolvers
ChainCountryResolver::resolve public function Resolves the country. Overrides CountryResolverInterface::resolve
ChainCountryResolver::__construct public function Constructs a new ChainCountryResolver object.