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 | * {@inheritdoc} |
||
63 | */ |
||
64 | public function init() |
||
70 | |||
71 | /** |
||
72 | * @return double |
||
73 | */ |
||
74 | public function getPrice() |
||
78 | |||
79 | /** |
||
80 | * Sets the [[price]]. |
||
81 | * |
||
82 | * The $price will be casted to double |
||
83 | * |
||
84 | * @param mixed $price |
||
85 | */ |
||
86 | public function setPrice($price) |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | public function getCost($withDiscount = true) |
||
102 | |||
103 | /** |
||
104 | * The method returns the `crc32b` hash of a distinct condition |
||
105 | * Example:. |
||
106 | * |
||
107 | * ```php |
||
108 | * return hash('crc32b', implode('_', ['domain', 'registration', $this->name])); |
||
109 | * ``` |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | abstract public function getId(); |
||
114 | |||
115 | /** |
||
116 | * @param array $options Options that override defaults on [[Yii::createObject()]] |
||
117 | * @throws \yii\base\InvalidConfigException |
||
118 | * @return Calculation |
||
119 | */ |
||
120 | public function getCalculationModel($options = []) |
||
136 | |||
137 | /** |
||
138 | * @param array $options Options that override defaults on [[Yii::createObject()]] |
||
139 | * @throws \yii\base\InvalidConfigException |
||
140 | * @return AbstractPurchase |
||
141 | */ |
||
142 | public function getPurchaseModel($options = []) |
||
152 | |||
153 | /** |
||
154 | * Returns the value of the domain. |
||
155 | * @return double |
||
156 | */ |
||
157 | public function getValue() |
||
161 | |||
162 | /** |
||
163 | * Sets the [[value]]. |
||
164 | * |
||
165 | * The $value will be casted to double |
||
166 | * |
||
167 | * @param mixed $value |
||
168 | */ |
||
169 | public function setValue($value) |
||
173 | |||
174 | public function serialize() |
||
178 | |||
179 | /** |
||
180 | * Method stores map of attributes that must be serialized. |
||
181 | * |
||
182 | * @return array key is the attribute name where the value should be extracted |
||
183 | * In case when the value shoule be assigned in a special way, use [[unserializationMap]] |
||
184 | * to map key to a closure, that will set the value. |
||
185 | * |
||
186 | * @see unserializationMap |
||
187 | */ |
||
188 | protected function serializationMap() |
||
197 | |||
198 | /** |
||
199 | * @return array |
||
200 | * Key is the attribute name, value - the closure to unserialize the value |
||
201 | */ |
||
202 | protected function unserializationMap() |
||
210 | |||
211 | public function unserialize($serialized) |
||
226 | } |
||
227 |
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: