1 | <?php |
||
16 | abstract class AbstractPreferenceBuilder implements PreferenceBuilderInterface |
||
17 | { |
||
18 | /** |
||
19 | * @var bool |
||
20 | */ |
||
21 | protected $isFromServer = false; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $fromField; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $variant = ''; |
||
32 | |||
33 | /** |
||
34 | * @var float |
||
35 | */ |
||
36 | protected $qFactor = 1; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * @inheritDoc |
||
41 | */ |
||
42 | 95 | public function setFromServer($isFromServer) |
|
49 | |||
50 | /** |
||
51 | * @inheritDoc |
||
52 | */ |
||
53 | 102 | public function setFromField($fromField) |
|
60 | |||
61 | /** |
||
62 | * @inheritDoc |
||
63 | * |
||
64 | * @throws InvalidVariantException If the provided variant is not valid. |
||
65 | */ |
||
66 | 95 | public function setVariant($variant) |
|
77 | |||
78 | /** |
||
79 | * @inheritDoc |
||
80 | * |
||
81 | * @throws InvalidVariantException If an invalid quality factor in encountered when building an server preference. |
||
82 | */ |
||
83 | 90 | public function setQualityFactor($qFactor) |
|
96 | |||
97 | /** |
||
98 | * Validate the variant, returning true if the variant is valid. |
||
99 | * |
||
100 | * @throws InvalidVariantException If the provided variant is not valid. |
||
101 | * |
||
102 | * @param string $variant |
||
103 | */ |
||
104 | abstract protected function validateVariant($variant); |
||
105 | |||
106 | /** |
||
107 | * Normalises the variant. |
||
108 | * |
||
109 | * @param string $variant |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | 56 | protected function normalizeVariant($variant) |
|
117 | |||
118 | /** |
||
119 | * Validate the quality factor, returning true if the quality factor is valid. |
||
120 | * |
||
121 | * @param float $qFactor |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | 51 | private function validQualityFactor($qFactor) |
|
129 | |||
130 | /** |
||
131 | * Normalises the provided quality factor, ensuring that the value returned is a float between 0 and 1 (inclusive). |
||
132 | * |
||
133 | * @param float $qFactor |
||
134 | * |
||
135 | * @return float |
||
136 | */ |
||
137 | 87 | private function normalizeQualityFactor($qFactor) |
|
154 | } |
||
155 |