Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
registry.php
1<?php
2namespace Bitrix\Sale;
3
5
6Main\Localization\Loc::loadMessages(__FILE__);
7
12final class Registry
13{
14 const EVENT_ON_INIT_REGISTRY_LIST = 'OnInitRegistryList';
15
16 const REGISTRY_TYPE_ORDER = 'ORDER';
17 const REGISTRY_TYPE_ARCHIVE_ORDER = 'ARCHIVE_ORDER';
18
19 const ENTITY_SHIPMENT = 'SHIPMENT';
20 const ENTITY_ORDER = 'ORDER';
21 const ENTITY_PAYMENT = 'PAYMENT';
22 const ENTITY_PAYMENT_COLLECTION = 'PAYMENT_COLLECTION';
23 const ENTITY_PAYABLE_BASKET_ITEM = 'PAYABLE_BASKET_ITEM';
24 const ENTITY_PAYABLE_SHIPMENT = 'PAYABLE_SHIPMENT';
25 const ENTITY_PAYABLE_ITEM_COLLECTION = 'PAYABLE_ITEM_COLLECTION';
26 const ENTITY_SHIPMENT_COLLECTION = 'SHIPMENT_COLLECTION';
27 const ENTITY_PROPERTY_VALUE = 'PROPERTY_VALUE';
28 const ENTITY_SHIPMENT_PROPERTY_VALUE = 'SHIPMENT_PROPERTY_VALUE';
29 const ENTITY_BUNDLE_COLLECTION = 'BUNDLE_COLLECTION';
30 const ENTITY_BASKET = 'BASKET';
31 const ENTITY_TAX = 'TAX';
32 const ENTITY_BASKET_ITEM = 'BASKET_ITEM';
33 const ENTITY_BASKET_PROPERTIES_COLLECTION = 'BASKET_PROPERTIES_COLLECTION';
34 const ENTITY_BASKET_PROPERTY_ITEM = 'BASKET_PROPERTY_ITEM';
35 const ENTITY_BASKET_RESERVE_COLLECTION = 'BASKET_RESERVE_COLLECTION';
36 const ENTITY_BASKET_RESERVE_COLLECTION_ITEM = 'BASKET_RESERVE_COLLECTION_ITEM';
37 const ENTITY_SHIPMENT_ITEM = 'SHIPMENT_ITEM';
38 const ENTITY_SHIPMENT_ITEM_COLLECTION = 'SHIPMENT_ITEM_COLLECTION';
39 const ENTITY_SHIPMENT_ITEM_STORE = 'SHIPMENT_ITEM_STORE';
40 const ENTITY_SHIPMENT_ITEM_STORE_COLLECTION = 'SHIPMENT_ITEM_STORE_COLLECTION';
41 const ENTITY_PROPERTY_VALUE_COLLECTION = 'PROPERTY_VALUE_COLLECTION';
42 const ENTITY_SHIPMENT_PROPERTY_VALUE_COLLECTION = 'SHIPMENT_PROPERTY_VALUE_COLLECTION';
43 const ENTITY_OPTIONS = 'CONFIG_OPTION';
44 const ENTITY_DISCOUNT = 'DISCOUNT';
45 const ENTITY_DISCOUNT_COUPON = 'DISCOUNT_COUPON';
46 const ENTITY_ORDER_DISCOUNT = 'ORDER_DISCOUNT';
47 const ENTITY_PERSON_TYPE = 'PERSON_TYPE';
48 const ENTITY_ORDER_STATUS = 'ORDER_STATUS';
49 const ENTITY_DELIVERY_STATUS = 'DELIVERY_STATUS';
50 const ENTITY_ENTITY_MARKER = 'ENTITY_MARKER';
51 const ENTITY_ORDER_HISTORY = 'ORDER_HISTORY';
52 const ENTITY_PROPERTY = 'PROPERTIES';
53 const ENTITY_SHIPMENT_PROPERTY = 'SHIPMENT_PROPERTIES';
54 const ENTITY_NOTIFY = 'NOTIFY';
55 const ENTITY_TRADE_BINDING_COLLECTION = 'TRADE_BINDING_COLLECTION';
56 const ENTITY_TRADE_BINDING_ENTITY = 'TRADE_BINDING_ENTITY';
57
58 private static $registryMap = [];
59 private static $registryObjects = [];
60 private $type = '';
61 private static $initData = [
63 Registry::ENTITY_ORDER => '\Bitrix\Sale\Order',
64 Registry::ENTITY_PAYMENT => '\Bitrix\Sale\Payment',
65 Registry::ENTITY_PAYMENT_COLLECTION => '\Bitrix\Sale\PaymentCollection',
66 Registry::ENTITY_PAYABLE_BASKET_ITEM => '\Bitrix\Sale\PayableBasketItem',
67 Registry::ENTITY_PAYABLE_SHIPMENT => '\Bitrix\Sale\PayableShipmentItem',
68 Registry::ENTITY_PAYABLE_ITEM_COLLECTION => '\Bitrix\Sale\PayableItemCollection',
69 Registry::ENTITY_SHIPMENT => '\Bitrix\Sale\Shipment',
70 Registry::ENTITY_SHIPMENT_COLLECTION => '\Bitrix\Sale\ShipmentCollection',
71 Registry::ENTITY_SHIPMENT_ITEM => '\Bitrix\Sale\ShipmentItem',
72 Registry::ENTITY_SHIPMENT_ITEM_COLLECTION => '\Bitrix\Sale\ShipmentItemCollection',
73 Registry::ENTITY_SHIPMENT_ITEM_STORE => '\Bitrix\Sale\ShipmentItemStore',
74 Registry::ENTITY_SHIPMENT_ITEM_STORE_COLLECTION => '\Bitrix\Sale\ShipmentItemStoreCollection',
75 Registry::ENTITY_PROPERTY_VALUE_COLLECTION => '\Bitrix\Sale\PropertyValueCollection',
76 Registry::ENTITY_SHIPMENT_PROPERTY_VALUE_COLLECTION => '\Bitrix\Sale\ShipmentPropertyValueCollection',
77 Registry::ENTITY_PROPERTY_VALUE => '\Bitrix\Sale\PropertyValue',
78 Registry::ENTITY_SHIPMENT_PROPERTY_VALUE => '\Bitrix\Sale\ShipmentPropertyValue',
79 Registry::ENTITY_PROPERTY => '\Bitrix\Sale\Property',
80 Registry::ENTITY_SHIPMENT_PROPERTY => '\Bitrix\Sale\ShipmentProperty',
81 Registry::ENTITY_TAX => '\Bitrix\Sale\Tax',
82 Registry::ENTITY_BASKET_PROPERTY_ITEM => '\Bitrix\Sale\BasketPropertyItem',
83 Registry::ENTITY_BUNDLE_COLLECTION => '\Bitrix\Sale\BundleCollection',
84 Registry::ENTITY_BASKET => '\Bitrix\Sale\Basket',
85 Registry::ENTITY_BASKET_ITEM => '\Bitrix\Sale\BasketItem',
86 Registry::ENTITY_BASKET_PROPERTIES_COLLECTION => '\Bitrix\Sale\BasketPropertiesCollection',
87 Registry::ENTITY_BASKET_RESERVE_COLLECTION => ReserveQuantityCollection::class,
89 Registry::ENTITY_DISCOUNT => '\Bitrix\Sale\Discount',
90 Registry::ENTITY_DISCOUNT_COUPON => '\Bitrix\Sale\DiscountCouponsManager',
91 Registry::ENTITY_ORDER_DISCOUNT => '\Bitrix\Sale\OrderDiscount',
92 Registry::ENTITY_OPTIONS => 'Bitrix\Main\Config\Option',
93 Registry::ENTITY_PERSON_TYPE => 'Bitrix\Sale\PersonType',
94 Registry::ENTITY_ORDER_STATUS => 'Bitrix\Sale\OrderStatus',
95 Registry::ENTITY_DELIVERY_STATUS => 'Bitrix\Sale\DeliveryStatus',
96 Registry::ENTITY_ENTITY_MARKER => '\Bitrix\Sale\EntityMarker',
97 Registry::ENTITY_ORDER_HISTORY => 'Bitrix\Sale\OrderHistory',
98 Registry::ENTITY_NOTIFY => 'Bitrix\Sale\Notify',
99 Registry::ENTITY_TRADE_BINDING_COLLECTION => 'Bitrix\Sale\TradeBindingCollection',
100 Registry::ENTITY_TRADE_BINDING_ENTITY => 'Bitrix\Sale\TradeBindingEntity',
101 ],
103 Registry::ENTITY_ORDER => '\Bitrix\Sale\Archive\Order',
104 Registry::ENTITY_PAYMENT => '\Bitrix\Sale\Payment',
105 Registry::ENTITY_PAYMENT_COLLECTION => '\Bitrix\Sale\PaymentCollection',
106 Registry::ENTITY_PAYABLE_BASKET_ITEM => '\Bitrix\Sale\PayableBasketItem',
107 Registry::ENTITY_PAYABLE_SHIPMENT => '\Bitrix\Sale\PayableShipmentItem',
108 Registry::ENTITY_PAYABLE_ITEM_COLLECTION => '\Bitrix\Sale\PayableItemCollection',
109 Registry::ENTITY_SHIPMENT => '\Bitrix\Sale\Shipment',
110 Registry::ENTITY_SHIPMENT_COLLECTION => '\Bitrix\Sale\ShipmentCollection',
111 Registry::ENTITY_SHIPMENT_ITEM => '\Bitrix\Sale\ShipmentItem',
112 Registry::ENTITY_SHIPMENT_ITEM_COLLECTION => '\Bitrix\Sale\ShipmentItemCollection',
113 Registry::ENTITY_SHIPMENT_ITEM_STORE => '\Bitrix\Sale\ShipmentItemStore',
114 Registry::ENTITY_SHIPMENT_ITEM_STORE_COLLECTION => '\Bitrix\Sale\ShipmentItemStoreCollection',
115 Registry::ENTITY_PROPERTY_VALUE_COLLECTION => '\Bitrix\Sale\PropertyValueCollection',
116 Registry::ENTITY_SHIPMENT_PROPERTY_VALUE_COLLECTION => '\Bitrix\Sale\ShipmentPropertyValueCollection',
117 Registry::ENTITY_PROPERTY_VALUE => '\Bitrix\Sale\PropertyValue',
118 Registry::ENTITY_SHIPMENT_PROPERTY_VALUE => '\Bitrix\Sale\ShipmentPropertyValue',
119 Registry::ENTITY_PROPERTY => '\Bitrix\Sale\Property',
120 Registry::ENTITY_SHIPMENT_PROPERTY => '\Bitrix\Sale\ShipmentProperty',
121 Registry::ENTITY_TAX => '\Bitrix\Sale\Tax',
122 Registry::ENTITY_BASKET_PROPERTY_ITEM => '\Bitrix\Sale\BasketPropertyItem',
123 Registry::ENTITY_BUNDLE_COLLECTION => '\Bitrix\Sale\BundleCollection',
124 Registry::ENTITY_BASKET => '\Bitrix\Sale\Basket',
125 Registry::ENTITY_BASKET_ITEM => '\Bitrix\Sale\BasketItem',
126 Registry::ENTITY_BASKET_PROPERTIES_COLLECTION => '\Bitrix\Sale\BasketPropertiesCollection',
127 Registry::ENTITY_DISCOUNT => '\Bitrix\Sale\Discount',
128 Registry::ENTITY_DISCOUNT_COUPON => '\Bitrix\Sale\DiscountCouponsManager',
129 Registry::ENTITY_ORDER_DISCOUNT => '\Bitrix\Sale\OrderDiscount',
130 Registry::ENTITY_OPTIONS => 'Bitrix\Main\Config\Option',
131 Registry::ENTITY_PERSON_TYPE => 'Bitrix\Sale\PersonType',
132 Registry::ENTITY_ORDER_STATUS => 'Bitrix\Sale\OrderStatus',
133 Registry::ENTITY_DELIVERY_STATUS => 'Bitrix\Sale\DeliveryStatus',
134 Registry::ENTITY_ENTITY_MARKER => '\Bitrix\Sale\EntityMarker',
135 Registry::ENTITY_ORDER_HISTORY => 'Bitrix\Sale\OrderHistory',
136 Registry::ENTITY_TRADE_BINDING_COLLECTION => 'Bitrix\Sale\TradeBindingCollection',
137 Registry::ENTITY_TRADE_BINDING_ENTITY => 'Bitrix\Sale\TradeBindingEntity',
138 Registry::ENTITY_NOTIFY => 'Bitrix\Sale\Notify',
139 ],
140 ];
141
145 private static function initRegistry()
146 {
147 self::$registryMap = self::$initData;
148
149 $event = new Main\Event('sale', self::EVENT_ON_INIT_REGISTRY_LIST);
150 $event->send();
151 $resultList = $event->getResults();
152
153 if (is_array($resultList) && !empty($resultList))
154 {
155 foreach ($resultList as $eventResult)
156 {
158 if ($eventResult->getType() === Main\EventResult::SUCCESS)
159 {
160 $params = $eventResult->getParameters();
161 if (!empty($params) && is_array($params))
162 {
163 self::$registryMap = array_merge(self::$registryMap, $params);
164 }
165 }
166 }
167 }
168 }
169
173 public function getType()
174 {
175 return $this->type;
176 }
177
183 public static function getInstance($type)
184 {
185 if (!self::$registryMap)
186 {
187 self::initRegistry();
188 }
189
190 if (!isset(self::$registryObjects[$type]))
191 {
192 if (isset(self::$registryMap[$type]))
193 {
194 self::$registryObjects[$type] = new static($type);
195 }
196 else
197 {
198 throw new Main\ArgumentException();
199 }
200 }
201
202 return self::$registryObjects[$type];
203 }
204
210 public static function setRegistry($code, $registryItem)
211 {
212 if (!self::$registryMap)
213 {
214 self::initRegistry();
215 }
216
217 self::$registryMap[$code] = $registryItem;
218 }
219
224 private function __construct($type)
225 {
226 $this->type = $type;
227 }
228
233 public function set($code, $className)
234 {
235 self::$registryMap[$this->type][$code] = $className;
236 }
237
243 public function get($code)
244 {
245 if (isset(self::$registryMap[$this->type][$code]))
246 {
247 return self::$registryMap[$this->type][$code];
248 }
249
250 throw new Main\SystemException(
251 Main\Localization\Loc::getMessage(
252 'SALE_REGISTRY_CODE_VALUE_NO_EXISTS',
253 ['#TYPE#' => $this->getType(), '#CODE#' => $code]
254 )
255 );
256 }
257
262 public function getOrderClassName()
263 {
264 return $this->get(self::ENTITY_ORDER);
265 }
266
271 public function getPaymentClassName()
272 {
273 return $this->get(self::ENTITY_PAYMENT);
274 }
275
280 public function getShipmentClassName()
281 {
282 return $this->get(self::ENTITY_SHIPMENT);
283 }
284
290 {
291 return $this->get(self::ENTITY_SHIPMENT_ITEM_COLLECTION);
292 }
293
298 public function getShipmentItemClassName()
299 {
300 return $this->get(self::ENTITY_SHIPMENT_ITEM);
301 }
302
308 {
309 return $this->get(self::ENTITY_SHIPMENT_ITEM_STORE);
310 }
311
320
325 public function getBasketItemClassName()
326 {
327 return $this->get(self::ENTITY_BASKET_ITEM);
328 }
329
335 {
336 return $this->get(self::ENTITY_SHIPMENT_COLLECTION);
337 }
338
344 {
345 return $this->get(self::ENTITY_PAYMENT_COLLECTION);
346 }
347
353 {
354 return $this->get(self::ENTITY_PAYABLE_ITEM_COLLECTION);
355 }
356
362 {
364 }
365
374
380 {
381 return $this->get(self::ENTITY_PROPERTY_VALUE);
382 }
383
389 {
390 return $this->get(self::ENTITY_SHIPMENT_PROPERTY_VALUE);
391 }
392
393
398 public function getBasketClassName()
399 {
400 return $this->get(self::ENTITY_BASKET);
401 }
402
408 {
409 return $this->get(self::ENTITY_BUNDLE_COLLECTION);
410 }
411
416 public function getDiscountClassName()
417 {
418 return $this->get(self::ENTITY_DISCOUNT);
419 }
420
426 {
427 return $this->get(self::ENTITY_DISCOUNT_COUPON);
428 }
429
435 {
436 return $this->get(self::ENTITY_ORDER_DISCOUNT);
437 }
438
443 public function getTaxClassName()
444 {
445 return $this->get(self::ENTITY_TAX);
446 }
447
453 {
455 }
456
462 {
463 return $this->get(self::ENTITY_BASKET_PROPERTY_ITEM);
464 }
465
471 {
473 }
474
479 public function getReservedItemClassName()
480 {
482 }
483
488 public function getPersonTypeClassName()
489 {
490 return $this->get(self::ENTITY_PERSON_TYPE);
491 }
492
497 public function getOrderStatusClassName()
498 {
499 return $this->get(self::ENTITY_ORDER_STATUS);
500 }
501
507 {
508 return $this->get(self::ENTITY_DELIVERY_STATUS);
509 }
510
515 public function getEntityMarkerClassName()
516 {
517 return $this->get(self::ENTITY_ENTITY_MARKER);
518 }
519
524 public function getOrderHistoryClassName()
525 {
526 return $this->get(self::ENTITY_ORDER_HISTORY);
527 }
528
533 public function getNotifyClassName()
534 {
535 return $this->get(self::ENTITY_NOTIFY);
536 }
541 public function getPropertyClassName()
542 {
543 return $this->get(self::ENTITY_PROPERTY);
544 }
545
551 {
552 return $this->get(self::ENTITY_SHIPMENT_PROPERTY);
553 }
554}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
const ENTITY_BASKET_PROPERTIES_COLLECTION
Definition registry.php:33
const ENTITY_BASKET_PROPERTY_ITEM
Definition registry.php:34
const ENTITY_SHIPMENT_COLLECTION
Definition registry.php:26
const ENTITY_PAYABLE_BASKET_ITEM
Definition registry.php:23
const ENTITY_TRADE_BINDING_COLLECTION
Definition registry.php:55
getBasketPropertiesCollectionClassName()
Definition registry.php:452
const ENTITY_PROPERTY_VALUE
Definition registry.php:27
const ENTITY_BUNDLE_COLLECTION
Definition registry.php:29
const ENTITY_BASKET_RESERVE_COLLECTION
Definition registry.php:35
const ENTITY_PAYMENT_COLLECTION
Definition registry.php:22
static getInstance($type)
Definition registry.php:183
const ENTITY_SHIPMENT_PROPERTY_VALUE
Definition registry.php:28
const ENTITY_SHIPMENT_PROPERTY
Definition registry.php:53
getPropertyValueCollectionClassName()
Definition registry.php:361
const ENTITY_PROPERTY_VALUE_COLLECTION
Definition registry.php:41
const REGISTRY_TYPE_ARCHIVE_ORDER
Definition registry.php:17
const ENTITY_ORDER_DISCOUNT
Definition registry.php:46
const ENTITY_DISCOUNT_COUPON
Definition registry.php:45
const ENTITY_SHIPMENT_ITEM_COLLECTION
Definition registry.php:38
const ENTITY_PAYABLE_SHIPMENT
Definition registry.php:24
static setRegistry($code, $registryItem)
Definition registry.php:210
getShipmentItemStoreCollectionClassName()
Definition registry.php:316
const ENTITY_SHIPMENT_PROPERTY_VALUE_COLLECTION
Definition registry.php:42
getShipmentPropertyValueCollectionClassName()
Definition registry.php:370
const ENTITY_TRADE_BINDING_ENTITY
Definition registry.php:56
const ENTITY_SHIPMENT_ITEM_STORE_COLLECTION
Definition registry.php:40
const ENTITY_DELIVERY_STATUS
Definition registry.php:49
const ENTITY_SHIPMENT_ITEM_STORE
Definition registry.php:39
const ENTITY_BASKET_RESERVE_COLLECTION_ITEM
Definition registry.php:36
const ENTITY_PAYABLE_ITEM_COLLECTION
Definition registry.php:25
const EVENT_ON_INIT_REGISTRY_LIST
Definition registry.php:14