You are here

public function CouponCodePattern::__construct in Commerce Core 8.2

Constructs a new CouponCodePattern object.

Parameters

string $type: The pattern type.

string $prefix: The prefix.

string $suffix: The suffix.

int $length: The length.

File

modules/promotion/src/CouponCodePattern.php, line 59

Class

CouponCodePattern
Represents a coupon code pattern.

Namespace

Drupal\commerce_promotion

Code

public function __construct(string $type, string $prefix = '', string $suffix = '', int $length = 8) {
  $pattern_types = [
    self::ALPHANUMERIC,
    self::ALPHABETIC,
    self::NUMERIC,
  ];
  if (!in_array($type, $pattern_types)) {
    throw new \InvalidArgumentException(sprintf('Unknown pattern type "%s".', $type));
  }
  $this->type = $type;
  $this->prefix = $prefix;
  $this->suffix = $suffix;
  $this->length = $length;
}