1 | <?php |
||
32 | abstract class AbstractCartPosition extends ActiveRecord implements CartPositionInterface, CalculableModelInterface, Serializable |
||
33 | { |
||
34 | use CartPositionTrait; |
||
35 | |||
36 | /** |
||
37 | * @var string|array|Calculation |
||
38 | * - string: the action calculation model class name |
||
39 | * - array: array of options for [[Yii::createObject()]] call |
||
40 | * - object: the object that extends [[Calculation]] class and represents calculation of the specified object type |
||
41 | */ |
||
42 | protected $_calculationModel; |
||
43 | |||
44 | /** |
||
45 | * @var string|array |
||
46 | * - string: the position purchase model class name |
||
47 | * - array: array of options for [[Yii::createObject()]] call |
||
48 | */ |
||
49 | protected $_purchaseModel; |
||
50 | |||
51 | /** |
||
52 | * @var double the price of the 1 piece of the position |
||
53 | */ |
||
54 | protected $_price; |
||
55 | |||
56 | /** |
||
57 | * @var double the full value of position |
||
58 | */ |
||
59 | protected $_value; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $_currency; |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public function init() |
||
75 | |||
76 | /** |
||
77 | * @return double |
||
78 | */ |
||
79 | public function getPrice() |
||
83 | |||
84 | /** |
||
85 | * Sets the [[price]]. |
||
86 | * |
||
87 | * The $price will be casted to double |
||
88 | * |
||
89 | * @param mixed $price |
||
90 | */ |
||
91 | public function setPrice($price) |
||
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | public function getCost($withDiscount = true) |
||
107 | |||
108 | /** |
||
109 | * The method returns the `crc32b` hash of a distinct condition |
||
110 | * Example:. |
||
111 | * |
||
112 | * ```php |
||
113 | * return hash('crc32b', implode('_', ['domain', 'registration', $this->name])); |
||
114 | * ``` |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | abstract public function getId(); |
||
119 | |||
120 | /** |
||
121 | * @param array $options Options that override defaults on [[Yii::createObject()]] |
||
122 | * @throws \yii\base\InvalidConfigException |
||
123 | * @return Calculation |
||
124 | */ |
||
125 | public function getCalculationModel($options = []) |
||
141 | |||
142 | /** |
||
143 | * @param array $options Options that override defaults on [[Yii::createObject()]] |
||
144 | * @throws \yii\base\InvalidConfigException |
||
145 | * @return AbstractPurchase |
||
146 | */ |
||
147 | public function getPurchaseModel($options = []) |
||
157 | |||
158 | /** |
||
159 | * Returns the value of the domain. |
||
160 | * @return double |
||
161 | */ |
||
162 | public function getValue() |
||
166 | |||
167 | /** |
||
168 | * Sets the [[value]]. |
||
169 | * |
||
170 | * The $value will be casted to double |
||
171 | * |
||
172 | * @param mixed $value |
||
173 | */ |
||
174 | public function setValue($value) |
||
178 | |||
179 | public function serialize() |
||
183 | |||
184 | /** |
||
185 | * Method stores map of attributes that must be serialized. |
||
186 | * |
||
187 | * @return array key is the attribute name where the value should be extracted |
||
188 | * In case when the value shoule be assigned in a special way, use [[unserializationMap]] |
||
189 | * to map key to a closure, that will set the value |
||
190 | * |
||
191 | * @see unserializationMap |
||
192 | */ |
||
193 | protected function serializationMap() |
||
204 | |||
205 | /** |
||
206 | * @return array |
||
207 | * Key is the attribute name, value - the closure to unserialize the value |
||
208 | */ |
||
209 | protected function unserializationMap() |
||
217 | |||
218 | public function unserialize($serialized) |
||
233 | |||
234 | /** |
||
235 | * @return string |
||
236 | */ |
||
237 | public function getCurrency(): ?string |
||
241 | |||
242 | /** |
||
243 | * @param string $currency |
||
244 | */ |
||
245 | public function setCurrency(string $currency): void |
||
249 | } |
||
250 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: