1 | <?php |
||
20 | class Slug |
||
21 | { |
||
22 | /** |
||
23 | * @var string $whiteSpacePattern A regular expression that matches white-space characters |
||
24 | */ |
||
25 | private $whiteSpacePattern = '/[\s]/'; |
||
26 | |||
27 | /** |
||
28 | * @var string $invalidCharactersPattern A regular expression that matches all characters that are invalid for a |
||
29 | * Slug |
||
30 | */ |
||
31 | private $invalidCharactersPattern = '/[^\p{L}\w-_:.,+]/u'; |
||
32 | |||
33 | /** |
||
34 | * @var int $minLength Defines the minimum length for a Slug |
||
35 | */ |
||
36 | private $minLength = 2; |
||
37 | |||
38 | /** |
||
39 | * @var int $maxLength Defines the maximum length of a Slug |
||
40 | */ |
||
41 | private $maxLength = 64; |
||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $slug; |
||
46 | |||
47 | /** |
||
48 | * Create a new SlugValidator instance. |
||
49 | * |
||
50 | * @param string $slug human-readable, descriptive URL fragment for the product (e.g. |
||
51 | * "fancy-t-shirt-1-with-ice-cream-pooping-unicorn") |
||
52 | * |
||
53 | * @throws SlugException If the given $slug is invalid |
||
54 | */ |
||
55 | 44 | public function __construct(string $slug) |
|
60 | |||
61 | /** |
||
62 | * Get a string representation of the current Slug. |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | 7 | public function __toString() |
|
70 | |||
71 | /** |
||
72 | * Validate the given Slug |
||
73 | * |
||
74 | * @param string $sku A unique identifier for a product (e.g. "fancy-short-1") |
||
75 | * |
||
76 | * @return void |
||
77 | * |
||
78 | * @throws SlugException If the given $sku is invalid |
||
79 | */ |
||
80 | 44 | private function validateSlug(string $sku) |
|
111 | |||
112 | } |