1 | <?php |
||
12 | class SKU |
||
13 | { |
||
14 | /** |
||
15 | * @var string $whiteSpacePattern A regular expression that matches white-space characters |
||
16 | */ |
||
17 | private $whiteSpacePattern = '/[\s]/'; |
||
18 | |||
19 | /** |
||
20 | * @var string $invalidCharactersPattern A regular expression that matches all characters that are invalid for a SKU |
||
21 | */ |
||
22 | private $invalidCharactersPattern = '/[^a-z0-9-]/'; |
||
23 | |||
24 | /** |
||
25 | * @var string $uppercaseCharactersPattern A regular expression that matches uppercase characters |
||
26 | */ |
||
27 | private $uppercaseCharactersPattern = '/[A-Z]/'; |
||
28 | |||
29 | /** |
||
30 | * @var string $invalidPrefixCharacters A regular expression that matches characters that cannot be used as a prefix |
||
31 | * for SKUs |
||
32 | */ |
||
33 | private $invalidPrefixCharacters = '/^[-]/'; |
||
34 | |||
35 | /** |
||
36 | * @var string $invalidSuffixCharacters A regular expression that matches characters that cannot be used as a prefix |
||
37 | * for SKUs |
||
38 | */ |
||
39 | private $invalidSuffixCharacters = '/[-]$/'; |
||
40 | |||
41 | /** |
||
42 | * @var int $minLength Defines the minimum length for a SKU |
||
43 | */ |
||
44 | private $minLength = 2; |
||
45 | |||
46 | /** |
||
47 | * @var int $maxLength Defines the maximum length of a SKU |
||
48 | */ |
||
49 | private $maxLength = 32; |
||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | private $sku; |
||
54 | |||
55 | /** |
||
56 | * Create a new SKU instance |
||
57 | * |
||
58 | * @param string $sku A unique identifier for a product (e.g. "fancy-short-1") |
||
59 | * |
||
60 | * @throws SKUException If the given $sku is invalid |
||
61 | */ |
||
62 | 47 | public function __construct(string $sku) |
|
67 | |||
68 | /** |
||
69 | * Get a string representation of the current SKU. |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | 1 | public function __toString() |
|
77 | |||
78 | /** |
||
79 | * Validate the given SKU |
||
80 | * |
||
81 | * @param string $sku A unique identifier for a product (e.g. "fancy-short-1") |
||
82 | * |
||
83 | * @return void |
||
84 | * |
||
85 | * @throws SKUException If the given $sku is invalid |
||
86 | */ |
||
87 | 47 | private function validateSKU(string $sku) |
|
140 | } |