1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Utils\UrlRewriteEntityType |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2021 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Utils; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The enum with the entity types for the URL rewrite handling. |
25
|
|
|
* |
26
|
|
|
* @author Tim Wagner <[email protected]> |
27
|
|
|
* @copyright 2021 TechDivision GmbH <[email protected]> |
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
29
|
|
|
* @link https://github.com/techdivision/import |
30
|
|
|
* @link http://www.techdivision.com |
31
|
|
|
*/ |
32
|
|
|
class UrlRewriteEntityType implements EnumInterface |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The URL rewrite entity type `product`. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
const PRODUCT = 'product'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The URL rewrite entity type `category`. |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
const CATEGORY = 'category'; |
48
|
|
|
/** |
49
|
|
|
* The URL rewrite entity type `cms-page`. |
50
|
|
|
* |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
const CMS_PAGE = 'cms-page'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The array with the valid URL rewrite entity types. |
57
|
|
|
* |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
private $types = array( |
61
|
|
|
UrlRewriteEntityType::PRODUCT, |
62
|
|
|
UrlRewriteEntityType::CATEGORY, |
63
|
|
|
UrlRewriteEntityType::CMS_PAGE |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* The URL rewrite entity type value. |
68
|
|
|
* |
69
|
|
|
* @var string |
70
|
|
|
*/ |
71
|
|
|
private $value; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Initializes the enum with the passed value. |
75
|
|
|
* |
76
|
|
|
* @param string $value The enum's value to use |
77
|
|
|
*/ |
78
|
11 |
|
public function __construct(string $value = UrlRewriteEntityType::PRODUCT) |
79
|
|
|
{ |
80
|
11 |
|
if ($this->isValid($value)) { |
81
|
11 |
|
$this->value = $value; |
82
|
|
|
} else { |
83
|
|
|
throw \InvalidArgumentException(sprintf('Value "%s" not a const in enum "%s"', $value, __CLASS__)); |
84
|
|
|
} |
85
|
11 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Query whether or not the passed value is valid. |
89
|
|
|
* |
90
|
|
|
* @param string $value Thevalue to query for |
91
|
|
|
* |
92
|
|
|
* @return boolean TRUE if the value is valid, else FALSE |
93
|
|
|
* @see \TechDivision\Import\Utils\EnumInterface::isValid() |
94
|
|
|
*/ |
95
|
11 |
|
public function isValid($value) : bool |
96
|
|
|
{ |
97
|
11 |
|
return in_array($value, $this->types, true); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Query whether or not the actual instance has the passed value. |
102
|
|
|
* |
103
|
|
|
* @param string $value The value to query for |
104
|
|
|
* |
105
|
|
|
* @return bool TRUE if the instance equals the passed value, else FALSE |
106
|
|
|
*/ |
107
|
11 |
|
public function equals($value) : bool |
108
|
|
|
{ |
109
|
11 |
|
return $this->value === $value; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Return's the enum's value. |
114
|
|
|
* |
115
|
|
|
* @return string The enum's value |
116
|
|
|
* @see \TechDivision\Import\Utils\EnumInterface::__toString() |
117
|
|
|
*/ |
118
|
11 |
|
public function __toString() : string |
119
|
|
|
{ |
120
|
11 |
|
return (string) $this->value; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|