You are here

class ChainOrderTypeResolver in Commerce Core 8.2

Default implementation of the chain order type resolver.

Hierarchy

Expanded class hierarchy of ChainOrderTypeResolver

1 string reference to 'ChainOrderTypeResolver'
commerce_order.services.yml in modules/order/commerce_order.services.yml
modules/order/commerce_order.services.yml
1 service uses ChainOrderTypeResolver
commerce_order.chain_order_type_resolver in modules/order/commerce_order.services.yml
Drupal\commerce_order\Resolver\ChainOrderTypeResolver

File

modules/order/src/Resolver/ChainOrderTypeResolver.php, line 10

Namespace

Drupal\commerce_order\Resolver
View source
class ChainOrderTypeResolver implements ChainOrderTypeResolverInterface {

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

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

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

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

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

}

Members

Namesort descending Modifiers Type Description Overrides
ChainOrderTypeResolver::$resolvers protected property The resolvers.
ChainOrderTypeResolver::addResolver public function Adds a resolver. Overrides ChainOrderTypeResolverInterface::addResolver
ChainOrderTypeResolver::getResolvers public function Gets all added resolvers. Overrides ChainOrderTypeResolverInterface::getResolvers
ChainOrderTypeResolver::resolve public function Resolves the order type. Overrides OrderTypeResolverInterface::resolve
ChainOrderTypeResolver::__construct public function Constructs a new ChainOrderTypeResolver object.