final class CouponCodePattern in Commerce Core 8.2
Represents a coupon code pattern.
Coupon code patterns are passed to the coupon code generator.
Hierarchy
- class \Drupal\commerce_promotion\CouponCodePattern
Expanded class hierarchy of CouponCodePattern
See also
\Drupal\commerce_promotion\CouponCodeGeneratorInterface
2 files declare their use of CouponCodePattern
- CouponCodeGeneratorTest.php in modules/
promotion/ tests/ src/ Kernel/ CouponCodeGeneratorTest.php - CouponGenerateForm.php in modules/
promotion/ src/ Form/ CouponGenerateForm.php
File
- modules/
promotion/ src/ CouponCodePattern.php, line 12
Namespace
Drupal\commerce_promotionView source
final class CouponCodePattern {
// Pattern types.
const ALPHANUMERIC = 'alphanumeric';
const ALPHABETIC = 'alphabetic';
const NUMERIC = 'numeric';
/**
* The pattern type.
*
* @var string
*/
protected $type;
/**
* The prefix.
*
* @var string
*/
protected $prefix;
/**
* The suffix.
*
* @var string
*/
protected $suffix;
/**
* The length.
*
* @var int
*/
protected $length;
/**
* Constructs a new CouponCodePattern object.
*
* @param string $type
* The pattern type.
* @param string $prefix
* The prefix.
* @param string $suffix
* The suffix.
* @param int $length
* The length.
*/
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;
}
/**
* Gets the pattern type.
*
* @return string
* The pattern type.
*/
public function getType() : string {
return $this->type;
}
/**
* Gets the prefix.
*
* @return string
* The prefix.
*/
public function getPrefix() : string {
return $this->prefix;
}
/**
* Gets the suffix.
*
* @return string
* The suffix.
*/
public function getSuffix() : string {
return $this->suffix;
}
/**
* Gets the length.
*
* @return int
* The length.
*/
public function getLength() : int {
return $this->length;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CouponCodePattern:: |
protected | property | The length. | |
CouponCodePattern:: |
protected | property | The prefix. | |
CouponCodePattern:: |
protected | property | The suffix. | |
CouponCodePattern:: |
protected | property | The pattern type. | |
CouponCodePattern:: |
constant | |||
CouponCodePattern:: |
constant | |||
CouponCodePattern:: |
public | function | Gets the length. | |
CouponCodePattern:: |
public | function | Gets the prefix. | |
CouponCodePattern:: |
public | function | Gets the suffix. | |
CouponCodePattern:: |
public | function | Gets the pattern type. | |
CouponCodePattern:: |
constant | |||
CouponCodePattern:: |
public | function | Constructs a new CouponCodePattern object. |