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